Files
LehrerApp/LehrerApp.Sync/Models/SyncModels.cs
2026-03-29 23:47:31 +02:00

67 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace LehrerApp.Sync.Models;
/// <summary>
/// Ein einzelnes Ereignis im Event-Log.
/// Wird verschlüsselt zum Server übertragen der Server versteht den Payload nicht.
/// </summary>
public class SyncEvent
{
public Guid EventId { get; init; } = Guid.NewGuid();
public string DeviceId { get; init; } = "";
public DeviceType DeviceType { get; init; }
public DateTime Timestamp { get; init; } = DateTime.UtcNow;
public long SequenceNr { get; init; } // monoton steigend pro Gerät
public string EntityType { get; init; } = ""; // "Student", "Exam", "Grade" ...
public string EntityId { get; init; } = "";
public string Operation { get; init; } = ""; // "Create", "Update", "Delete"
public string Payload { get; init; } = ""; // JSON, AES-256 verschlüsselt
}
/// <summary>
/// Eintrag im lokalen Konflikt-Log für UI-Anzeige.
/// </summary>
public class ConflictEntry
{
public Guid Id { get; init; } = Guid.NewGuid();
public DateTime DetectedAt { get; init; } = DateTime.UtcNow;
public SyncEvent LocalEvent { get; init; } = null!;
public SyncEvent RemoteEvent { get; init; } = null!;
public string Resolution { get; init; } = ""; // "LocalWon", "RemoteWon", "Pending"
public bool Reviewed { get; set; }
}
/// <summary>
/// Antwort des Servers auf einen Pull-Request.
/// </summary>
public class PullResponse
{
public List<SyncEvent> Events { get; init; } = [];
public long ServerSequenceNr { get; init; }
}
/// <summary>
/// Antwort des Servers auf einen Push-Request.
/// </summary>
public class PushResponse
{
public bool Success { get; init; }
public long ServerSequenceNr { get; init; }
public List<Guid> ConflictingEventIds { get; init; } = [];
}
public enum DeviceType { Desktop, Companion }
/// <summary>
/// Sync-Status für UI-Anzeige.
/// </summary>
public class SyncStatus
{
public SyncState State { get; set; } = SyncState.Idle;
public DateTime? LastSyncAt { get; set; }
public int PendingEvents { get; set; }
public int ConflictCount { get; set; }
public string? ErrorMessage { get; set; }
}
public enum SyncState { Idle, Syncing, Error, Offline }