A merge could still trash photos it never verified, resume against a pair the user had answered meanwhile, and take different unhashed photos for copies; the dialog and the lists worded several facts wrongly or lost them on refresh. - Merge: a retry resumes only while the pair is still the job's; Verify requires the other archive online and its folder in place, stops on an unreadable photo, files a differing unhashed photo as a second version and must cover every frame before Trash; the plan hashes unmatched unhashed photos first, lists "Deleted in the other" and names the relinked servers; second versions stay discoverable (CopySides.VersionsAsync). - Integrate: a retry after a failure before the journal runs again. - Sync: a sequence back after a 404 stays Linked while its link holds; a local cull no longer asks for attention. - Block lines of both planners name the right sequence, archive, server and space through one formatter. - Compare dialog: one Details row per setting with worded values, Projects headings, Choose focuses the kept-sequence radios, the photo selection reaches rows outside the viewport, the Replace confirmation lists the losers per side, plan lines read as queued. - Matches and Library: counts first and grouped, integrating shown as a share, local matches name the other archive, the Library keeps its match and "deleted on server" statuses across a refresh. Refs #73 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
214 lines
10 KiB
C#
214 lines
10 KiB
C#
using Chronos.Core.Localization;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Data.Projects;
|
|
using Chronos.Data.Sync;
|
|
|
|
namespace Chronos.Data.Copies;
|
|
|
|
/// <summary>The user's choice for one photo under Choose each (nothing preselected: <see cref="Leave"/>).</summary>
|
|
public enum PhotoChoice
|
|
{
|
|
Leave = 0,
|
|
Bring = 1,
|
|
KeepBoth = 2,
|
|
TakeHere = 3,
|
|
TakeThere = 4,
|
|
}
|
|
|
|
/// <summary>What a plan does with one photo.</summary>
|
|
public enum PhotoAction
|
|
{
|
|
Send = 0,
|
|
Fetch = 1,
|
|
SendVersion = 2,
|
|
FetchVersion = 3,
|
|
TrashHere = 4,
|
|
TrashThere = 5,
|
|
}
|
|
|
|
/// <summary>Why a plan cannot be applied (each maps to one <c>Errors.Copies.*</c> key).</summary>
|
|
public enum CopyBlock
|
|
{
|
|
NeedsNewerServer,
|
|
NoUploadRight,
|
|
NoFetchRight,
|
|
NoEditRight,
|
|
NoDeleteRight,
|
|
LinkTaken,
|
|
NoSpace,
|
|
Busy,
|
|
ArchiveOffline,
|
|
DetailsUnchosen,
|
|
FolderMoved,
|
|
UnsentWorkspace,
|
|
BothLinked,
|
|
TrashBlocked,
|
|
KeptUnchosen,
|
|
ChangedFile,
|
|
}
|
|
|
|
/// <summary>The choices of an Integrate: photo policy, per-photo choices (by photo key), per-detail sides (by path), projects.</summary>
|
|
public sealed record IntegrateChoices(CopyPhotoPolicy Photos, IReadOnlyDictionary<string, PhotoChoice> PerPhoto,
|
|
IReadOnlyDictionary<string, CopySide> Details, CopyProjects Projects);
|
|
|
|
/// <summary>One photo step of a plan: the photo's key, what is done, the frame it starts from, its name, size and SHA-256.</summary>
|
|
public sealed record PhotoStep(string Key, PhotoAction Action, Guid? FrameId, string FileName, long Bytes, string? Sha256);
|
|
|
|
/// <summary>A photo a trash step takes whose raw SHA-256 nothing else holds (no other frame of this index, nor the other side).</summary>
|
|
public sealed record LastCopy(string Key, CopySide Side, string FileName, long Bytes);
|
|
|
|
/// <summary>A project copied across: from which side, the source, the name it gets at the other home, its versions and head.</summary>
|
|
public sealed record ProjectStep(CopySide From, Guid SourceProjectId, string SourceName, string TargetName, int Versions, Guid SourceHeadId);
|
|
|
|
/// <summary>
|
|
/// The dry run of an Integrate of a local sequence with a server sequence (design §5c). Payload is the one portable payload
|
|
/// both sides get; LocalPayload and RemotePayload are each side's as planned (the apply-time content check).
|
|
/// </summary>
|
|
public sealed record IntegratePlan(Guid CopyId, string Server, Guid LocalId, Guid RemoteId, IntegrateChoices Choices,
|
|
IReadOnlyList<PhotoStep> Photos, IReadOnlyList<LastCopy> LastCopies, int LeftOut, SyncPayload? Payload,
|
|
SyncPayload? LocalPayload, SyncPayload? RemotePayload, int DetailChanges, IReadOnlyList<ProjectStep> Projects,
|
|
long FetchBytes, long SendBytes, long FreeBytes, long? QuotaLeftBytes, IReadOnlyList<CopyBlock> Blocks,
|
|
int LocalFramesVersion, int LocalSettingsVersion, int RemoteFramesVersion, int RemoteSettingsVersion, string Fingerprint)
|
|
{
|
|
public bool CanApply => Blocks.Count == 0;
|
|
|
|
public bool Destructive => Photos.Any(p => p.Action is PhotoAction.TrashHere or PhotoAction.TrashThere);
|
|
|
|
/// <summary>New photos move by themselves afterwards only when the plan leaves nothing on one side only (design §6.1).</summary>
|
|
public bool AutoPhotos => LeftOut == 0;
|
|
|
|
/// <summary>The context the plan was made with (rights, names): the job plans again with it (<see cref="IntegratePlanner"/>).</summary>
|
|
public CopyPlanContext? Context { get; init; }
|
|
}
|
|
|
|
/// <summary>The choices of a merge of two local copies (projects are always copied across: the other's home goes to the trash).</summary>
|
|
public sealed record MergeChoices(CopyPhotoPolicy Photos, IReadOnlyDictionary<string, PhotoChoice> PerPhoto,
|
|
IReadOnlyDictionary<string, CopySide> Details);
|
|
|
|
/// <summary>A render of the dropped sequence that moves to the kept one (its row keeps its id).</summary>
|
|
public sealed record RenderStep(Guid RenderId, string FileName, long Bytes, string? Sha256);
|
|
|
|
/// <summary>The dry run of a merge of two local sequences into the kept one (design §5d).</summary>
|
|
public sealed record MergePlan(Guid CopyId, Guid KeepId, Guid DropId, MergeChoices Choices, IReadOnlyList<PhotoStep> Photos,
|
|
IReadOnlyList<LastCopy> LastCopies, IReadOnlyList<RenderStep> Renders, SyncPayload? Payload, int DetailChanges,
|
|
IReadOnlyList<ProjectStep> Projects, IReadOnlyList<string> SessionKeys, IReadOnlyList<string> SkippedSessionKeys,
|
|
IReadOnlyList<string> Links, DeletePlan Trash, long CopyBytes, long FreeBytes, IReadOnlyList<CopyBlock> Blocks,
|
|
int KeepFramesVersion, int KeepSettingsVersion, int DropFramesVersion, int DropSettingsVersion, string Fingerprint)
|
|
{
|
|
public bool CanApply => Blocks.Count == 0;
|
|
|
|
/// <summary><see cref="Links"/> by the names their servers are shown by.</summary>
|
|
public IReadOnlyList<string> LinkNames { get; init; } = [];
|
|
|
|
/// <summary>The name of the server both sequences are linked to (<see cref="CopyBlock.BothLinked"/>); null otherwise.</summary>
|
|
public string? BothLinkedServer { get; init; }
|
|
|
|
/// <summary>Photos the kept sequence holds that the other deleted: they stay in the kept one ("Deleted in the other").</summary>
|
|
public int DeletedInOther { get; init; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// What the planners need to know of this PC and the signed-in account: names, rights (OwnsOrAdmin: of the server sequence),
|
|
/// whether the server keeps projects, the quota left, sequences with unsent workspace work, and every server's originals archive.
|
|
/// </summary>
|
|
public sealed record CopyPlanContext(string PcName, string? ServerName, bool CanUpload, bool CanFetch, bool CanEdit, bool CanDelete,
|
|
bool OwnsOrAdmin, bool KeepsProjects, long? QuotaLeft, IReadOnlySet<Guid> UnsentWorkspaceSequences,
|
|
IReadOnlySet<Guid> ServerOriginalsArchives);
|
|
|
|
/// <summary>The server-side dry run of moving photos of a pair's server sequence to the server's trash (design §6.2).</summary>
|
|
public sealed record TrashTherePlan(Guid CopyId, string Server, Guid RemoteId, IReadOnlyList<Guid> FrameIds, IReadOnlyList<string> Keys, int Photos,
|
|
long Bytes, int FramesVersion, IReadOnlyList<LastCopy> LastCopies);
|
|
|
|
/// <summary>The dry run of moving photos of a pair's local copy to its archive trash, with the ones no other sequence of this index holds.</summary>
|
|
public sealed record TrashHerePlan(FrameDeletePlan Plan, IReadOnlyList<LastCopy> LastCopies);
|
|
|
|
/// <summary>
|
|
/// The dry run of dropping one version of a photo kept in two versions (design §4.1, Versions): the version
|
|
/// <see cref="Key"/> goes to the trash of both sides (this PC's copy and the server's, or both local copies of a merge),
|
|
/// the other version <see cref="PartnerKey"/> stays on both. Applied only while that other version is still held,
|
|
/// verified by content, on both sides.
|
|
/// </summary>
|
|
/// <param name="Other">The other local copy's dry run (a pair of two local copies); null for a server pair.</param>
|
|
/// <param name="RemoteFrameIds">The server's frames of the version (a server pair), at <see cref="RemoteFramesVersion"/>.</param>
|
|
public sealed record DropVersionPlan(Guid CopyId, string Key, string PartnerKey, FrameDeletePlan Here, FrameDeletePlan? Other, Guid? RemoteId,
|
|
IReadOnlyList<Guid> RemoteFrameIds, int RemotePhotos, long RemoteBytes, int RemoteFramesVersion, IReadOnlyList<LastCopy> LastCopies)
|
|
{
|
|
/// <summary>Every frame the drop moves, on both sides.</summary>
|
|
public int Photos => Here.Frames.Count + (Other?.Frames.Count ?? 0) + RemotePhotos;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The journal of one project copied to another home: the intended name, when it was asked, the copy once made, the version
|
|
/// the copy was made from, and the versions pushed so far (source version id to the copy's).
|
|
/// </summary>
|
|
public sealed record TransplantStep(string Intent, DateTimeOffset Asked, Guid? TargetId, Guid? BaseId, int BaseNumber,
|
|
IReadOnlyList<TransplantMove> Moves);
|
|
|
|
/// <summary>A version of the source project and its copy at the other home.</summary>
|
|
public sealed record TransplantMove(Guid Source, Guid Copy);
|
|
|
|
/// <summary>Copies a project with its whole history from one home to another (ProjectTransplant).</summary>
|
|
public interface IProjectCopier
|
|
{
|
|
Task<SequenceProject> CopyAsync(IProjectHome from, SequenceProject source, IProjectHome to, string name,
|
|
TransplantStep? journal, Func<TransplantStep, ValueTask> save, CancellationToken ct);
|
|
}
|
|
|
|
/// <summary>Whether a sequence has workspace projects with unsent versions or unsaved work (a merge waits for them).</summary>
|
|
public interface IWorkspaceGuard
|
|
{
|
|
Task<bool> HasUnsentAsync(Guid sequenceId, CancellationToken ct);
|
|
}
|
|
|
|
/// <summary>The sequences changed since the plan was made: nothing was applied; the pair goes back to its previous state.</summary>
|
|
public sealed class StaleCopyPlanException : InvalidOperationException
|
|
{
|
|
public StaleCopyPlanException()
|
|
: base(Loc.L("Errors.Copies.StalePlan"))
|
|
{
|
|
}
|
|
|
|
public StaleCopyPlanException(string message)
|
|
: base(message)
|
|
{
|
|
}
|
|
|
|
public StaleCopyPlanException(string message, Exception inner)
|
|
: base(message, inner)
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>A sequence of the pair is already linked to another sequence of that server: nothing was changed.</summary>
|
|
public sealed class CopyLinkTakenException : InvalidOperationException
|
|
{
|
|
public CopyLinkTakenException()
|
|
: base(Loc.L("Errors.Copies.LinkTaken", string.Empty, string.Empty))
|
|
{
|
|
}
|
|
|
|
public CopyLinkTakenException(string message)
|
|
: base(message)
|
|
{
|
|
}
|
|
|
|
public CopyLinkTakenException(string message, Exception inner)
|
|
: base(message, inner)
|
|
{
|
|
}
|
|
|
|
/// <summary>The server key both sequences of a merge are linked to (<see cref="BothLinked"/>); null otherwise.</summary>
|
|
public string? Server { get; private init; }
|
|
|
|
/// <summary>The refusal for <paramref name="title"/> already linked to another sequence of <paramref name="server"/>.</summary>
|
|
public static CopyLinkTakenException For(string title, string server) => new(Loc.L("Errors.Copies.LinkTaken", title, server));
|
|
|
|
/// <summary>
|
|
/// The refusal of a merge whose two sequences are both linked to sequences of the server <paramref name="key"/>, worded
|
|
/// with <paramref name="name"/> (the caller resolves the key to the name the server is shown by; the key by default).
|
|
/// </summary>
|
|
public static CopyLinkTakenException BothLinked(string key, string? name = null) =>
|
|
new(Loc.L("Errors.Copies.BothLinked", name ?? key)) { Server = key };
|
|
}
|