Files
Chronos/src/Chronos.Data/Sync/SyncModel.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

182 lines
7.8 KiB
C#

using Chronos.Core.Model;
namespace Chronos.Data.Sync;
/// <summary>Where a sequence stands between this PC and the server (BRIEF §12.7, §14.5).</summary>
public enum SyncStatus
{
/// <summary>Same originals and settings on both sides.</summary>
InSync,
LocalOnly,
RemoteOnly,
/// <summary>Only on the server; this PC keeps its proxies for editing.</summary>
ProxiesOnly,
/// <summary>This PC holds originals or settings the server lacks.</summary>
LocalAhead,
/// <summary>The server holds originals or settings this PC lacks.</summary>
ServerAhead,
/// <summary>Both sides changed the settings, title, tags, rating or notes since they last agreed: the user picks.</summary>
Conflict,
/// <summary>An upload or download job is queued, running or paused.</summary>
Transferring,
}
/// <summary>How the user settles a conflict (BRIEF §12.7).</summary>
public enum SyncResolution
{
KeepMine,
TakeServer,
/// <summary>The server's version wins; this PC's settings are kept next to the project as a dated copy.</summary>
SaveBoth,
}
/// <summary>What a download job fetches.</summary>
public enum SyncDownloadMode
{
/// <summary>Originals, hash-verified, into the local archive.</summary>
Originals,
/// <summary>Proxies (thumbnails where the server has none) into the proxy cache.</summary>
Proxies,
/// <summary>The server's renders the local copy lacks, into its exports folder.</summary>
Exports,
}
/// <summary>What an upload job sends.</summary>
public enum SyncUploadMode
{
/// <summary>Originals and settings (creating the server sequence when needed).</summary>
Originals,
/// <summary>This PC's renders the server lacks (BRIEF §14.5: renders are uploaded on request).</summary>
Exports,
}
/// <summary>
/// One server sequence as this client last saw it, linked to its local copy when there is one. The base versions are
/// the settings counters both sides had when they last agreed; the diff versions are the frame counters and render
/// counts the missing counts were computed at, so originals and renders are compared again only when either side's change.
/// </summary>
public sealed record SyncLink
{
/// <summary>Normalised server address (<see cref="SyncService.ServerKey"/>).</summary>
public required string Server { get; init; }
public required Guid RemoteId { get; init; }
public Guid? LocalId { get; init; }
// ---- The server's side, from its sequence listing ----
public required string Title { get; init; }
public int FrameCount { get; init; }
public long TotalBytes { get; init; }
public int RenderCount { get; init; }
public SequenceStatus RemoteStatus { get; init; }
public int RemoteSettingsVersion { get; init; }
public int RemoteFramesVersion { get; init; }
public DateTimeOffset RemoteUpdatedAt { get; init; }
// ---- Agreement and comparison state ----
public int? BaseLocalSettings { get; init; }
public int? BaseRemoteSettings { get; init; }
public int? DiffLocalFrames { get; init; }
public int? DiffRemoteFrames { get; init; }
public int? DiffLocalRenders { get; init; }
public int? DiffRemoteRenders { get; init; }
/// <summary>
/// The server's update time the originals were compared at, kept while proxies it asks for may be made here (some
/// were counted, or the copy holds originals the server cannot decode and this PC can); null otherwise. The proxies
/// it asks for change without its frame counters moving (one arrives from a render node, its proxy policy changes),
/// and every such change leaves a new update time, so the originals are compared again when it moved.
/// </summary>
public DateTimeOffset? DiffRemoteUpdatedAt { get; init; }
/// <summary>
/// Local originals the server does not have, and proxies it asks for that this PC can make (it cannot decode those
/// originals): an upload sends both.
/// </summary>
public int MissingRemote { get; init; }
/// <summary>Server originals this PC does not have.</summary>
public int MissingLocal { get; init; }
/// <summary>Server renders the local copy does not have, and their size.</summary>
public int ExportsToGet { get; init; }
public long ExportsToGetBytes { get; init; }
/// <summary>Renders of the local copy the server does not have (whose file is still on this PC), and their size.</summary>
public int ExportsToSend { get; init; }
public long ExportsToSendBytes { get; init; }
/// <summary>Settings versions at which the content was found to conflict; null when it does not.</summary>
public int? ConflictLocalSettings { get; init; }
public int? ConflictRemoteSettings { get; init; }
/// <summary>The server's side when the conflict was found: what the user is shown and what "Take server" applies.</summary>
public SyncPayload? ConflictRemote { get; init; }
/// <summary>Frames whose proxy (or thumbnail) is in this PC's proxy cache.</summary>
public int ProxiesCached { get; init; }
/// <summary>Server frames version the proxy cache was filled at.</summary>
public int? ProxiesFramesVersion { get; init; }
/// <summary>Why the last comparison of this sequence failed (it is compared again next time); null when it worked.</summary>
public string? Error { get; init; }
public DateTimeOffset? SyncedAt { get; init; }
public bool ServerHasProxies => (RemoteStatus & SequenceStatus.ProxiesBuilt) != 0;
/// <summary>
/// The proxy cache was never completed or predates the server's last frame change (frames the server has no
/// proxy or thumbnail for stay missing until their frames change, so they are not fetched again and again).
/// </summary>
public bool ProxiesStale => ProxiesFramesVersion != RemoteFramesVersion;
}
/// <summary>One row of the sync table: the local sequence, the server sequence, or both, and where they stand.</summary>
/// <param name="Transfer">The upload or download job working on it, if any (the user's before background ones).</param>
public sealed record SyncEntry(Sequence? Local, SyncLink? Link, SyncStatus Status, Job? Transfer = null)
{
public string Title => Local?.DisplayTitle ?? Link?.Title ?? string.Empty;
/// <summary>The server's id, or the local one for a sequence the server does not have.</summary>
public Guid Id => Link?.RemoteId ?? Local!.Id;
/// <summary>This PC holds originals of the sequence.</summary>
public bool HasLocalOriginals => Local is { FrameCount: > 0 };
}
/// <summary>The sync table after a refresh.</summary>
/// <param name="Duration">Time the refresh took (listing, manifest diffs, settings exchange).</param>
public sealed record SyncSnapshot(string Server, IReadOnlyList<SyncEntry> Entries, DateTimeOffset RefreshedAt, TimeSpan Duration)
{
public long ServerBytes => Entries.Sum(e => e.Link?.TotalBytes ?? 0);
public int ServerSequences => Entries.Count(e => e.Link is not null);
}
/// <summary>Options a refresh applies.</summary>
/// <param name="AutoSyncSettings">Send and take settings changed on one side only (Server.html "Sync projects automatically").</param>
/// <param name="KeepProxiesOffline">Keep the proxy caches of server sequences this PC opened with proxies up to date.</param>
/// <param name="CanEdit">The account may change server sequences; without it this PC's edits are never sent.</param>
public sealed record SyncPolicy(bool AutoSyncSettings = true, bool KeepProxiesOffline = false, bool CanEdit = true);
/// <summary>
/// A conflict could not be settled as the user chose because one side changed again after it was shown; the
/// sequence was compared again, so the user can choose on the fresh content.
/// </summary>
public sealed class SyncConflictChangedException(string message) : InvalidOperationException(message);