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,9 +9,11 @@ using Chronos.Core.Model;
|
||||
using Chronos.Core.Project;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Archiving.Jobs;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Projects;
|
||||
using Chronos.Data.Workspaces;
|
||||
using Chronos.Protocol;
|
||||
|
||||
namespace Chronos.App.Workspace;
|
||||
|
||||
@@ -51,6 +53,9 @@ public sealed record WorkspaceEntry(Guid ProjectId, Guid SequenceId, string Name
|
||||
|
||||
/// <summary>This Chronos reads its working state: it can open.</summary>
|
||||
public bool IsReadable => !Damaged && !Newer;
|
||||
|
||||
/// <summary>The project's home is a server (phase 5b), not this PC's archive.</summary>
|
||||
public bool IsServerHome => !Home.IsArchive;
|
||||
}
|
||||
|
||||
/// <summary>What changing the workspace folder to <see cref="Folder"/> does: Edit lists its projects from then on; nothing is moved.</summary>
|
||||
@@ -71,6 +76,13 @@ public sealed record WorkspaceCopyFacts(long Bytes, long? Free)
|
||||
public bool TooLittleSpace => Free is { } free && free < Bytes + WorkspaceJobs.CopySpaceReserve;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A workspace project's home told that the project changed there (owner review 2, R8, phase 5b: a server's
|
||||
/// <c>projectChanged</c>): <see cref="Change"/> is one of <c>Protocol.ProjectChanges</c>; null for every project of
|
||||
/// <see cref="Server"/> when changes may have been missed (its events were lost for a while).
|
||||
/// </summary>
|
||||
public sealed record WorkspaceHomeChange(string Server, Guid? ProjectId, string? Change);
|
||||
|
||||
/// <summary>A project brought into the workspace and the copy of its media that was queued.</summary>
|
||||
public sealed record WorkspaceCheckout(SequenceProject Project, Job Copy);
|
||||
|
||||
@@ -108,12 +120,14 @@ public sealed record WorkspaceRemovalPlan(Guid ProjectId, string Name, int Files
|
||||
/// <summary>
|
||||
/// The workspace of this PC (owner review 2, R8), composed for the desktop: its folder (Settings › Workspace, else
|
||||
/// <c>workspace</c> under the data folder: <c>%LOCALAPPDATA%\Chronos\workspace</c>, <c>.\data\workspace</c> for a portable
|
||||
/// copy), the <see cref="WorkspaceStore"/> and <see cref="WorkspaceSync"/> over it, and this PC's archive as the home of
|
||||
/// its projects (<see cref="ArchiveProjectHome"/>; a server home comes in phase 5b). Every operation runs off the UI thread
|
||||
/// and returns where the project stands. Nothing a workspace holds is lost: a version is sent before its copy goes, a copy
|
||||
/// is removed only once the home verifiably holds its head, the work a user chose to discard is kept in
|
||||
/// <c><workspace>/.trash</c>, and versions the home holds are pruned past Settings › Workspace › Kept versions only
|
||||
/// after the home was asked for each. A capture (sample data, no engine) has no workspace: Edit opens the library there.
|
||||
/// copy), the <see cref="WorkspaceStore"/> and <see cref="WorkspaceSync"/> over it, and the homes of its projects: this PC's
|
||||
/// archive (<see cref="ArchiveProjectHome"/>) or, from phase 5b, the signed-in server (<see cref="ServerHomes"/>, a
|
||||
/// <see cref="ServerProjectHome"/>; a project of a server this PC is not signed in to reads as offline, its work waiting
|
||||
/// here). Every operation runs off the UI thread and returns where the project stands. Nothing a workspace holds is lost: a
|
||||
/// version is sent before its copy goes, a copy is removed only once the home verifiably holds its head, the work a user
|
||||
/// chose to discard is kept in <c><workspace>/.trash</c>, and versions the home holds are pruned past Settings ›
|
||||
/// Workspace › Kept versions only after the home returned each, a page of its history at a time. A capture (sample data, no
|
||||
/// engine) has no workspace: Edit opens the library there.
|
||||
/// </summary>
|
||||
public sealed class WorkspaceHost
|
||||
{
|
||||
@@ -190,17 +204,64 @@ public sealed class WorkspaceHost
|
||||
|
||||
public WorkspaceStore Store => Sync.Store;
|
||||
|
||||
/// <summary>The home of a workspace project; null for a home this PC cannot reach in this phase (a server, phase 5b).</summary>
|
||||
/// <summary>
|
||||
/// The project home of a server home (phase 5b; the desktop's <c>SyncHost.ProjectHome</c>): null while this PC is not
|
||||
/// signed in to that server, or it keeps no projects. Without it every server home reads as out of reach.
|
||||
/// </summary>
|
||||
public Func<BundleHome, IProjectHome?>? ServerHomes { get; set; }
|
||||
|
||||
/// <summary>A workspace project's home told that it changed there (any thread): its state is read again.</summary>
|
||||
public event Action<WorkspaceHomeChange>? HomeChanged;
|
||||
|
||||
/// <summary>The home of a workspace project; null for a home this PC cannot reach now (the index not open, a server it is not signed in to).</summary>
|
||||
public IProjectHome? HomeOf(BundleHome home)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(home);
|
||||
return home.IsArchive && _db() is { } db && _archives() is { } archives ? new ArchiveProjectHome(db, archives.Projects, home.SequenceId) : null;
|
||||
if (!home.IsArchive) return ServerHomes?.Invoke(home);
|
||||
return _db() is { } db && _archives() is { } archives ? new ArchiveProjectHome(db, archives.Projects, home.SequenceId) : null;
|
||||
}
|
||||
|
||||
/// <summary>The home of a sequence of this PC's archive (<paramref name="sequenceId"/> is in its index).</summary>
|
||||
public static BundleHome ArchiveHome(Guid sequenceId) => new(BundleHome.ArchiveKind, sequenceId);
|
||||
|
||||
/// <summary>The home of a sequence of this PC's archive.</summary>
|
||||
/// <exception cref="WorkspaceException">The index or the archive engine is not open.</exception>
|
||||
public IProjectHome HomeOfSequence(Guid sequenceId) =>
|
||||
HomeOf(new BundleHome(BundleHome.ArchiveKind, sequenceId)) ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
public IProjectHome HomeOfSequence(Guid sequenceId) => Reachable(ArchiveHome(sequenceId));
|
||||
|
||||
/// <summary>The home <paramref name="home"/> names, which must be reachable now.</summary>
|
||||
/// <exception cref="WorkspaceException">The index or the archive engine is not open (this PC's archive).</exception>
|
||||
/// <exception cref="HomeUnavailableException">This PC is not signed in to the server, or it keeps no projects.</exception>
|
||||
public IProjectHome Reachable(BundleHome home) =>
|
||||
HomeOf(home) ?? (home.IsArchive
|
||||
? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"))
|
||||
: throw new HomeUnavailableException("This PC is not signed in to the server of the project, or it keeps no projects."));
|
||||
|
||||
/// <summary>
|
||||
/// The signed-in server told that a project changed there (phase 5b), or (<paramref name="change"/> null) that changes
|
||||
/// may have been missed: projects of this workspace whose home it is are told (<see cref="HomeChanged"/>).
|
||||
/// </summary>
|
||||
public void OnServerProjectChanged(string server, ProjectChangedEvent? change)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(server);
|
||||
if (change is null)
|
||||
{
|
||||
HomeChanged?.Invoke(new WorkspaceHomeChange(server, null, null));
|
||||
return;
|
||||
}
|
||||
// The folder is named by the project's id: only a project this workspace holds, of that server and sequence, is told.
|
||||
try
|
||||
{
|
||||
if (!IsAvailable || Store.Find(change.ProjectId)?.ReadBundle().Workspace?.Home is not { IsArchive: false } home || home.SequenceId != change.SequenceId
|
||||
|| !string.Equals(home.Server, server, StringComparison.OrdinalIgnoreCase))
|
||||
return;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or InvalidDataException or UnauthorizedAccessException)
|
||||
{
|
||||
Log.Info("workspace", $"A change of project {change.ProjectId} on {server} could not be matched: {ex.Message}");
|
||||
return;
|
||||
}
|
||||
HomeChanged?.Invoke(new WorkspaceHomeChange(server, change.ProjectId, change.Change));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The projects of the workspace; one whose working state cannot be read is listed as damaged (<see cref="WorkspaceEntry.Damaged"/>),
|
||||
@@ -307,10 +368,15 @@ public sealed class WorkspaceHost
|
||||
}
|
||||
|
||||
/// <summary>The home's live projects of a sequence, Main first (made from the sequence's settings when it has none yet).</summary>
|
||||
public Task<IReadOnlyList<SequenceProject>> HomeProjectsAsync(Guid sequenceId, CancellationToken cancellationToken = default)
|
||||
public Task<IReadOnlyList<SequenceProject>> HomeProjectsAsync(Guid sequenceId, CancellationToken cancellationToken = default) =>
|
||||
HomeProjectsAsync(ArchiveHome(sequenceId), cancellationToken);
|
||||
|
||||
/// <summary>The live projects of <paramref name="home"/>'s sequence, Main first (made from the sequence's settings when it has none yet).</summary>
|
||||
/// <exception cref="HomeUnavailableException">A server home this PC cannot reach now.</exception>
|
||||
public Task<IReadOnlyList<SequenceProject>> HomeProjectsAsync(BundleHome home, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var home = HomeOfSequence(sequenceId);
|
||||
return Task.Run(() => home.ListAsync(cancellationToken), cancellationToken);
|
||||
var reached = Reachable(home);
|
||||
return Task.Run(() => reached.ListAsync(cancellationToken), cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -321,10 +387,22 @@ public sealed class WorkspaceHost
|
||||
/// <exception cref="ProjectException">The home has no such project, or the name is invalid or taken.</exception>
|
||||
/// <exception cref="HomeUnavailableException">The archive is offline or busy.</exception>
|
||||
/// <exception cref="WorkspaceException">The workspace folder lies inside a library: nothing was written, here or at the home.</exception>
|
||||
public async Task<WorkspaceCheckout> CheckoutAsync(Guid sequenceId, Guid? projectId, string? newName, string media = BundleMedia.Proxies,
|
||||
public Task<WorkspaceCheckout> CheckoutAsync(Guid sequenceId, Guid? projectId, string? newName, string media = BundleMedia.Proxies,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
CheckoutAsync(ArchiveHome(sequenceId), projectId, newName, media, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Brings a project of <paramref name="home"/>'s sequence (this PC's archive, or the signed-in server) into the workspace
|
||||
/// and queues the copy of its media, as <see cref="CheckoutAsync(Guid, Guid?, string?, string, CancellationToken)"/>.
|
||||
/// </summary>
|
||||
/// <exception cref="ProjectException">The home has no such project, or the name is invalid or taken.</exception>
|
||||
/// <exception cref="HomeUnavailableException">The home cannot be reached now.</exception>
|
||||
/// <exception cref="WorkspaceException">The workspace folder lies inside a library: nothing was written, here or at the home.</exception>
|
||||
public async Task<WorkspaceCheckout> CheckoutAsync(BundleHome home, Guid? projectId, string? newName, string media = BundleMedia.Proxies,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var home = HomeOfSequence(sequenceId);
|
||||
var reached = Reachable(home);
|
||||
var sequenceId = home.SequenceId;
|
||||
var checkout = await Task.Run(async () =>
|
||||
{
|
||||
// Refused before anything is written: the copy job would refuse such a folder after the checkout filled it.
|
||||
@@ -333,11 +411,11 @@ public sealed class WorkspaceHost
|
||||
SequenceProject project;
|
||||
if (newName is not null)
|
||||
{
|
||||
project = await home.CreateAsync(newName, null, null, cancellationToken).ConfigureAwait(false);
|
||||
project = await reached.CreateAsync(newName, null, null, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var listed = await home.ListAsync(cancellationToken).ConfigureAwait(false);
|
||||
var listed = await reached.ListAsync(cancellationToken).ConfigureAwait(false);
|
||||
project = projectId is { } id
|
||||
? listed.FirstOrDefault(p => p.Id == id) ?? throw new ProjectException(ProjectError.NotFound, $"The home has no project {id}.")
|
||||
: listed.First(p => p.IsMain);
|
||||
@@ -345,9 +423,10 @@ public sealed class WorkspaceHost
|
||||
// A copy here this Chronos cannot read (damaged, or a newer Chronos's): nothing is checked out or copied over it.
|
||||
if (Store.Find(project.Id) is { } here && await EntryOrUnreadableAsync(here, cancellationToken).ConfigureAwait(false) is { IsReadable: false } unreadable)
|
||||
throw Unreadable(unreadable);
|
||||
await Sync.CheckoutAsync(home, project.Id, media, cancellationToken).ConfigureAwait(false);
|
||||
var folder = await Sync.CheckoutAsync(reached, project.Id, media, cancellationToken).ConfigureAwait(false);
|
||||
Log.Info("workspace", $"Project {project.Id} ('{project.Name}') of sequence {sequenceId} checked out into {Store.Root}");
|
||||
return new WorkspaceCheckout(project, await QueueCopyCoreAsync(sequenceId, project.Id, media, cancellationToken).ConfigureAwait(false));
|
||||
var title = folder.ReadBundle().Sequence.Title ?? string.Empty;
|
||||
return new WorkspaceCheckout(project, await QueueCopyCoreAsync(home, project.Id, media, title, cancellationToken).ConfigureAwait(false));
|
||||
}, cancellationToken);
|
||||
// Back on the caller's thread (the UI's): the settings are written there.
|
||||
Remember(sequenceId, checkout.Project.Id);
|
||||
@@ -361,20 +440,24 @@ public sealed class WorkspaceHost
|
||||
public Task<Job> QueueCopyAsync(Guid projectId, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
var bundle = Existing(projectId).ReadBundle();
|
||||
return await QueueCopyCoreAsync(bundle.Workspace!.Home.SequenceId, projectId, bundle.Workspace.Media.Kind, cancellationToken).ConfigureAwait(false);
|
||||
return await QueueCopyCoreAsync(bundle.Workspace!.Home, projectId, bundle.Workspace.Media.Kind, bundle.Sequence.Title ?? string.Empty, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Where a project stands. With <paramref name="askHome"/>, against its home's head too: a home that cannot be reached
|
||||
/// reads as offline; one that answers it no longer has the project or its sequence (the sequence left the index) reads
|
||||
/// as <see cref="WorkspaceState.Gone"/>, whose local copy can then only be removed (nothing is removed by itself).
|
||||
/// (a server this PC is not signed in to among them) reads as offline; one that answers it no longer has the project or
|
||||
/// its sequence (the sequence left the index, the project was deleted there) reads as <see cref="WorkspaceState.Gone"/>,
|
||||
/// whose local copy can then only be removed (nothing is removed by itself).
|
||||
/// </summary>
|
||||
public Task<WorkspaceStatus> StatusAsync(Guid projectId, bool askHome = true, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
var project = Existing(projectId);
|
||||
var home = askHome ? HomeOf(project.ReadBundle().Workspace!.Home) : null;
|
||||
var named = project.ReadBundle().Workspace!.Home;
|
||||
var home = askHome ? HomeOf(named) : null;
|
||||
try
|
||||
{
|
||||
if (askHome && home is null && !named.IsArchive) return Offline(await Sync.StatusAsync(projectId, null, cancellationToken).ConfigureAwait(false));
|
||||
return await Sync.StatusAsync(projectId, home, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) when (home is not null && ex is ProjectException or DatabaseException or IOException)
|
||||
@@ -392,6 +475,13 @@ public sealed class WorkspaceHost
|
||||
Conflict = gone ? null : local.Conflict,
|
||||
};
|
||||
}
|
||||
|
||||
static WorkspaceStatus Offline(WorkspaceStatus local) =>
|
||||
local with
|
||||
{
|
||||
Offline = true,
|
||||
State = local.State is WorkspaceState.MediaRemoved or WorkspaceState.Damaged or WorkspaceState.Conflict ? local.State : WorkspaceState.Offline,
|
||||
};
|
||||
}, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
@@ -542,23 +632,30 @@ public sealed class WorkspaceHost
|
||||
|
||||
/// <summary>A new project of the sequence named <paramref name="name"/> from <paramref name="fromVersionId"/> (a version the home holds), else from Main's head.</summary>
|
||||
/// <exception cref="ProjectException">The name is invalid or taken.</exception>
|
||||
public Task<SequenceProject> CreateProjectAsync(Guid sequenceId, string name, Guid? fromVersionId, CancellationToken cancellationToken = default)
|
||||
public Task<SequenceProject> CreateProjectAsync(Guid sequenceId, string name, Guid? fromVersionId, CancellationToken cancellationToken = default) =>
|
||||
CreateProjectAsync(ArchiveHome(sequenceId), name, fromVersionId, cancellationToken);
|
||||
|
||||
/// <summary>A new project of <paramref name="home"/>'s sequence named <paramref name="name"/> from <paramref name="fromVersionId"/>, else from Main's head.</summary>
|
||||
/// <exception cref="ProjectException">The name is invalid or taken.</exception>
|
||||
/// <exception cref="HomeUnavailableException">The home cannot be reached now.</exception>
|
||||
public Task<SequenceProject> CreateProjectAsync(BundleHome home, string name, Guid? fromVersionId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var home = HomeOfSequence(sequenceId);
|
||||
var reached = Reachable(home);
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
var created = await home.CreateAsync(name, fromVersionId, null, cancellationToken).ConfigureAwait(false);
|
||||
Log.Info("workspace", $"Project '{created.Name}' ({created.Id}) made for sequence {sequenceId}");
|
||||
var created = await reached.CreateAsync(name, fromVersionId, null, cancellationToken).ConfigureAwait(false);
|
||||
Log.Info("workspace", $"Project '{created.Name}' ({created.Id}) made for sequence {home.SequenceId}");
|
||||
return created;
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Renames a project at its home, then its working state here.</summary>
|
||||
/// <exception cref="ProjectException">The name is invalid or taken, or the project is gone.</exception>
|
||||
/// <exception cref="HomeUnavailableException">The home cannot be reached now: the name stays.</exception>
|
||||
public Task<string> RenameAsync(Guid projectId, string name, CancellationToken cancellationToken = default) => Task.Run(async () =>
|
||||
{
|
||||
var project = Existing(projectId);
|
||||
var renamed = await ArchiveProjects(project).RenameAsync(projectId, name, cancellationToken).ConfigureAwait(false);
|
||||
var renamed = await HomeOfProject(projectId).RenameAsync(projectId, name, cancellationToken).ConfigureAwait(false);
|
||||
using (await project.LockAsync(LockWait, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
var bundle = project.ReadBundle();
|
||||
@@ -592,8 +689,8 @@ public sealed class WorkspaceHost
|
||||
var status = (await SendAsync(projectId, home, cancellationToken).ConfigureAwait(false)).Status;
|
||||
if (status.State == WorkspaceState.Gone) throw new WorkspaceException(Loc.L("Errors.Workspace.DeletedAtHome"));
|
||||
if (status.Conflict is not null) throw new WorkspaceException(Loc.L("Errors.Workspace.Conflict"));
|
||||
if (status.Ahead > 0 || (status.Modified && !status.ReadOnly)) throw new WorkspaceException(Loc.L("Errors.Workspace.Unsent"));
|
||||
await ArchiveProjects(project).DeleteAsync(projectId, cancellationToken).ConfigureAwait(false);
|
||||
if (status.Ahead > 0 || (status.Modified && !status.ReadOnly)) throw new WorkspaceException(Unsent(workspace.Home));
|
||||
await home.DeleteAsync(projectId, cancellationToken).ConfigureAwait(false);
|
||||
Log.Info("workspace", $"Project {projectId} ('{workspace.Name}') deleted at its home");
|
||||
try
|
||||
{
|
||||
@@ -624,7 +721,7 @@ public sealed class WorkspaceHost
|
||||
var status = (await SyncAsync(projectId, cancellationToken).ConfigureAwait(false)).Status;
|
||||
if (status.State == WorkspaceState.Gone) throw new WorkspaceException(Loc.L("Errors.Workspace.DeletedAtHome"));
|
||||
if (status.Conflict is not null) throw new WorkspaceException(Loc.L("Errors.Workspace.Conflict"));
|
||||
if (status.Ahead > 0 || (status.Modified && !status.ReadOnly)) throw new WorkspaceException(Loc.L("Errors.Workspace.Unsent"));
|
||||
if (status.Ahead > 0 || (status.Modified && !status.ReadOnly)) throw new WorkspaceException(Unsent(Existing(projectId).ReadBundle().Workspace!.Home));
|
||||
}
|
||||
|
||||
/// <summary>The plan of "Remove local copy": the folder's files and size, and what would not be at the home after it.</summary>
|
||||
@@ -682,7 +779,7 @@ public sealed class WorkspaceHost
|
||||
var status = await Sync.StatusAsync(projectId, null, cancellationToken).ConfigureAwait(false);
|
||||
// A version saved here that cannot be read may be one the home never had: only discarding keeps it aside.
|
||||
if (status.Ahead > 0 || status.Damaged > 0 || (status.Modified && !status.ReadOnly) || status.Conflict is not null)
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.Unsent"));
|
||||
throw new WorkspaceException(Unsent(workspace.Home));
|
||||
await VerifyHomeAsync(projectId, workspace, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
await RemoveFolderAsync(project, cancellationToken).ConfigureAwait(false);
|
||||
@@ -742,7 +839,8 @@ public sealed class WorkspaceHost
|
||||
/// <summary>The home holds this copy's work: its head and the base this copy was last in step with read back, each matching its hash.</summary>
|
||||
private async Task VerifyHomeAsync(Guid projectId, BundleWorkspace workspace, CancellationToken cancellationToken)
|
||||
{
|
||||
var home = HomeOf(workspace.Home) ?? throw new WorkspaceException(Loc.L("Errors.Workspace.Offline"));
|
||||
var server = !workspace.Home.IsArchive;
|
||||
var home = HomeOf(workspace.Home) ?? throw new WorkspaceException(WorkspaceText.ForHome("Errors.Workspace.Offline", server));
|
||||
ProjectVersion head;
|
||||
ProjectVersion? basis;
|
||||
bool held;
|
||||
@@ -761,13 +859,16 @@ public sealed class WorkspaceHost
|
||||
}
|
||||
catch (Exception ex) when (ex is HomeUnavailableException or ProjectException or DatabaseException)
|
||||
{
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.Offline"), ex);
|
||||
throw new WorkspaceException(WorkspaceText.ForHome("Errors.Workspace.Offline", server), ex);
|
||||
}
|
||||
if (!held || !ProjectContent.Verifies(head.SettingsJson, head.ContentHash) || basis is null || !ProjectContent.Verifies(basis.SettingsJson, basis.ContentHash)
|
||||
|| (workspace.Base is { } known && !string.Equals(known.ContentHash, basis.ContentHash, StringComparison.OrdinalIgnoreCase)))
|
||||
throw new WorkspaceException(Loc.L("Errors.Workspace.HomeCheck"));
|
||||
throw new WorkspaceException(WorkspaceText.ForHome("Errors.Workspace.HomeCheck", server));
|
||||
}
|
||||
|
||||
/// <summary>"Some work is not in the library (on the server) yet": worded for the project's home.</summary>
|
||||
private static string Unsent(BundleHome home) => WorkspaceText.ForHome("Errors.Workspace.Unsent", !home.IsArchive);
|
||||
|
||||
/// <summary>
|
||||
/// The project's folder taken out of the workspace under its lease: every file and folder in it but the media and the
|
||||
/// lease (the working state, the versions, the sync state, the exports, and whatever else a Chronos keeps there) moved
|
||||
@@ -889,25 +990,42 @@ public sealed class WorkspaceHost
|
||||
_savePreferences();
|
||||
}
|
||||
|
||||
private async Task<Job> QueueCopyCoreAsync(Guid sequenceId, Guid projectId, string media, CancellationToken cancellationToken)
|
||||
/// <summary>
|
||||
/// The copy of a project's media from its home, unless one is waiting or running: a sequence of this PC's archive copied
|
||||
/// from there, a server's downloaded from it (<paramref name="title"/> labels that job: the index has no row for it).
|
||||
/// </summary>
|
||||
private async Task<Job> QueueCopyCoreAsync(BundleHome home, Guid projectId, string media, string title, CancellationToken cancellationToken)
|
||||
{
|
||||
var engine = _engine() ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
var db = _db() ?? throw new WorkspaceException(Loc.L("Editor.Error.NoEngine"));
|
||||
Guid known;
|
||||
lock (_gate) _copies.TryGetValue(projectId, out known);
|
||||
if (known != Guid.Empty && await db.Jobs.GetAsync(known, cancellationToken).ConfigureAwait(false) is { State: JobState.Queued or JobState.Running } running) return running;
|
||||
var sequence = await db.Sequences.GetAsync(sequenceId, cancellationToken).ConfigureAwait(false)
|
||||
?? throw new ProjectException(ProjectError.SequenceNotFound, $"Sequence {sequenceId} is not in the index.");
|
||||
var job = await engine.EnqueueAsync(WorkspaceJobs.Copy(sequence, Store.Root, projectId, media), cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
ArchiveJobRequest request;
|
||||
if (home.IsArchive)
|
||||
{
|
||||
var sequence = await db.Sequences.GetAsync(home.SequenceId, cancellationToken).ConfigureAwait(false)
|
||||
?? throw new ProjectException(ProjectError.SequenceNotFound, $"Sequence {home.SequenceId} is not in the index.");
|
||||
request = WorkspaceJobs.Copy(sequence, Store.Root, projectId, media);
|
||||
}
|
||||
else
|
||||
{
|
||||
request = WorkspaceJobs.CopyFromServer(home.SequenceId, title, home.Server ?? throw new InvalidDataException("A server home names no server."), Store.Root,
|
||||
projectId, media);
|
||||
}
|
||||
var job = await engine.EnqueueAsync(request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
lock (_gate) _copies[projectId] = job.Id;
|
||||
return job;
|
||||
}
|
||||
|
||||
private IProjectHome HomeOfProject(Guid projectId) =>
|
||||
HomeOf(Existing(projectId).ReadBundle().Workspace!.Home) ?? throw new HomeUnavailableException("The project's home cannot be reached from this PC.");
|
||||
|
||||
private ProjectService ArchiveProjects(WorkspaceProject project) =>
|
||||
project.ReadBundle().Workspace!.Home.IsArchive && _archives() is { } archives ? archives.Projects : throw new WorkspaceException(Loc.L("Errors.Workspace.Offline"));
|
||||
/// <exception cref="HomeUnavailableException">The project's home cannot be reached now.</exception>
|
||||
private IProjectHome HomeOfProject(Guid projectId)
|
||||
{
|
||||
var home = Existing(projectId).ReadBundle().Workspace!.Home;
|
||||
return HomeOf(home) ?? throw new HomeUnavailableException(home.IsArchive
|
||||
? "The project's home cannot be reached from this PC."
|
||||
: "This PC is not signed in to the server of the project, or it keeps no projects.");
|
||||
}
|
||||
|
||||
private WorkspaceProject Existing(Guid projectId) => Store.Find(projectId) ?? throw new WorkspaceException(Loc.L("Errors.Workspace.NotCheckedOut"));
|
||||
|
||||
|
||||
Reference in new issue
Block a user