Adds the Videos rail section (Ctrl+4; Archive, Jobs and Server move to Ctrl+5..7) that lists every render of this PC's archive, the signed-in server and the workspace (not sent yet) in one list merged by render id, with search, kind, codec, year, source and order filters, cards or a list, and a player pane that plays in-process and falls back to "Cannot play here". Copy to folder queues a hash-verified VideoCopy job into the new Settings > Archive > Videos folder (never inside the archive or the workspace, the reason given when unset); Delete... runs the dry run first, shows its bytes and what stays, and deletes with the plan's fingerprint. An older server, or one out of reach, leaves this PC's videos with the reason. The trash dialog restores videos entries through the videos library, and a finished VideoCopy job raises its toast. Refs #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
4.6 KiB
C#
106 lines
4.6 KiB
C#
using Chronos.Core.Model;
|
||
|
||
namespace Chronos.App.Jobs;
|
||
|
||
/// <summary>What the shell says when a job of this PC ends.</summary>
|
||
public enum JobNotice
|
||
{
|
||
None,
|
||
Done,
|
||
Failed,
|
||
}
|
||
|
||
/// <summary>
|
||
/// Which job endings raise a toast (BRIEF §12.1 "toasts for job completion"): the long operations the user asked for
|
||
/// end with one toast, whichever screen started them. Background work (thumbnails, proxies, light analysis, the
|
||
/// analysis queued after an import) and scans (the archive scan schedule runs every 10 minutes) end silently; an import
|
||
/// has its own toast when it ends well, and a download shows on its Library card and Server row. Every other failure
|
||
/// is said. A schedule's background run (owner review 2, R10: the index backup, a weekly verify) is said only when it
|
||
/// fails, unless it is upkeep the next run repeats. Cancelled jobs were stopped on purpose.
|
||
/// </summary>
|
||
public static class JobNotices
|
||
{
|
||
/// <summary>
|
||
/// The notice for <paramref name="job"/> after a change from <paramref name="before"/> (null: not seen before).
|
||
/// A job already finished before the change (a repeated event, a page read again) says nothing.
|
||
/// </summary>
|
||
public static JobNotice For(JobState? before, Job job)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(job);
|
||
if (before is JobState.Done or JobState.Failed or JobState.Cancelled) return JobNotice.None;
|
||
if (job.Priority == JobPriority.Background)
|
||
return job.ScheduleId is not null && job.State == JobState.Failed && !IsUpkeep(job.Kind) ? JobNotice.Failed : JobNotice.None;
|
||
return job.State switch
|
||
{
|
||
JobState.Done when Announces(job.Kind) => JobNotice.Done,
|
||
JobState.Failed when !IsUpkeep(job.Kind) => JobNotice.Failed,
|
||
_ => JobNotice.None,
|
||
};
|
||
}
|
||
|
||
private static bool Announces(JobKind kind) =>
|
||
kind is JobKind.Render or JobKind.DeepAnalyse or JobKind.Verify or JobKind.Rebuild or JobKind.Maintenance or JobKind.UploadCommit
|
||
or JobKind.Move or JobKind.Adopt or JobKind.EmptyTrash or JobKind.Convert or JobKind.WorkspaceRender or JobKind.WorkspaceSend
|
||
or JobKind.WorkspaceMove or JobKind.VideoCopy;
|
||
|
||
/// <summary>
|
||
/// Work that keeps the index and its previews current: the next run repeats it, the Archive screen shows what is missing.
|
||
/// Clean-ups too: the housekeeping schedule runs them again (a failed index backup is said).
|
||
/// </summary>
|
||
private static bool IsUpkeep(JobKind kind) =>
|
||
kind is JobKind.Scan or JobKind.Thumbs or JobKind.Proxies or JobKind.LightAnalyse or JobKind.Cleanup;
|
||
}
|
||
|
||
/// <summary>Endings said in one toast: one job, or several of a batch.</summary>
|
||
public sealed record JobEnding(JobNotice Notice, IReadOnlyList<Job> Jobs);
|
||
|
||
/// <summary>
|
||
/// Job endings waiting for their toast, so that a batch speaks once (Server › Upload all queues one upload per
|
||
/// sequence): finished jobs of one kind wait until no job of that kind the user waits for is queued or running, then
|
||
/// one toast says how many finished; failures are said at the end of the update that brought them, together when
|
||
/// several failed at once. WPF-free; feed it on the UI thread.
|
||
/// </summary>
|
||
public sealed class JobEndings
|
||
{
|
||
private readonly SortedDictionary<JobKind, List<Job>> _done = [];
|
||
private readonly List<Job> _failed = [];
|
||
|
||
/// <summary>Finished jobs still waiting for the rest of their kind (tests).</summary>
|
||
public int Waiting => _done.Values.Sum(l => l.Count);
|
||
|
||
public void Add(JobNotice notice, Job job)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(job);
|
||
if (notice == JobNotice.Failed)
|
||
{
|
||
_failed.Add(job);
|
||
}
|
||
else if (notice == JobNotice.Done)
|
||
{
|
||
if (!_done.TryGetValue(job.Kind, out var jobs)) _done[job.Kind] = jobs = [];
|
||
jobs.Add(job);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// The toasts due now: the failures added since the last call, then each finished kind that <paramref name="busy"/>
|
||
/// no longer reports as queued or running. What is returned is forgotten.
|
||
/// </summary>
|
||
public IReadOnlyList<JobEnding> Take(Func<JobKind, bool> busy)
|
||
{
|
||
ArgumentNullException.ThrowIfNull(busy);
|
||
var due = new List<JobEnding>();
|
||
if (_failed.Count > 0)
|
||
{
|
||
due.Add(new JobEnding(JobNotice.Failed, [.. _failed]));
|
||
_failed.Clear();
|
||
}
|
||
foreach (var kind in _done.Keys.Where(k => !busy(k)).ToList())
|
||
{
|
||
due.Add(new JobEnding(JobNotice.Done, _done[kind]));
|
||
_done.Remove(kind);
|
||
}
|
||
return due;
|
||
}
|
||
}
|