Files
Chronos/src/Chronos.App/Editor/ISequenceSource.cs
T
Alby96andClaude Opus 5.5 9b24cf74fc
CI / Build and test (push) Successful in 9m43s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 27s
CI / PostgreSQL 16 integration (push) Failing after 8m41s
CI / PostgreSQL 17 integration (push) Successful in 12m37s
CI / Docker image (push) Successful in 56s
Release / Build, test and publish (push) Successful in 14m59s
Release / Server image (push) Successful in 1m51s
feat: owner review 2 phase 5a: workspace and projects with a local home (#14)
Edit opens a sequence as a project of a workspace folder outside the library. Projects have linear version histories kept as sidecars in .chronos/projects/, Main mirrors the sequence's settings, and sync merges setting by setting. Migration 0009, JobKind.WorkspaceCopy = 20, Settings › Workspace, and 241 new strings in 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-04 09:22:08 +01:00

144 lines
7.7 KiB
C#

using Chronos.Core.Analysis;
using Chronos.Core.Analysis.Deep;
using Chronos.Core.Imaging;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Projects;
namespace Chronos.App.Editor;
/// <summary>
/// Where the sequence open in the editor lives: the local archive (<see cref="LocalSequenceSource"/>) or a server the
/// client is connected to (<see cref="RemoteSequenceSource"/>: proxies from the cache, project and jobs through the
/// API). The editor reads frames, saves the project, queues jobs and follows them only through this interface.
/// </summary>
public interface ISequenceSource : IAsyncDisposable
{
/// <summary>
/// The sequence lives on a server (BRIEF §14.5 "edit with proxies, render where the originals are"): its project is
/// saved there and its renders and analyses run there, one job per preset.
/// </summary>
bool IsRemote { get; }
/// <summary>
/// The project is shown, not changed: a server sequence for an account without the Edit right, or one whose frames
/// changed on the server (<see cref="IsOutdated"/>). The editor disables every change and the source refuses to
/// store one. It can turn true while the sequence is open (<see cref="ReadOnlyChanged"/>).
/// </summary>
bool IsReadOnly { get; }
/// <summary>
/// The frames this PC shows are no longer the sequence's (frames added or removed on the server since its proxies
/// were fetched): frame positions in the project would point at other frames, so nothing is saved or rendered until
/// the sequence is opened again with fresh proxies.
/// </summary>
bool IsOutdated { get; }
/// <summary>
/// A change stored meanwhile by someone else to settings the editor changed too is asked about
/// (<see cref="ProjectConflictException"/>), never merged over the editor's: a server sequence, a workspace project.
/// </summary>
bool AsksConflicts => IsRemote;
/// <summary><see cref="IsReadOnly"/> changed (any thread).</summary>
event Action? ReadOnlyChanged;
/// <summary>A job that may concern the sequence changed (any thread): this PC's engine, or the server's events.</summary>
event Action<Job>? JobChanged;
/// <summary>Everything the editor shows of the sequence; read off the UI thread.</summary>
/// <exception cref="EditorException">The sequence is gone, or its project cannot be read (corrupt, or written by a newer Chronos).</exception>
Task<SequenceContent> LoadAsync(CancellationToken cancellationToken);
/// <summary>
/// Whether the frames <see cref="LoadAsync"/> read last are still the sequence's, in the same order and folder: frames
/// inserted or removed since (a sync download, an import of earlier photos, a scan) moved the stored project's
/// positions, and a Reorganize may have moved the folder. A server sequence whose frames changed becomes
/// <see cref="IsOutdated"/>.
/// </summary>
/// <exception cref="EditorException">The sequence is gone.</exception>
Task<bool> FramesCurrentAsync(CancellationToken cancellationToken);
/// <summary>
/// Frame <paramref name="index"/> in linear light, oriented, long edge at most <paramref name="maxLongEdge"/>; null
/// when the frame cannot be read. The caller owns the buffer.
/// </summary>
ValueTask<ImageBuffer?> DecodeAsync(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken);
/// <summary>
/// Stores <paramref name="project"/>, edited from <paramref name="basis"/> (the version last loaded or saved). A
/// change made meanwhile by someone else is kept where this edit left the value alone (<see cref="ProjectMerge"/>).
/// Returns the stored project.
/// </summary>
/// <exception cref="EditorException">The editor's own reason the project was not stored, worded for the user.</exception>
Task<ProjectSettings> SaveProjectAsync(ProjectSettings project, ProjectSettings basis, CancellationToken cancellationToken);
/// <summary>
/// The three-way merge of the editor's projects, all three naming this source's frames (<see cref="ProjectMerge"/>): member
/// by member, a member both sides changed listed as a conflict and settled for <paramref name="ours"/>. A workspace
/// project merges its frame positions photo by photo, as its sync does.
/// </summary>
ProjectMergeResult Merge(ProjectSettings basis, ProjectSettings ours, ProjectSettings theirs) => ProjectMerge.MergeWithConflicts(basis, ours, theirs);
/// <summary>
/// Keeps <paramref name="unsaved"/>, an edit that can no longer be stored (the stored project became a newer Chronos's,
/// which this one never merges with), where the user finds it and nothing sends it; returns where, or null when this
/// source keeps nothing aside (the edit then stays in the editor as it is).
/// </summary>
Task<string?> SetAsideAsync(ProjectSettings unsaved, CancellationToken cancellationToken) => Task.FromResult<string?>(null);
/// <summary>Queues an analysis or render job for the sequence; returns the job id.</summary>
Task<Guid> SubmitAsync(ArchiveJobRequest request, CancellationToken cancellationToken);
/// <summary>Recent jobs that may concern the sequence (queued, running, finished), for the busy state and the cost of Analyse.</summary>
Task<IReadOnlyList<Job>> ListJobsAsync(CancellationToken cancellationToken);
/// <summary>Cancels a job of the sequence that waits or runs; its new state arrives through <see cref="JobChanged"/>.</summary>
Task CancelJobAsync(Guid jobId, CancellationToken cancellationToken);
/// <summary>Queues a failed or cancelled job of the sequence again from its checkpoint.</summary>
Task RetryJobAsync(Guid jobId, CancellationToken cancellationToken);
}
/// <summary>A sequence as the editor opens it.</summary>
/// <param name="Frames">Frame rows in index order.</param>
/// <param name="Light">Light analysis of the frame metadata (BRIEF §10.1).</param>
/// <param name="Deep">The saved deep analysis when it describes the current frames, else null (<see cref="DeepOfOtherFrames"/> says why).</param>
/// <param name="SourceWidth">Dominant oriented full-resolution width (0 when unknown).</param>
/// <param name="ExportsFolder">Default output folder of renders; null when the sequence is not on this PC.</param>
/// <param name="Renders">Finished renders, newest first (an empty output path when the file is not on this PC).</param>
/// <param name="SavedCopies">This PC's projects kept by "Save both" when a sync conflict was settled, newest first.</param>
public sealed record SequenceContent(
Sequence Sequence,
IReadOnlyList<Frame> Frames,
ProjectSettings Project,
LightAnalysisReport Light,
DeepAnalysisReport? Deep,
int SourceWidth,
int SourceHeight,
string? ExportsFolder,
IReadOnlyList<Render> Renders,
IReadOnlyList<SavedCopy> SavedCopies)
{
/// <summary>Flags of frames that never reach a render (as the render job skips them).</summary>
public const FrameFlags NotRendered = FrameFlags.Missing | FrameFlags.Corrupt | FrameFlags.Excluded | FrameFlags.Undecodable;
public int Count => Frames.Count;
/// <summary>
/// A saved deep analysis exists and reads, but describes another number of frames (frames were added or removed since);
/// false when there is none or it cannot be read now (archive offline, file moved or damaged, a server that sends none).
/// </summary>
public bool DeepOfOtherFrames { get; init; }
/// <summary>Frames the render skips besides the project's exclusions.</summary>
public IEnumerable<int> NotRenderable()
{
for (var i = 0; i < Frames.Count; i++)
{
if ((Frames[i].Flags & NotRendered) != 0) yield return i;
}
}
}