Server sequences that are not in the local index open through a RemoteSequenceSource: proxies from the cache, project from the server's settings with their version (a 409 merges again), analysis report from the server, analyses and renders posted as server jobs (one per preset) and followed through the server's events. Set hero now reaches the index (SequenceEdit.HeroFrameId) so the Library card shows it. The Export tab gains the Sync option (remembered in the project) and restores "Save both" copies through undo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
71 lines
2.8 KiB
C#
71 lines
2.8 KiB
C#
using System.IO;
|
|
using Titano.Core.Model;
|
|
using Titano.Data;
|
|
using Titano.Data.Jobs;
|
|
using Titano.Data.Processing;
|
|
using Titano.Data.Sync;
|
|
|
|
namespace Titano.App.Editor;
|
|
|
|
/// <summary>Whether the Export "Sync" option can be used, or why not (its tooltip says which).</summary>
|
|
public enum ExportSyncGate
|
|
{
|
|
Available,
|
|
|
|
/// <summary>A server sequence: its renders are made on the server and stay there.</summary>
|
|
Remote,
|
|
|
|
/// <summary>No server session is open.</summary>
|
|
SignedOut,
|
|
|
|
/// <summary>The server does not have this sequence.</summary>
|
|
NotLinked,
|
|
|
|
/// <summary>The account may not send files to the server.</summary>
|
|
NoUpload,
|
|
}
|
|
|
|
/// <summary>
|
|
/// Export "Sync" (Export.html, BRIEF §14.5): a render made on this PC whose export asked for it is sent to the server
|
|
/// the sequence is linked to once it is done (<see cref="SyncService.EnqueueSendExportsAsync"/>), while signed in with
|
|
/// the Upload right. The choice travels inside the render job (its export), so it holds after the editor closes.
|
|
/// </summary>
|
|
public sealed class ExportSync(TitanoDatabase db, SyncService sync, JobEngine engine)
|
|
{
|
|
/// <summary>The option's state for a sequence.</summary>
|
|
/// <param name="server">Key of the signed-in server; null while signed out.</param>
|
|
/// <param name="linked">The server has the sequence (a sync link joins them).</param>
|
|
public static ExportSyncGate Gate(bool isRemote, string? server, bool linked, bool canUpload) =>
|
|
isRemote ? ExportSyncGate.Remote
|
|
: server is null ? ExportSyncGate.SignedOut
|
|
: !linked ? ExportSyncGate.NotLinked
|
|
: !canUpload ? ExportSyncGate.NoUpload
|
|
: ExportSyncGate.Available;
|
|
|
|
/// <summary>
|
|
/// Queues sending a finished render's output; returns the send job, or null when the job is not a finished render
|
|
/// of this PC that asked for it, or the sequence cannot be sent now.
|
|
/// </summary>
|
|
public async Task<Job?> SendAsync(Job job, string? server, bool canUpload, CancellationToken cancellationToken = default)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(job);
|
|
if (job is not { Kind: JobKind.Render, State: JobState.Done, TargetIds: [var target] } || !Wanted(job)) return null;
|
|
if (await db.Sequences.GetAsync(target, cancellationToken) is not { } local) return null;
|
|
var linked = server is not null && await sync.LinkOfAsync(server, local.Id, cancellationToken) is not null;
|
|
if (Gate(false, server, linked, canUpload) != ExportSyncGate.Available) return null;
|
|
return await sync.EnqueueSendExportsAsync(engine, server!, local, cancellationToken);
|
|
}
|
|
|
|
private static bool Wanted(Job job)
|
|
{
|
|
try
|
|
{
|
|
return ProcessingJobs.ReadRender(job.ParametersJson).Export.SyncToServer;
|
|
}
|
|
catch (InvalidDataException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|