merge: remote editor after the review (server jobs, stale proxies, conflict prompt, read-only accounts)

Resolved: the export plan keeps the remote editor's version counter and the
integration branch's ran flag; the capture runs the Save-both copies scene, then
the Arabic scenes, and the remote editor scenes after the sync ones.
Dropped the translations of Archive.Adopt.Copy and Tooltips.Editor.Frames.Hero,
whose English changed; DECISIONS gains the three branches' decisions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-06 20:33:54 +00:00
commit 712bf9417f
81 files changed
+3826 -262

No files matched your search

+295 -53
View File
@@ -3,6 +3,8 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Titano.App.Infrastructure;
using Titano.App.Jobs;
using Titano.App.Server;
using Titano.App.Shell;
using Titano.Core.Advice;
using Titano.Core.Analysis;
@@ -39,9 +41,10 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private readonly LatestRunner _corrections = new(Debounce);
private readonly LatestRunner _plans = new(Debounce);
private readonly DispatcherTimer _player;
private readonly Dictionary<Guid, Job> _jobs = [];
private readonly SequenceJobs _jobs;
private readonly AsyncRelayCommand _analyse;
private readonly AsyncRelayCommand _render;
private readonly AsyncRelayCommand _cancelServerJob;
private PreviewRenderer _renderer;
private int _currentIndex;
private EditorTab _selectedTab;
@@ -64,11 +67,14 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private bool _previewBusy;
private RenderCorrections? _correctionsValue;
private ExportPlan? _plan;
private int _planVersion;
private bool _planned;
private string? _renderPreset;
private IReadOnlyList<TimelineMarker> _markers = [];
private IThumbnailSource _thumbnails;
private int _playLimit;
private double? _analysisSecondsPerFrame;
private ExportSyncGate _syncGate;
private bool _disposed;
public EditorViewModel(ShellViewModel shell, EditorSession session, IReadOnlyList<IVideoEncoderProvider> encoders, EncoderHost host)
@@ -78,6 +84,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
_encoders = encoders;
_host = host;
_dispatcher = Dispatcher.CurrentDispatcher;
_jobs = new SequenceJobs(session.Content.Sequence.Id);
_renderer = new PreviewRenderer(session.Content, session.Source);
Planner = new ExportPlanner(session.Content, encoders, host);
_thumbnails = new EditorThumbnails(session.Source, session.Content.Count);
@@ -85,11 +92,12 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
_player.Tick += (_, _) => Advance();
BackCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Library));
_analyse = new AsyncRelayCommand(AnalyseAsync, () => !IsBusy && !IsAnalysing);
OptimiseAllCommand = new RelayCommand(OptimiseAll, () => !IsBusy);
_analyse = new AsyncRelayCommand(AnalyseAsync, () => !IsLocked && !IsAnalysing);
OptimiseAllCommand = new RelayCommand(OptimiseAll, () => !IsLocked);
_render = new AsyncRelayCommand(() => RenderAsync(JobPriority.User, batch: false), () => CanRender);
UndoCommand = new RelayCommand(() => Session.Undo(), () => !IsBusy && Session.History.CanUndo);
RedoCommand = new RelayCommand(() => Session.Redo(), () => !IsBusy && Session.History.CanRedo);
_cancelServerJob = new AsyncRelayCommand(CancelServerJobAsync, () => ServerJob is not null);
UndoCommand = new RelayCommand(() => Session.Undo(), () => !IsLocked && Session.History.CanUndo);
RedoCommand = new RelayCommand(() => Session.Redo(), () => !IsLocked && Session.History.CanRedo);
PlayCommand = new RelayCommand(() => TogglePlay(limit: 0));
PreviewClipCommand = new RelayCommand(() => TogglePlay(limit: ClipFrames()));
StepBackCommand = new RelayCommand(() => CurrentIndex--);
@@ -102,12 +110,17 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Tabs = [Frames, Exposure, new MotionTab(this), new CameraTab(this), new TimeTab(this), new StackTab(this), new ExportTab(this)];
_selectedTab = Exposure;
_currentIndex = session.Project.HeroFrame is { } hero && (uint)hero < (uint)FrameCount ? hero : 0;
// Until the link is read (AttachJobsAsync), a sequence of this PC cannot send its renders.
_syncGate = session.IsRemote ? ExportSyncGate.Remote : ExportSyncGate.SignedOut;
RenderChoices = [.. ExportPresets.BuiltIn.Select(p => new Choice(p.Id, p.NameKey))];
session.ProjectChanged += OnProjectChanged;
session.ContentChanged += OnContentChanged;
session.SaveFailed += OnSaveFailed;
if (shell.Services.Jobs is { } jobs) jobs.JobChanged += OnJobChanged;
session.ConflictFound += OnConflictFound;
session.Source.JobChanged += OnJobChanged;
session.Source.ReadOnlyChanged += OnReadOnlyChanged;
shell.Services.Sync.Changed += OnSyncChanged;
UpdateMarkers();
RequestCorrections();
RequestPlan();
@@ -122,6 +135,58 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
public string Title => Session.Content.Sequence.DisplayTitle;
/// <summary>A server sequence edited with proxies (the header says where it lives).</summary>
public bool IsRemote => Session.IsRemote;
/// <summary>The server a server sequence lives on ("Studio NAS"); null for a sequence of this PC.</summary>
public string? ServerName => IsRemote ? Shell.Services.Server.ServerName ?? Loc.L("Server.Label.Server") : null;
/// <summary>"Studio NAS" beside the title of a server sequence; "Studio NAS · read-only" when it is only shown.</summary>
public string? RemoteText => !IsRemote ? null
: IsOutdated ? Loc.L("Editor.Remote.Outdated", ServerName)
: IsReadOnly ? Loc.L("Editor.Remote.ReadOnly", ServerName)
: ServerName;
public string? RemoteToolTip => !IsRemote ? null
: IsOutdated ? Loc.L("Tooltips.Editor.Outdated", ServerName)
: IsReadOnly ? Loc.L("Tooltips.Editor.RemoteReadOnly", ServerName)
: Loc.L("Tooltips.Editor.Remote", ServerName);
/// <summary>
/// "Render · 46 %", "Render · queued": the analysis or render of a server sequence the server runs or holds (the job
/// bar shows this PC's jobs); null when there is none.
/// </summary>
public string? ServerJobText => ServerJob is { } job ? EditorText.ServerJob(job) : null;
/// <summary>Frames, speed and time left of the server job.</summary>
public string? ServerJobToolTip => ServerJob is { } job ? EditorText.ServerJobDetail(job, ServerName ?? string.Empty) : null;
/// <summary>The glyph of the server job (DESIGN §4): ◐ an analysis running, ● a render running, ○ waiting, paused.</summary>
public StatusKind ServerJobKind => ServerJob switch
{
{ State: JobState.Running, Kind: JobKind.DeepAnalyse or JobKind.LightAnalyse } => StatusKind.Analysing,
{ State: JobState.Running } => StatusKind.Running,
{ State: JobState.Paused } => StatusKind.Paused,
_ => StatusKind.Queued,
};
/// <summary>The server job runs and reports how far it is (its progress bar shows).</summary>
public bool HasServerJobProgress => ServerJob is { State: JobState.Running, ProgressTotal: > 0 };
/// <summary>Fraction of the server job done (0–1).</summary>
public double ServerJobProgress => ServerJob is { State: JobState.Running, ProgressTotal: > 0 } job ? (double)job.ProgressDone / job.ProgressTotal : 0;
/// <summary>Cancels the server job (BRIEF §11.5: cancel is always available); the toast that follows offers Retry.</summary>
public ICommand CancelServerJobCommand => _cancelServerJob;
public string? CancelServerJobToolTip => IsRemote ? Loc.L("Tooltips.Editor.ServerJob.Cancel", ServerName) : null;
/// <summary>The Export "Sync" option: available, or why not.</summary>
public ExportSyncGate SyncGate { get => _syncGate; private set => Set(ref _syncGate, value); }
/// <summary>The server job the header shows (<see cref="SequenceJobs.Shown"/>).</summary>
private Job? ServerJob => IsRemote ? _jobs.Shown : null;
/// <summary>
/// "3,600 frames · Canon EOS R5 · 2 s interval · 2 h 00 m · 3 warnings"; on the Export tab what the video will be:
/// "3,600 frames · 24 fps · 2 min 30 s · 3840×2160 · source 8192×5464" (Export.html).
@@ -309,22 +374,38 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
public ExportPlan? Plan { get => _plan; private set => Set(ref _plan, value); }
/// <summary>An analysis or render of this sequence is running: settings wait, viewing tools stay live.</summary>
public bool IsBusy => _jobs.Values.Any(j => j.State == JobState.Running);
public bool IsBusy => _jobs.IsBusy;
/// <summary>A deep analysis of this sequence is queued or running (Analyse would queue it twice).</summary>
public bool IsAnalysing => _jobs.Values.Any(j => j.Kind == JobKind.DeepAnalyse);
/// <summary>A deep analysis of this sequence is queued, running or paused (Analyse would queue it twice).</summary>
public bool IsAnalysing => _jobs.IsAnalysing;
public bool IsEditable => !IsBusy;
/// <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"/>).
/// </summary>
public bool IsReadOnly => Session.IsReadOnly;
public string? BusyToolTip => IsBusy ? Loc.L("Tooltips.Editor.Busy") : null;
/// <summary>The frames on the server are no longer the proxies this PC shows: nothing is saved or rendered until they are fetched again.</summary>
public bool IsOutdated => Session.Source.IsOutdated;
/// <summary>Changes to the project wait (a job runs) or are not allowed (<see cref="IsReadOnly"/>); viewing tools stay live.</summary>
public bool IsLocked => IsReadOnly || IsBusy;
public bool IsEditable => !IsLocked;
/// <summary>Why the controls that change the project are disabled; null while they are not.</summary>
public string? LockedToolTip => IsOutdated ? Loc.L("Tooltips.Editor.Outdated", ServerName)
: IsReadOnly ? Loc.L("Tooltips.Editor.ReadOnly")
: IsBusy ? Loc.L("Tooltips.Editor.Busy")
: null;
/// <summary>What Analyse does and costs ("about 6 min" from the speed of the last analysis), or why it is disabled.</summary>
public string AnalyseToolTip => IsBusy ? Loc.L("Tooltips.Editor.Busy")
: IsAnalysing ? Loc.L("Tooltips.Editor.AnalyseQueued")
public string AnalyseToolTip => LockedToolTip
?? (IsAnalysing ? Loc.L("Tooltips.Editor.AnalyseQueued")
: _analysisSecondsPerFrame is { } perFrame ? Loc.L("Tooltips.Editor.AnalyseCost", Formatting.Duration(TimeSpan.FromSeconds(perFrame * FrameCount)))
: Loc.L("Tooltips.Editor.Analyse");
: Loc.L("Tooltips.Editor.Analyse"));
public string OptimiseAllToolTip => Loc.L(IsBusy ? "Tooltips.Editor.Busy" : "Tooltips.Editor.OptimiseAll");
public string OptimiseAllToolTip => LockedToolTip ?? Loc.L("Tooltips.Editor.OptimiseAll");
public bool IsPlaying => _player.IsEnabled;
@@ -339,32 +420,60 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
public IReadOnlyList<Choice> RenderChoices { get; }
/// <summary>The export preset the Render button renders (choosing another one sets it).</summary>
/// <summary>
/// The export preset the Render button renders: choosing another one sets it in the project, or, for an account that
/// may render but not edit (<see cref="IsReadOnly"/>), only in this editor.
/// </summary>
public Choice? SelectedRenderChoice
{
get => RenderChoices.FirstOrDefault(c => string.Equals((string)c.Value, Plan?.Export.PresetId ?? EditorSettings.ExportPreset.Effective(Session.Project, null),
StringComparison.OrdinalIgnoreCase));
get
{
var id = (IsReadOnly ? _renderPreset : null) ?? Plan?.Export.PresetId ?? EditorSettings.ExportPreset.Effective(Session.Project, null);
return RenderChoices.FirstOrDefault(c => string.Equals((string)c.Value, id, StringComparison.OrdinalIgnoreCase));
}
set
{
if (value?.Value is not string id) return;
Session.Edit(p => p with { Export = p.Export with { Preset = p.Export.Preset.WithManual(id), Overrides = new ExportOverrides() } });
if (!IsReadOnly)
{
Session.Edit(p => p with { Export = p.Export with { Preset = p.Export.Preset.WithManual(id), Overrides = new ExportOverrides() } });
return;
}
if (string.Equals(id, _renderPreset, StringComparison.OrdinalIgnoreCase)) return;
_renderPreset = id;
OnPropertyChanged();
RequestPlan();
}
}
/// <summary>
/// The export Render renders: the project's, or with the preset chosen in the Render menu of a read-only session
/// (the project keeps its own; the batch stays the project's).
/// </summary>
public ExportSettings RenderExport => IsReadOnly && _renderPreset is { } id
? Session.ExportFor(id) with { Batch = Session.Project.Export.Batch }
: Session.Project.Export;
/// <summary>"Render · 4K archive".</summary>
public string RenderText => Loc.L("Editor.Render", Plan?.PresetName ?? string.Empty);
public string RenderToolTip => RenderBlockedReason ?? Loc.L("Tooltips.Editor.Render");
public string RenderToolTip => RenderBlockedReason ?? (IsRemote ? Loc.L("Tooltips.Editor.RenderServer", ServerName) : Loc.L("Tooltips.Editor.Render"));
/// <summary>The ▾ part of Render: another preset for the project, or only for this render when the project cannot change.</summary>
public string RenderChoiceToolTip => Loc.L(IsReadOnly ? "Tooltips.Editor.RenderChoiceReadOnly" : "Tooltips.Editor.RenderChoice");
public bool CanRender => RenderBlockedReason is null;
/// <summary>Why the project's export cannot be rendered now, localised; null when it can.</summary>
public string? RenderBlockedReason => Plan switch
{
_ when IsRemote && !Shell.Services.Sync.CanRender => Loc.L("Tooltips.Editor.Render.NoRight", ServerName),
_ when IsOutdated => Loc.L("Tooltips.Editor.Outdated", ServerName),
null when _planned => Loc.L("Tooltips.Editor.Render.NoSource"),
null => Loc.L("Tooltips.Editor.Render.Planning"),
{ NameError: { } error } => Loc.L("Tooltips.Editor.Render.NameError", error),
{ Setup.Encoder.IsReady: false } plan => plan.Setup.Encoder.Notices.LastOrDefault() is { } notice
// The server picks its encoder (a render node, or its managed fallback): this PC's encoders do not decide.
{ Setup.Encoder.IsReady: false } plan when !IsRemote => plan.Setup.Encoder.Notices.LastOrDefault() is { } notice
? Loc.L(notice.Key, [.. notice.Args])
: Loc.L("Editor.Export.Unavailable"),
{ Setup.Plan.Frames.Count: 0 } => Loc.L("Tooltips.Editor.Render.NoFrames"),
@@ -399,13 +508,17 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
/// <summary>"Optimise section": the advisor's heavier decisions, reported in a toast (what changed, from what to what).</summary>
public void Optimise(AdvisorSection section) => Report(Session.Optimise(section));
/// <summary>Queues a render of the project's export (with its batch presets when <paramref name="batch"/>).</summary>
/// <summary>
/// Queues a render of the project's export (with its batch presets when <paramref name="batch"/>): on this PC's
/// engine, or one server job per preset for a server sequence.
/// </summary>
public async Task RenderAsync(JobPriority priority, bool batch)
{
var export = batch ? Session.Project.Export : Session.Project.Export with { Batch = [] };
var request = Session.RenderRequest(export) with { Priority = priority };
await Session.SubmitAsync(request);
Shell.Notify(Loc.L("Editor.Render.Queued"), request.Label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
var export = batch ? RenderExport : RenderExport with { Batch = [] };
var requests = Session.RenderRequests(export);
foreach (var request in requests) await Session.SubmitAsync(request with { Priority = priority });
if (IsRemote) Shell.Notify(Loc.L("Editor.Render.QueuedServer", ServerName), requests[0].Label);
else Shell.Notify(Loc.L("Editor.Render.Queued"), requests[0].Label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
}
/// <summary>Re-reads the enabled state of every command (the async ones keep their own event).</summary>
@@ -413,6 +526,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
_analyse.RaiseCanExecuteChanged();
_render.RaiseCanExecuteChanged();
_cancelServerJob.RaiseCanExecuteChanged();
foreach (var tab in Tabs) tab.RefreshCommands();
CommandManager.InvalidateRequerySuggested();
}
@@ -452,16 +566,31 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Task[] Work() => [_preview.Idle, _corrections.Idle, _plans.Idle, .. Tabs.OfType<ExportTab>().Select(t => t.EstimatesIdle)];
}
/// <summary>Loads the jobs of this sequence already queued or running (busy state) and the speed of the last analysis.</summary>
/// <summary>
/// Loads the jobs of this sequence already queued or running (busy state), the speed of the last analysis and
/// whether the Export "Sync" option applies.
/// </summary>
public async Task AttachJobsAsync()
{
if (Shell.Services.Jobs is not { } jobs) return;
var page = await jobs.ListAsync(null, 200);
foreach (var job in page.Items) Track(job);
foreach (var job in page.Items.OrderBy(j => j.Finished)) LearnAnalysisSpeed(job);
await RefreshSyncGateAsync();
var jobs = await Session.Source.ListJobsAsync(CancellationToken.None);
foreach (var job in jobs) _jobs.Track(job);
foreach (var job in jobs.OrderBy(j => j.Finished)) LearnAnalysisSpeed(job);
OnBusyChanged();
}
/// <summary>Reads again whether this sequence can send its renders to the signed-in server (session, link, rights).</summary>
public async Task RefreshSyncGateAsync()
{
var sync = Shell.Services.Sync;
var server = sync.Server;
var linked = !IsRemote && server is not null && sync.Service is { } service
&& await service.LinkOfAsync(server, Session.Content.Sequence.Id) is not null;
if (_disposed) return;
SyncGate = ExportSync.Gate(IsRemote, server, linked, sync.CanUpload);
foreach (var tab in Tabs) tab.OnSyncGateChanged();
}
public async ValueTask DisposeAsync()
{
if (_disposed) return;
@@ -473,7 +602,10 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Session.ProjectChanged -= OnProjectChanged;
Session.ContentChanged -= OnContentChanged;
Session.SaveFailed -= OnSaveFailed;
if (Shell.Services.Jobs is { } jobs) jobs.JobChanged -= OnJobChanged;
Session.ConflictFound -= OnConflictFound;
Session.Source.JobChanged -= OnJobChanged;
Session.Source.ReadOnlyChanged -= OnReadOnlyChanged;
Shell.Services.Sync.Changed -= OnSyncChanged;
foreach (var tab in Tabs) tab.Dispose();
base.Dispose();
await Session.DisposeAsync();
@@ -572,9 +704,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
foreach (var tab in Tabs) tab.OnCorrectionsChanged();
}
private void RequestPlan() => _ = RunPlanAsync(Planner, Session.Project);
private void RequestPlan() => _ = RunPlanAsync(Planner, Session.Project, RenderExport, ++_planVersion);
private async Task RunPlanAsync(ExportPlanner planner, ProjectSettings project)
private async Task RunPlanAsync(ExportPlanner planner, ProjectSettings project, ExportSettings export, int version)
{
ExportPlan? plan = null;
// A superseded request ends quietly without planning; undo and redo bring back the very same project instance,
@@ -584,7 +716,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
await _plans.Schedule(_ =>
{
plan = planner.Plan(project);
plan = planner.Plan(project, export);
ran = true;
return Task.CompletedTask;
});
@@ -594,13 +726,11 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
Log.Warning("editor", "Planning the export failed", ex);
ran = true;
}
if (!ran || _disposed || !ReferenceEquals(planner, Planner) || !ReferenceEquals(project, Session.Project)) return;
// A later request (a new project, another render choice) owns the plan.
if (!ran || _disposed || !ReferenceEquals(planner, Planner) || version != _planVersion) return;
_planned = true;
Plan = plan;
OnPropertyChanged(nameof(RenderText));
OnPropertyChanged(nameof(RenderToolTip));
OnPropertyChanged(nameof(RenderBlockedReason));
OnPropertyChanged(nameof(CanRender));
OnRenderStateChanged();
OnPropertyChanged(nameof(SelectedRenderChoice));
OnPropertyChanged(nameof(Summary));
foreach (var tab in Tabs) tab.OnPlanChanged();
@@ -694,6 +824,32 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
ActionCommand = new RelayCommand(() => _ = Session.FlushAsync()),
});
/// <summary>
/// A save met settings someone changed to other values on the server (BRIEF §14.5 "explicit conflict prompt"): the
/// dialog lists them; Keep mine overwrites the server's, Take server (the safe default, also on Esc) shows theirs as
/// one undoable step. Saving waits until then.
/// </summary>
private void OnConflictFound(ProjectConflictException conflict) => _dispatcher.BeginInvoke(() =>
{
if (_disposed || Session.Conflict is null) return;
var keepMine = Shell.Services.Dialogs.Confirm(ConflictRequest(conflict, Title, ServerName ?? string.Empty));
if (!_disposed) Session.ResolveConflict(keepMine);
});
/// <summary>The conflict prompt: what differs (the editor's value, then the server's) and what each choice replaces.</summary>
internal static ConfirmRequest ConflictRequest(ProjectConflictException conflict, string title, string server) => new()
{
Heading = Loc.L("Editor.Conflict.Title", server),
Message = Loc.L("Editor.Conflict.Message", title, server),
Detail = string.Join(Environment.NewLine, SyncText.Differences(conflict.Differences, 10)),
DetailToolTip = Loc.L("Tooltips.Server.Conflict.Detail"),
SafeText = Loc.L("Server.Sync.Action.TakeServer"),
SafeToolTip = Loc.L("Tooltips.Editor.Conflict.TakeServer", server),
ActionText = Loc.L("Server.Sync.Action.KeepMine"),
ActionToolTip = Loc.L("Tooltips.Editor.Conflict.KeepMine", server),
IsDestructive = true,
};
private void UpdateMarkers()
{
var content = Session.Content;
@@ -745,28 +901,87 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
private async Task AnalyseAsync()
{
await Session.SubmitAsync(Session.AnalysisRequest());
Shell.Notify(Loc.L("Editor.Analyse.Queued"), Title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
// The Jobs screen lists this PC's jobs; a server's analysis shows beside the title.
if (IsRemote) Shell.Notify(Loc.L("Editor.Analyse.QueuedServer", ServerName), Title);
else Shell.Notify(Loc.L("Editor.Analyse.Queued"), Title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
}
private void OnJobChanged(Job job)
{
if (!job.TargetIds.Contains(Session.Content.Sequence.Id) || job.Kind is not (JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render)) return;
if (!_jobs.Concerns(job)) return;
_dispatcher.BeginInvoke(() =>
{
if (_disposed) return;
var wasActive = _jobs.ContainsKey(job.Id);
Track(job);
var wasActive = _jobs.IsActive(job.Id);
// Progress alone (several times a second on a server) only moves the server job's text and bar.
if (_jobs.Track(job)) OnBusyChanged();
else OnServerJobChanged();
LearnAnalysisSpeed(job);
OnBusyChanged();
if (wasActive && job.State == JobState.Done) _ = ReloadAsync(job.Kind == JobKind.Render ? job : null);
if (!wasActive) return;
if (job.State == JobState.Done) _ = ReloadAsync(job.Kind == JobKind.Render ? job : null);
else if (IsRemote && job.State is JobState.Failed or JobState.Cancelled) ReportServerJobEnded(job);
});
}
private void Track(Job job)
/// <summary>
/// The frames of the server sequence changed while it is open (any thread): everything that changes the project is
/// disabled and says why, and a toast offers to fetch the proxies again.
/// </summary>
private void OnReadOnlyChanged() => _dispatcher.BeginInvoke(() =>
{
if (!job.TargetIds.Contains(Session.Content.Sequence.Id) || job.Kind is not (JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render)) return;
if (job.State is JobState.Queued or JobState.Running) _jobs[job.Id] = job;
else _jobs.Remove(job.Id);
if (_disposed) return;
OnPropertyChanged(nameof(IsReadOnly));
OnPropertyChanged(nameof(IsOutdated));
OnPropertyChanged(nameof(RemoteText));
OnPropertyChanged(nameof(RemoteToolTip));
OnPropertyChanged(nameof(RenderChoiceToolTip));
OnRenderStateChanged();
OnBusyChanged();
if (!IsOutdated) return;
var (id, title) = (Session.Content.Sequence.Id, Title);
Shell.ShowToast(new Toast
{
Title = Loc.L("Editor.Outdated.Title", ServerName),
Message = title,
ActionText = Loc.L("Editor.Outdated.Fetch"),
ActionToolTip = Loc.L("Tooltips.Editor.Outdated.Fetch"),
ActionCommand = new AsyncRelayCommand(() => Shell.Sequence.FetchProxiesAsync(id, title)),
});
});
/// <summary>A server job of this sequence failed or was cancelled: what happened, and Retry (BRIEF §11.5).</summary>
private void ReportServerJobEnded(Job job)
{
var server = ServerName ?? string.Empty;
Shell.ShowToast(new Toast
{
Title = Loc.L("Editor.ServerJob.Ended", JobText.Kind(job.Kind), Loc.L("Jobs.State." + job.State), server),
Message = job.Error ?? job.TargetLabel ?? Title,
ActionText = Loc.L("Jobs.Action.Retry"),
ActionToolTip = Loc.L("Tooltips.Editor.ServerJob.Retry", server),
ActionCommand = new AsyncRelayCommand(() => Session.Source.RetryJobAsync(job.Id, CancellationToken.None), () => !_disposed),
});
}
private async Task CancelServerJobAsync()
{
if (ServerJob is { } job) await Session.Source.CancelJobAsync(job.Id, CancellationToken.None);
}
/// <summary>The session, the sync links or the rights changed (any thread): whether the Export "Sync" option applies.</summary>
private void OnSyncChanged() => _dispatcher.BeginInvoke(() => _ = OnSyncChangedAsync());
private async Task OnSyncChangedAsync()
{
if (_disposed) return;
try
{
await RefreshSyncGateAsync();
}
catch (Data.DatabaseException ex)
{
Log.Warning("editor", "The sync state of the sequence could not be read", ex);
}
}
/// <summary>Seconds per frame of the latest finished deep analysis (any sequence): the cost Analyse announces.</summary>
@@ -782,13 +997,18 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
await Session.ReloadAsync();
}
catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or InvalidOperationException or UnauthorizedAccessException)
catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or InvalidOperationException or UnauthorizedAccessException
or System.Net.Http.HttpRequestException or Protocol.Client.TitanoApiException or OperationCanceledException)
{
// A server that does not answer in time cancels the request (OperationCanceledException).
Shell.ReportError(ex);
return;
}
if (render is null || _disposed) return;
var output = Session.Content.Renders.FirstOrDefault(r => render.Started is not { } started || r.Created >= started)?.OutputPath;
// A server's render stays on the server: nothing to show in Explorer.
var output = Session.Content.Renders.FirstOrDefault(r => render.Started is not { } started || r.Created >= started)?.OutputPath is { Length: > 0 } path
? path
: null;
Shell.ShowToast(new Toast
{
Title = Loc.L("Editor.Render.Done"),
@@ -803,14 +1023,36 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
{
OnPropertyChanged(nameof(IsBusy));
OnPropertyChanged(nameof(IsAnalysing));
OnPropertyChanged(nameof(IsLocked));
OnPropertyChanged(nameof(IsEditable));
OnPropertyChanged(nameof(BusyToolTip));
OnPropertyChanged(nameof(LockedToolTip));
OnPropertyChanged(nameof(AnalyseToolTip));
OnPropertyChanged(nameof(OptimiseAllToolTip));
OnServerJobChanged();
foreach (var tab in Tabs) tab.OnBusyChanged();
RefreshCommands();
}
private void OnServerJobChanged()
{
if (!IsRemote) return;
OnPropertyChanged(nameof(ServerJobText));
OnPropertyChanged(nameof(ServerJobToolTip));
OnPropertyChanged(nameof(ServerJobKind));
OnPropertyChanged(nameof(HasServerJobProgress));
OnPropertyChanged(nameof(ServerJobProgress));
_cancelServerJob.RaiseCanExecuteChanged();
}
/// <summary>What Render renders and whether it can (the plan, the rights or the frames changed).</summary>
private void OnRenderStateChanged()
{
OnPropertyChanged(nameof(RenderText));
OnPropertyChanged(nameof(RenderToolTip));
OnPropertyChanged(nameof(RenderBlockedReason));
OnPropertyChanged(nameof(CanRender));
}
/// <summary>A rendered preview as frozen bitmaps and overlays in picture pixels (built off the UI thread).</summary>
private sealed record PreviewResult(ImageSource Corrected, ImageSource Original, Rect Crop, IReadOnlyList<Point> Horizon, IReadOnlyList<MotionVector> Vectors,
ImageSource? Waveform)