feat(app): workspace projects whose home is a server, pushed and pulled like this PC's archive
Owner review 2, R8, phase 5b (client part), ported onto the final phase 5a.
A Chronos Server with the "projects" capability is now the home of
workspace projects. A server sequence is edited in the workspace like a
local one, not inside the library, and its versions sync with the server
"like git".
- Data: ServerProjectHome is an IProjectHome over ChronosClient.
- These are HomeUnavailableException, so the workspace shows Offline: a
server out of reach, an expired sign-in, a 503 (lease, offline archive,
projects_unreadable), a 409 folder_in_use, and a server without projects.
- 404 sequence/project/version and refused names are ProjectException;
other refusals keep their meaning.
- A deleted project's head is 404 project, so final 5a's HeadAsync NotFound
rule reads it as Gone. The original 5b's IsLiveAsync and
WorkspaceStatus.Gone are dropped. IProjectHome gains rename and delete.
- Data: WorkspaceJobs.CopyFromServer downloads into the workspace, through
the desktop's session, the proxies of one frames version (or the
thumbnails standing in for them), with the aliases of the server's
conversions. It is rebuilt on final 5a's copy handler:
- the copy:frame:fv:folder checkpoint, EnsureSpace (from the server's proxy
sizes), WritingMedia, and the cancelled-copy clean-up;
- the editor's current file is never overwritten;
- each file is hashed as it arrives and checked on disk, four at a time.
It never writes this PC's archive. Originals are still refused until 5c.
- Data: SyncAgent passes on the server's projectChanged events, and after a
lost event stream it reports that changes may have been missed.
- App: SyncHost gives the server home over one session client. The Server
screen offers Open in workspace, disabled with its reason on older
servers, whose sequences keep opening with proxies.
- App: Edit opens or checks out server projects with final 5a's refusals:
unreadable copies, a disabled damaged or newer Main, a refused folder. The
"sequence left the index" refusal now applies only to projects of this
PC's archive.
- App: the picker and the chip follow projectChanged (Server newer, Not on
server). Every state, conflict, delete, remove and failure text uses its
".Server" form when one exists (WorkspaceText.ForHome). That includes 5a's
newer-format conflict, the save conflict, the taken-values toast, Gone and
version-too-large.
- App: a render of a server project first offers to send what is not on the
server, then renders the version the server holds. Offline, Gone, Damaged
and missing media hold the render. Analyses and renders run as server jobs
(ServerJobs, shared with RemoteSequenceSource).
- Pruning keeps final 5a's rule: a version is pruned only after HoldsAsync
reads it back.
- Strings in en and it; ARCHITECTURE, DECISIONS and CHANGELOG.
Tests:
- ServerProjectHome error mapping, using a fake handler.
- Against the in-process server:
- two workspaces on one project: fast-forward, replay and merge, keep mine,
take server, save both, restore;
- the copy job verifying, resuming and following new frames;
- a project deleted on the server (Gone from its head; a push sends
nothing);
- an offline server.
- SyncAgent project events.
- App tests for the host, the project menu and renders of a server home.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e2ecc409a3
commit
26bab759fe
48 files changed
+3243
-409
No files matched your search
@@ -9,6 +9,7 @@ using Chronos.Core.Project;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Data.Workspaces;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
@@ -54,13 +55,19 @@ public interface IWorkspaceUi
|
||||
/// banner when the home's frames moved past the workspace's. Every operation first stores the editor's last edit; what a
|
||||
/// pull, a restore or taking the library's values changed comes back into the editor (merged, or as an undo step). A
|
||||
/// conflict is asked about only when the merge met settings both sides changed, and a choice settles only the conflict
|
||||
/// shown; one an automatic sync met waits for the dialog open to close. Call from the UI thread.
|
||||
/// shown; one an automatic sync met waits for the dialog open to close. A project whose home is a server (phase 5b) words
|
||||
/// its texts for the server, follows what the server tells of it (<see cref="WorkspaceHost.HomeChanged"/>: the chip reads
|
||||
/// Server newer, or that the server no longer has it, its copy kept here), and renders only what the server holds
|
||||
/// (<see cref="ReadyToRenderAsync"/>). Call from the UI thread.
|
||||
/// </summary>
|
||||
public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
{
|
||||
/// <summary>How long after the last edit the chip reads the working state again (a little after the editor's save).</summary>
|
||||
public static readonly TimeSpan StateRefreshDelay = TimeSpan.FromMilliseconds(600);
|
||||
|
||||
/// <summary>How long after an analysis ended a change the home tells is taken as its Auto values reaching Main.</summary>
|
||||
private static readonly TimeSpan AnalysisTake = TimeSpan.FromMinutes(2);
|
||||
|
||||
private readonly WorkspaceHost _host;
|
||||
private readonly WorkspaceSequenceSource _source;
|
||||
private readonly EditorSession _session;
|
||||
@@ -82,6 +89,12 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
/// <summary>The conflict dialog asked in the background, until it is closed (one is asked at a time).</summary>
|
||||
private ConflictDialogViewModel? _asking;
|
||||
|
||||
/// <summary>
|
||||
/// When an analysis of the sequence ended while Sync automatically is on and the home had not told its new Main yet
|
||||
/// (a server catches up a moment later): the change it tells next is taken.
|
||||
/// </summary>
|
||||
private DateTime? _analysisEnded;
|
||||
|
||||
public ProjectMenuViewModel(WorkspaceHost host, WorkspaceSequenceSource source, EditorSession session, IWorkspaceUi ui)
|
||||
{
|
||||
_host = host;
|
||||
@@ -99,6 +112,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
RemoveCopyCommand = new AsyncRelayCommand(OpenRemoveCopyAsync);
|
||||
source.JobChanged += OnJobChanged;
|
||||
session.ProjectChanged += OnProjectChanged;
|
||||
host.HomeChanged += OnHomeChanged;
|
||||
}
|
||||
|
||||
public Guid ProjectId => _source.ProjectId;
|
||||
@@ -107,6 +121,9 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
|
||||
public bool IsMain => _source.Workspace?.IsMain == true;
|
||||
|
||||
/// <summary>The project's home is a server (phase 5b): its texts name the server, its renders are of what the server holds.</summary>
|
||||
public bool IsServerHome => _source.IsServerHome;
|
||||
|
||||
/// <summary>The project's name (Main in the UI language).</summary>
|
||||
public string Name => _source.Workspace is { } workspace ? WorkspaceText.ProjectName(workspace.Name, workspace.IsMain) : string.Empty;
|
||||
|
||||
@@ -114,11 +131,11 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
|
||||
public bool IsSyncing => _isSyncing;
|
||||
|
||||
public string StateText => WorkspaceText.State(_status, _isSyncing);
|
||||
public string StateText => WorkspaceText.State(_status, _isSyncing, IsServerHome);
|
||||
|
||||
public StatusKind StateKind => WorkspaceText.Kind(_status, _isSyncing);
|
||||
|
||||
public string StateToolTip => WorkspaceText.StateToolTip(_status, _isSyncing);
|
||||
public string StateToolTip => WorkspaceText.StateToolTip(_status, _isSyncing, IsServerHome);
|
||||
|
||||
/// <summary>The ▾ button: its name, then where the project stands, then what the menu holds.</summary>
|
||||
public string MenuToolTip => Loc.L("Tooltips.Editor.Project.Menu", Name, StateText);
|
||||
@@ -136,17 +153,25 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
/// <summary>A copy of the media runs (Update media): the banner says so.</summary>
|
||||
public bool IsUpdatingMedia => _copyJob != Guid.Empty;
|
||||
|
||||
public string MediaUpdateText => Loc.L(IsUpdatingMedia ? "Editor.Workspace.Updating" : "Editor.Workspace.MediaChanged");
|
||||
public string MediaUpdateText => IsUpdatingMedia ? Loc.L("Editor.Workspace.Updating") : WorkspaceText.ForHome("Editor.Workspace.MediaChanged", IsServerHome);
|
||||
|
||||
public string MediaChangedToolTip => WorkspaceText.ForHome("Tooltips.Editor.Workspace.MediaChanged", IsServerHome);
|
||||
|
||||
public string UpdateMediaToolTip => WorkspaceText.ForHome("Tooltips.Editor.Workspace.UpdateMedia", IsServerHome);
|
||||
|
||||
/// <summary>A version can be saved: the settings are this Chronos's, no conflict waits, the media are here and the library still has the project.</summary>
|
||||
public bool CanSaveVersion => !_session.IsReadOnly && _status is not { Conflict: not null } and not { MediaRemoved: true } and not { State: WorkspaceState.Gone };
|
||||
|
||||
public string SaveVersionToolTip => _session.IsReadOnly ? Loc.L("Errors.Workspace.ReadOnly")
|
||||
: _status?.State == WorkspaceState.Gone ? Loc.L("Errors.Workspace.DeletedAtHome")
|
||||
: _status?.State == WorkspaceState.Gone ? WorkspaceText.ForHome("Errors.Workspace.DeletedAtHome", IsServerHome)
|
||||
: _status?.Conflict is not null ? Loc.L("Errors.Workspace.Conflict")
|
||||
: Loc.L("Tooltips.Editor.Project.SaveVersion");
|
||||
|
||||
public string DeleteToolTip => IsMain ? Loc.L("Errors.Workspace.MainKept") : Loc.L("Tooltips.Editor.Project.Delete");
|
||||
public string DeleteToolTip => IsMain ? Loc.L("Errors.Workspace.MainKept") : WorkspaceText.ForHome("Tooltips.Editor.Project.Delete", IsServerHome);
|
||||
|
||||
public string RenameToolTip => WorkspaceText.ForHome("Tooltips.Editor.Project.Rename", IsServerHome);
|
||||
|
||||
public string RemoveCopyToolTip => WorkspaceText.ForHome("Tooltips.Editor.Project.RemoveCopy", IsServerHome);
|
||||
|
||||
/// <summary>Save version… (Ctrl+S): the note dialog.</summary>
|
||||
public ICommand SaveVersionCommand { get; }
|
||||
@@ -195,6 +220,55 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
await RefreshAsync();
|
||||
if (_disposed || !_host.Settings.WorkspaceAutoSync || job.Kind is not (JobKind.DeepAnalyse or JobKind.LightAnalyse)) return;
|
||||
if (_status is { State: WorkspaceState.Behind }) await SyncAsync(quiet: true);
|
||||
// A server writes the Auto values into Main a moment after its analysis ends: what it tells next is taken then.
|
||||
else if (IsServerHome) _analysisEnded = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Before a render (phase 5b): a project whose home is a server renders what the server holds, so changes not saved as a
|
||||
/// version, or versions not sent, are first offered to be saved and sent (Sync); false when the user kept them here,
|
||||
/// the server could not take them or no longer has the project, or a conflict waits. A project of this PC's archive
|
||||
/// renders as it is: true.
|
||||
/// </summary>
|
||||
public async Task<bool> ReadyToRenderAsync()
|
||||
{
|
||||
if (!IsServerHome) return true;
|
||||
await StoreEditAsync();
|
||||
var status = await _host.StatusAsync(ProjectId);
|
||||
if (_disposed) return false;
|
||||
Apply(status);
|
||||
if (status.State is WorkspaceState.Gone or WorkspaceState.Offline or WorkspaceState.Damaged or WorkspaceState.MediaRemoved)
|
||||
{
|
||||
_ui.Notify(Loc.L("Editor.Workspace.RenderHeld"), WorkspaceText.StateToolTip(status, server: true), isError: status.State != WorkspaceState.Offline);
|
||||
return false;
|
||||
}
|
||||
if (status.Conflict is not null)
|
||||
{
|
||||
AskConflict(status.Conflict);
|
||||
return false;
|
||||
}
|
||||
if (status.Ahead == 0 && !status.Modified && _source.InStepWithHome(_session.Project) is not null) return true;
|
||||
if (!_ui.Confirm(new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Editor.Workspace.SendFirst.Title"),
|
||||
Message = Loc.L("Editor.Workspace.SendFirst.Message", Name),
|
||||
SafeText = Loc.L("Editor.Project.Keep"),
|
||||
SafeToolTip = Loc.L("Tooltips.Editor.Workspace.SendFirst.Keep"),
|
||||
ActionText = Loc.L("Editor.Workspace.SendFirst.Action"),
|
||||
ActionToolTip = Loc.L("Tooltips.Editor.Workspace.SendFirst.Action"),
|
||||
}))
|
||||
return false;
|
||||
try
|
||||
{
|
||||
await SaveAndSendAsync();
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"Project {ProjectId} could not be sent before its render", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.RenderHeld"), WorkspaceText.Failure(ex, server: true), isError: ex is not HomeUnavailableException);
|
||||
return false;
|
||||
}
|
||||
return !_disposed && _source.InStepWithHome(_session.Project) is not null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -222,7 +296,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
{
|
||||
_ui.Notify(Loc.L("Editor.Workspace.Saved", Formatting.Count(result.Version.Number)), Name);
|
||||
}
|
||||
if (result.SyncError is { } error) _ui.Notify(Loc.L("Editor.Workspace.NotSent"), WorkspaceText.Failure(error), isError: error is not HomeUnavailableException);
|
||||
if (result.SyncError is { } error)
|
||||
_ui.Notify(Loc.L("Editor.Workspace.NotSent"), WorkspaceText.Failure(error, IsServerHome), isError: error is not HomeUnavailableException);
|
||||
// Deleted in the library: said once, and no conflict is asked (nothing can be merged with it); the version stays here.
|
||||
if (result.Status.State == WorkspaceState.Gone) NotifyGone();
|
||||
else if (result.Status.Conflict is { } conflict) AskConflict(conflict);
|
||||
@@ -250,8 +325,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"Project {ProjectId} could not be synced", ex);
|
||||
_ui.Notify(Loc.L(ex is HomeUnavailableException ? "Editor.Workspace.Offline" : "Editor.Workspace.SyncFailed"), WorkspaceText.Failure(ex),
|
||||
isError: ex is not HomeUnavailableException);
|
||||
_ui.Notify(ex is HomeUnavailableException ? WorkspaceText.ForHome("Editor.Workspace.Offline", IsServerHome) : Loc.L("Editor.Workspace.SyncFailed"),
|
||||
WorkspaceText.Failure(ex, IsServerHome), isError: ex is not HomeUnavailableException);
|
||||
await RefreshAsync();
|
||||
}
|
||||
finally
|
||||
@@ -288,7 +363,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
if (result.Kept is { } kept)
|
||||
{
|
||||
if (await _session.TakeOverAsync(kept) is { } step)
|
||||
_ui.Notify(Loc.L("Editor.Workspace.TookLibrary"), Name, Loc.L("Editor.Workspace.Undo"), Loc.L("Tooltips.Editor.Workspace.UndoTake"), () => step.Undo());
|
||||
_ui.Notify(WorkspaceText.ForHome("Editor.Workspace.TookLibrary", IsServerHome), Name, Loc.L("Editor.Workspace.Undo"),
|
||||
WorkspaceText.ForHome("Tooltips.Editor.Workspace.UndoTake", IsServerHome), () => step.Undo());
|
||||
if (result.Pushed.Count > 0 && IsMain) await _ui.SequenceChangedAsync(SequenceId);
|
||||
}
|
||||
else
|
||||
@@ -307,8 +383,9 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
() => _ = _ui.OpenProjectAsync(sequenceId, copy.Id));
|
||||
}
|
||||
|
||||
/// <summary>The library no longer has the project: nothing more is sent, its work stays here (Remove local copy keeps it aside).</summary>
|
||||
private void NotifyGone() => _ui.Notify(Loc.L("Editor.Workspace.State.Gone"), Loc.L("Errors.Workspace.DeletedAtHome"));
|
||||
/// <summary>The home no longer has the project: nothing more is sent, its work stays here (Remove local copy keeps it aside).</summary>
|
||||
private void NotifyGone() =>
|
||||
_ui.Notify(WorkspaceText.ForHome("Editor.Workspace.State.Gone", IsServerHome), WorkspaceText.ForHome("Errors.Workspace.DeletedAtHome", IsServerHome));
|
||||
|
||||
/// <summary>
|
||||
/// Restores <paramref name="version"/> as the project, as one undo step (uncommitted changes are saved as a version
|
||||
@@ -355,6 +432,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
_disposed = true;
|
||||
_source.JobChanged -= OnJobChanged;
|
||||
_session.ProjectChanged -= OnProjectChanged;
|
||||
_host.HomeChanged -= OnHomeChanged;
|
||||
// A conflict still waiting to be asked belongs to this editor: it is not asked once the editor closed (Sync asks it next time).
|
||||
if (_asking is { } waiting && !ReferenceEquals(waiting, _ui.Dialog)) waiting.Dispose();
|
||||
base.Dispose();
|
||||
@@ -369,12 +447,12 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
private void OpenSaveVersion()
|
||||
{
|
||||
if (!CanSaveVersion) return;
|
||||
_ui.ShowDialog(new SaveVersionDialogViewModel(Name, SaveVersionAsync, _ui.CloseDialog));
|
||||
_ui.ShowDialog(new SaveVersionDialogViewModel(Name, SaveVersionAsync, _ui.CloseDialog, IsServerHome));
|
||||
}
|
||||
|
||||
private async Task OpenHistoryAsync()
|
||||
{
|
||||
var dialog = new HistoryDialogViewModel(Name, v => Task.FromResult(Compare(v)), RestoreAsync, _ui.CloseDialog);
|
||||
var dialog = new HistoryDialogViewModel(Name, v => Task.FromResult(Compare(v)), RestoreAsync, _ui.CloseDialog, IsServerHome);
|
||||
_ui.ShowDialog(dialog);
|
||||
try
|
||||
{
|
||||
@@ -389,8 +467,11 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The project's home (this PC's archive, or a server).</summary>
|
||||
private BundleHome Home => _source.Workspace?.Home ?? WorkspaceHost.ArchiveHome(SequenceId);
|
||||
|
||||
/// <summary>
|
||||
/// Open project…: "Open in workspace" over the library's projects of the sequence but the open one (a Save both
|
||||
/// Open project…: "Open in workspace" over the home's projects of the sequence but the open one (a Save both
|
||||
/// sibling, another PC's), or a new one; the choice opens in place of this one (checked out and copied when it is not
|
||||
/// here yet).
|
||||
/// </summary>
|
||||
@@ -399,32 +480,34 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
try
|
||||
{
|
||||
await StoreEditAsync();
|
||||
var projects = (await _host.HomeProjectsAsync(SequenceId)).Where(p => p.Id != ProjectId).ToList();
|
||||
var home = Home;
|
||||
var projects = (await _host.HomeProjectsAsync(home)).Where(p => p.Id != ProjectId).ToList();
|
||||
var dialog = new OpenInWorkspaceDialogViewModel(_session.Content.Sequence.DisplayTitle, projects, _ui.CloseDialog,
|
||||
[.. projects.Select(p => p.Name).Append(_source.Workspace?.Name ?? string.Empty)]);
|
||||
[.. projects.Select(p => p.Name).Append(_source.Workspace?.Name ?? string.Empty)], server: IsServerHome);
|
||||
_ui.ShowDialog(dialog);
|
||||
if (await dialog.Choice is not { } choice || _disposed) return;
|
||||
var id = choice.ProjectId ?? (await _host.CreateProjectAsync(SequenceId, choice.NewName!, _status?.Base?.VersionId)).Id;
|
||||
var id = choice.ProjectId ?? (await _host.CreateProjectAsync(home, choice.NewName!, _status?.Base?.VersionId)).Id;
|
||||
await _ui.OpenProjectAsync(SequenceId, id);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"Another project of sequence {SequenceId} could not be opened", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.OpenFailed"), WorkspaceText.Failure(ex), isError: true);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.OpenFailed"), WorkspaceText.Failure(ex, IsServerHome), isError: true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OpenNewProjectAsync()
|
||||
{
|
||||
var names = await OtherNamesAsync(null);
|
||||
var home = Home;
|
||||
_ui.ShowDialog(new ProjectNameDialogViewModel(false, string.Empty, names, async name =>
|
||||
{
|
||||
await StoreEditAsync();
|
||||
// From the open project's last version at the home, so the new one starts where this one is there.
|
||||
var created = await _host.CreateProjectAsync(SequenceId, name, _status?.Base?.VersionId);
|
||||
var created = await _host.CreateProjectAsync(home, name, _status?.Base?.VersionId);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.Created", created.Name), _session.Content.Sequence.DisplayTitle);
|
||||
_ = _ui.OpenProjectAsync(SequenceId, created.Id);
|
||||
}, _ui.CloseDialog));
|
||||
}, _ui.CloseDialog, IsServerHome));
|
||||
}
|
||||
|
||||
private async Task OpenRenameAsync()
|
||||
@@ -436,7 +519,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
await _session.ReloadAsync();
|
||||
_ui.Notify(Loc.L("Editor.Workspace.Renamed"), name);
|
||||
RaiseState();
|
||||
}, _ui.CloseDialog));
|
||||
}, _ui.CloseDialog, IsServerHome));
|
||||
}
|
||||
|
||||
private async Task DeleteAsync()
|
||||
@@ -446,11 +529,11 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
if (!_ui.Confirm(new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.L("Editor.Project.DeleteTitle", name),
|
||||
Message = Loc.L("Editor.Project.DeleteMessage"),
|
||||
Message = WorkspaceText.ForHome("Editor.Project.DeleteMessage", IsServerHome),
|
||||
SafeText = Loc.L("Editor.Project.Keep"),
|
||||
SafeToolTip = Loc.L("Tooltips.Editor.Project.Keep"),
|
||||
ActionText = Loc.L("Editor.Project.DeleteAction"),
|
||||
ActionToolTip = Loc.L("Tooltips.Editor.Project.DeleteAction"),
|
||||
ActionToolTip = WorkspaceText.ForHome("Tooltips.Editor.Project.DeleteAction", IsServerHome),
|
||||
IsDestructive = true,
|
||||
}))
|
||||
return;
|
||||
@@ -468,7 +551,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"Project {ProjectId} was not deleted", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.DeleteFailed"), WorkspaceText.Failure(ex), isError: true);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.DeleteFailed"), WorkspaceText.Failure(ex, IsServerHome), isError: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,12 +566,12 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
{
|
||||
await SaveAndSendAsync();
|
||||
await RemoveAsync(projectId, discard: false);
|
||||
}, () => RemoveCopyDialogViewModel.ConfirmDiscard(_ui, name), _ui.CloseDialog));
|
||||
}, () => RemoveCopyDialogViewModel.ConfirmDiscard(_ui, name), _ui.CloseDialog, IsServerHome));
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"The removal of project {ProjectId} could not be planned", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.RemoveFailed"), WorkspaceText.Failure(ex), isError: true);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.RemoveFailed"), WorkspaceText.Failure(ex, IsServerHome), isError: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,14 +587,15 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
var result = await _host.SyncAsync(ProjectId);
|
||||
Apply(result.Status);
|
||||
await TakeAsync(result);
|
||||
// Nothing can be sent to a project the library no longer has: only Discard takes the copy, its work kept aside.
|
||||
if (result.Status.State == WorkspaceState.Gone) throw new WorkspaceException(Loc.L("Errors.Workspace.DeletedAtHome"));
|
||||
// Nothing can be sent to a project the home no longer has: only Discard takes the copy, its work kept aside.
|
||||
if (result.Status.State == WorkspaceState.Gone) throw new WorkspaceException(WorkspaceText.ForHome("Errors.Workspace.DeletedAtHome", IsServerHome));
|
||||
if (result.Status.Conflict is { } conflict)
|
||||
{
|
||||
AskConflict(conflict);
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.Conflict"));
|
||||
}
|
||||
if (result.Status is { Ahead: > 0 } or { Modified: true, ReadOnly: false }) throw new WorkspaceException(Loc.L("Errors.Workspace.Unsent"));
|
||||
if (result.Status is { Ahead: > 0 } or { Modified: true, ReadOnly: false })
|
||||
throw new WorkspaceException(WorkspaceText.ForHome("Errors.Workspace.Unsent", IsServerHome));
|
||||
}
|
||||
|
||||
private async Task RemoveAsync(Guid projectId, bool discard)
|
||||
@@ -520,7 +604,8 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
if (!discard)
|
||||
{
|
||||
var status = await _host.StatusAsync(projectId, askHome: false);
|
||||
if (status is { Ahead: > 0 } or { Conflict: not null } or { Modified: true, ReadOnly: false }) throw new WorkspaceException(Loc.L("Errors.Workspace.Unsent"));
|
||||
if (status is { Ahead: > 0 } or { Conflict: not null } or { Modified: true, ReadOnly: false })
|
||||
throw new WorkspaceException(WorkspaceText.ForHome("Errors.Workspace.Unsent", IsServerHome));
|
||||
}
|
||||
var name = Name;
|
||||
if (!await _ui.CloseProjectAsync()) return;
|
||||
@@ -532,7 +617,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. (await _host.HomeProjectsAsync(SequenceId)).Where(p => p.Id != except).Select(p => p.Name)];
|
||||
return [.. (await _host.HomeProjectsAsync(Home)).Where(p => p.Id != except).Select(p => p.Name)];
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
@@ -555,7 +640,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"The media of project {ProjectId} could not be copied again", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), WorkspaceText.Failure(ex), isError: true);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), WorkspaceText.Failure(ex, IsServerHome), isError: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,9 +667,9 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
private void AskConflict(WorkspaceConflict conflict, bool background = false)
|
||||
{
|
||||
if (background && _asking is { IsClosed: false }) return;
|
||||
var lines = WorkspaceText.ConflictLines(conflict.Differences, 10);
|
||||
var lines = WorkspaceText.ConflictLines(conflict.Differences, 10, IsServerHome);
|
||||
var dialog = new ConflictDialogViewModel(Name, WorkspaceHost.SiblingName(_source.Workspace?.Name ?? Name), lines, choice => ResolveAsync(choice, conflict),
|
||||
_ui.CloseDialog, conflict.NewerFormat);
|
||||
_ui.CloseDialog, conflict.NewerFormat, IsServerHome);
|
||||
if (!background)
|
||||
{
|
||||
// Asked now: one still waiting from the background (or showing, which this one replaces) would only repeat an older list.
|
||||
@@ -669,6 +754,34 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
else _ = CopyEndedAsync(job);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The home told that this project changed there, or that changes may have been missed (any thread; phase 5b): where it
|
||||
/// stands is read again on the menu's thread, so the chip says Server newer, or that the server no longer has it.
|
||||
/// </summary>
|
||||
private void OnHomeChanged(WorkspaceHomeChange change)
|
||||
{
|
||||
if (_disposed || (change.ProjectId is { } id ? id != ProjectId : !IsServerHome || !string.Equals(change.Server, Home.Server, StringComparison.OrdinalIgnoreCase)))
|
||||
return;
|
||||
if (_context is { } context) context.Post(_ => _ = HomeChangedAsync(change), null);
|
||||
else _ = HomeChangedAsync(change);
|
||||
}
|
||||
|
||||
private async Task HomeChangedAsync(WorkspaceHomeChange change)
|
||||
{
|
||||
if (_disposed || _isSyncing) return;
|
||||
await RefreshAsync();
|
||||
// An analysis's Auto values reached Main at the server: with Sync automatically they are taken, as after an analysis here.
|
||||
if (_disposed || _analysisEnded is not { } ended || change.Change != ProjectChanges.Pushed) return;
|
||||
if (DateTime.UtcNow - ended > AnalysisTake)
|
||||
{
|
||||
_analysisEnded = null;
|
||||
return;
|
||||
}
|
||||
if (_status is not { State: WorkspaceState.Behind } || !_host.Settings.WorkspaceAutoSync) return;
|
||||
_analysisEnded = null;
|
||||
await SyncAsync(quiet: true);
|
||||
}
|
||||
|
||||
/// <summary>The copy of Update media ended: the editor reads the new frames (its positions follow them), or the toast says why not.</summary>
|
||||
private async Task CopyEndedAsync(Job job)
|
||||
{
|
||||
@@ -682,7 +795,7 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
Log.Warning("workspace", $"The new media of project {ProjectId} could not be read", ex);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), WorkspaceText.Failure(ex), isError: true);
|
||||
_ui.Notify(Loc.L("Editor.Workspace.CopyFailed"), WorkspaceText.Failure(ex, IsServerHome), isError: true);
|
||||
}
|
||||
await RefreshAsync();
|
||||
RaiseState();
|
||||
@@ -718,6 +831,11 @@ public sealed class ProjectMenuViewModel : LocalizedViewModel
|
||||
OnPropertyChanged(nameof(CanSaveVersion));
|
||||
OnPropertyChanged(nameof(SaveVersionToolTip));
|
||||
OnPropertyChanged(nameof(DeleteToolTip));
|
||||
OnPropertyChanged(nameof(IsServerHome));
|
||||
OnPropertyChanged(nameof(RenameToolTip));
|
||||
OnPropertyChanged(nameof(RemoveCopyToolTip));
|
||||
OnPropertyChanged(nameof(MediaChangedToolTip));
|
||||
OnPropertyChanged(nameof(UpdateMediaToolTip));
|
||||
_updateMedia.RaiseCanExecuteChanged();
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user