Files
Chronos/src/Chronos.App/Jobs/JobText.cs
T
Alby96andClaude Opus 5.5 2e1c67f531 feat(workspace): lay the phase 5c foundation
Phase 5c (owner review 2, R8) is built by six packages in parallel. This
commit settles everything they share, so each one touches its own files:

- job kinds WorkspaceRender (21), WorkspaceSend (22) and WorkspaceMove (23)
  with their wire names, default priorities, notices and parameter records;
  their handlers are registered as skeletons that throw until their
  package lands
- WorkspaceJobOptions and a new CreateHandlers overload; the earlier ones
  stay and default the options
- originals in the media index (an index of phase 5b reads as proxies
  only), their file names, and the exports/renders.json ledger of local
  renders, written atomically
- the optional project and version of an uploaded render
- the workspace settings (size limit, default media, version on render,
  clean-up age, project to open) and when each project was opened, which
  Reset and Import keep and Export leaves out
- WorkspaceHost split into partial files, with stubs for usage, trash and
  the folder move, removal hooks for unsent renders and last originals,
  and a guard that holds work while the workspace moves
- every new string of the phase in English and Italian, with tooltips

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 15:05:09 +01:00

86 lines
4.3 KiB
C#

using Chronos.App.Infrastructure;
using Chronos.Core.Localization;
using Chronos.Core.Model;
namespace Chronos.App.Jobs;
/// <summary>Localized texts of jobs: kind, speed, time left, place in the queue, state (Jobs screen and job bar).</summary>
public static class JobText
{
/// <summary>"Render", "Deep analysis", …</summary>
public static string Kind(JobKind kind) => Loc.L("Jobs.Kind." + kind);
/// <summary>True for jobs whose items are frames, so their speed reads in fps.</summary>
public static bool CountsFrames(JobKind kind) =>
kind is JobKind.Render or JobKind.Proxies or JobKind.Thumbs or JobKind.DeepAnalyse or JobKind.WorkspaceRender;
/// <summary>True for jobs whose progress counts bytes (hash verification, card import).</summary>
public static bool CountsBytes(JobKind kind) => kind is JobKind.Verify or JobKind.Import;
/// <summary>"11.3 fps" for frame jobs, "57 MB/s" for byte jobs, "41/s" otherwise; empty when unknown.</summary>
public static string Speed(JobKind kind, double? perSecond) => perSecond switch
{
> 0 and var rate when CountsBytes(kind) => Loc.L("Jobs.Speed.Bytes", Formatting.Bytes((long)rate)),
> 0 and var rate => Loc.L(CountsFrames(kind) ? "Jobs.Speed.Fps" : "Jobs.Speed.PerSecond", Formatting.Rate(rate)),
_ => string.Empty,
};
/// <summary>"1,240 / 3,600"; empty while the total is unknown.</summary>
public static string Counter(long done, long total) =>
total > 0 ? Loc.L("Jobs.Counter", Formatting.Count(done), Formatting.Count(total)) : string.Empty;
/// <summary>
/// The "Left" column: time left while running, "after n" while queued, the finish time of the history.
/// </summary>
public static string Left(JobEntry entry, int queuePosition) => entry.State switch
{
JobState.Running => entry.Eta is { } eta ? Formatting.Duration(eta) : string.Empty,
JobState.Queued => queuePosition > 1 ? Loc.L("Jobs.Left.After", queuePosition - 1) : Loc.L("Jobs.Left.Next"),
_ when entry.Job.Finished is { } finished => Formatting.TimeOfDay(finished),
_ => string.Empty,
};
/// <summary>State word, with the run time for done jobs ("done · 2:41").</summary>
public static string State(JobEntry entry)
{
var word = Loc.L("Jobs.State." + entry.State);
return entry.State == JobState.Done && entry.Job is { Started: { } started, Finished: { } finished }
? Loc.L("Jobs.State.WithDetail", word, Formatting.Elapsed(finished - started))
: word;
}
/// <summary>Where the job runs: "this PC" for this machine's workers, the node name otherwise.</summary>
public static string Where(string? nodeId, string localWorkerId)
{
if (string.IsNullOrEmpty(nodeId)) return string.Empty;
return IsLocal(nodeId, localWorkerId) ? Loc.L("Jobs.Where.ThisPc") : NodeName(nodeId);
}
/// <summary>The job was claimed by one of this machine's numbered workers ("node#0", "node#1", …).</summary>
public static bool IsLocal(string? nodeId, string localWorkerId) =>
!string.IsNullOrEmpty(nodeId) && NodeName(nodeId).Equals(localWorkerId, StringComparison.OrdinalIgnoreCase);
/// <summary>"Kind: target" ("Render: Harbour sunset → 4K HEVC"), what a row is called for screen readers.</summary>
public static string Name(Job job) =>
string.IsNullOrWhiteSpace(job.TargetLabel) ? Kind(job.Kind) : Loc.L("Jobs.Row.Name", Kind(job.Kind), job.TargetLabel);
private static string NodeName(string nodeId)
{
var hash = nodeId.IndexOf('#', StringComparison.Ordinal);
return hash < 0 ? nodeId : nodeId[..hash];
}
/// <summary>
/// Job bar line (DESIGN §4): "Render · Harbour sunset · 2,232 / 3,600 · 11.3 fps · 2 min left".
/// </summary>
public static string Bar(JobEntry entry)
{
var parts = new List<string>(5) { Kind(entry.Job.Kind) };
if (!string.IsNullOrWhiteSpace(entry.Job.TargetLabel)) parts.Add(entry.Job.TargetLabel!);
if (Counter(entry.Done, entry.Total) is { Length: > 0 } counter) parts.Add(counter);
if (Speed(entry.Job.Kind, entry.ItemsPerSecond) is { Length: > 0 } speed) parts.Add(speed);
if (entry.Eta is { } eta) parts.Add(Loc.L("Jobs.Bar.Left", Formatting.Duration(eta)));
return string.Join(Loc.Separator, parts);
}
}