init 1.0.0

This commit is contained in:
2026-06-19 00:42:00 +02:00
commit 5ca960746b
67 changed files with 3261 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
using LehrerApp.Sync.Models;
namespace LehrerApp.Sync;
/// <summary>
/// Desktop gewinnt gegen Companion.
/// Bei Gleichstand: späterer Timestamp gewinnt.
/// </summary>
public class ConflictResolver(EventQueue queue)
{
public ConflictEntry? TryResolve(SyncEvent remote, string localDeviceId)
{
var local = queue.GetPending()
.FirstOrDefault(e => e.EntityType == remote.EntityType
&& e.EntityId == remote.EntityId
&& e.DeviceId != remote.DeviceId);
if (local is null) return null;
var winner = (local.DeviceType, remote.DeviceType) switch
{
(DeviceType.Desktop, DeviceType.Companion) => local,
(DeviceType.Companion, DeviceType.Desktop) => remote,
_ => local.Timestamp >= remote.Timestamp ? local : remote,
};
if (winner == remote) queue.Acknowledge([local.EventId]);
return new ConflictEntry
{
LocalEvent = local,
RemoteEvent = remote,
Resolution = winner == local ? "LocalWon" : "RemoteWon",
};
}
}