diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx
index 8d67e04a..f6288036 100644
--- a/i18n/en/Tooltips.resx
+++ b/i18n/en/Tooltips.resx
@@ -432,7 +432,7 @@
The index has no file to copyNot available on this PCThe index is on PostgreSQL, which its own tools back up
- The archive makes no proxies (Settings › Archive › Proxies)
+ The archive makes no proxies (Settings › Archive › Proxy size)Queued by a schedule (Scheduled tab)Filter by target or kind as you typeOpen what this job worked on to see the problem
@@ -625,8 +625,8 @@
Largest long edge frames are decoded at for deep analysis (half the native size up to this); wider is slower and sees finer detailFree space on the archive driveRoot of the local archive; files are not moved · Enter applies, Esc reverts
- Copy the index to the backups folder, which keeps as many copies as the backup schedules in Jobs › Scheduled · a few seconds
- Copies of the index made by the backup schedules and Back up now; choose the one to return to
+ Copy the index to the backups folder, which keeps as many copies as the backup schedules in Jobs › Scheduled keep · a few seconds
+ Copies of the index made by the Index backup schedule (Jobs › Scheduled) or Back up now; choose the one to return toChoose the archive folderChoose the cache folder; a fast SSD helpsWhere frames spill and thumbnails are kept; a fast SSD helps · Enter applies, Esc reverts
diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx
index 232c9bde..35ab1709 100644
--- a/i18n/it/Tooltips.it.resx
+++ b/i18n/it/Tooltips.it.resx
@@ -423,7 +423,7 @@
Le attività che questa pianificazione ha messo in coda, dalla più recenteMostra questa attività nella coda con il suo logRimuove le voci del registro di controllo più vecchie del limite
- Riduce la cache a Impostazioni › Archiviazione › Limite cache, prima i file più vecchi
+ Riduce la cache a Impostazioni › Spazio su disco › Limite della cache, prima i file più vecchiRimuove le attività concluse più vecchie del limiteElenca le voci del cestino più vecchie del limite; non elimina niente{0} è una pianificazione propria di questo PC: si può modificare, disattivare o ripristinare, non eliminare
@@ -431,7 +431,7 @@
L'indice non ha un file da copiareNon disponibile su questo PCL'indice è su PostgreSQL, che si copia con i propri strumenti
- L'archivio non crea proxy (Impostazioni › Archivio › Proxy)
+ L'archivio non crea proxy (Impostazioni › Archivio › Dimensione proxy)Messa in coda da una pianificazione (scheda Pianificate)Filtra per oggetto o tipo mentre scriviApre l'oggetto dell'attività per vedere il problema
@@ -623,8 +623,8 @@
Lato lungo massimo dei fotogrammi decodificati per l'analisi profonda (metà della dimensione nativa fino a questo); più largo è più lento e vede dettagli più finiSpazio libero sull'unità dell'archivioRadice dell'archivio locale; i file non vengono spostati · Invio applica, Esc annulla
- Copia l'indice nella cartella dei backup, che ne tiene quante le copie pianificate in Attività › Pianificate · pochi secondi
- Copie dell'indice fatte dalle copie pianificate e da Salva una copia; scegli quella a cui tornare
+ Copia l'indice nella cartella dei backup, che ne conserva quante ne tengono le pianificazioni di copia in Attività › Pianificate · pochi secondi
+ Copie dell'indice fatte dalla pianificazione Copia dell'indice (Attività › Pianificate) o da Salva una copia; scegli quella a cui tornareScegli la cartella dell'archivioScegli la cartella della cache; un SSD veloce aiutaDove vanno i fotogrammi temporanei e le miniature; un SSD veloce aiuta · Invio applica, Esc annulla
diff --git a/src/Chronos.App/Infrastructure/AppServices.cs b/src/Chronos.App/Infrastructure/AppServices.cs
index e2e25eec..fa2a549d 100644
--- a/src/Chronos.App/Infrastructure/AppServices.cs
+++ b/src/Chronos.App/Infrastructure/AppServices.cs
@@ -232,7 +232,8 @@ public sealed class AppServices : IAsyncDisposable
///
/// Opens (or creates) the index at , migrates it (after a restore staged in Settings ›
/// Advanced replaced it, which needs no open index: it also recovers one that no longer opens), starts the job engine,
- /// then in the background reopens the archive and starts the schedules ().
+ /// then in the background reopens the archive and starts the schedules (, false at once
+ /// when the index or the engine does not open).
///
public async Task OpenAsync(string databasePath, CancellationToken ct = default)
{
@@ -246,11 +247,21 @@ public sealed class AppServices : IAsyncDisposable
{
OpenError = ex;
Log.Error("app", "The index could not be opened", ex);
+ // No index, no schedules: Jobs › Scheduled says so instead of waiting for them.
+ _schedulerReady.TrySetResult(false);
return;
}
- await StartJobsAsync(Database, startEngine: true, ct);
- Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems);
- Devices.Start();
+ try
+ {
+ await StartJobsAsync(Database, startEngine: true, ct);
+ Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems);
+ Devices.Start();
+ }
+ catch
+ {
+ _schedulerReady.TrySetResult(false);
+ throw;
+ }
_schedules = RunSchedulesAsync(_stopping.Token);
}
diff --git a/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs b/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs
index 51964c5e..52054335 100644
--- a/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs
+++ b/src/Chronos.App/Jobs/ScheduleEditorViewModel.cs
@@ -141,10 +141,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
{
_owner = owner;
_schedule = schedule;
- var available = owner.Actions;
- ActionOptions = [.. ScheduleActions.All.Select(a => available.FirstOrDefault(x => x.Name == a) is { } info
- ? new ScheduleActionOption(a, info.Available, info.Reason)
- : new ScheduleActionOption(a, true, null))];
+ ActionOptions = BuildActionOptions();
_action = schedule is not null
? ActionOptions.FirstOrDefault(o => o.Name == schedule.Action) ?? new ScheduleActionOption(schedule.Action, false, null)
: ActionOptions.FirstOrDefault(o => o.IsAvailable) ?? ActionOptions[0];
@@ -154,7 +151,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
// When: the stored recurrence, or every day at 03:00 for a new schedule.
var recurrence = ScheduleMapping.FromDto(schedule?.Recurrence) ?? ScheduleRecurrence.DailyAt(new TimeOnly(3, 0));
_kindIndex = (int)recurrence.Kind;
- Units = [.. Enum.GetValues().Select(u => new SettingsOption(u, Loc.L("Jobs.Editor.Unit." + u)))];
+ Units = BuildUnits();
_unit = Units.First(u => u.Value == (recurrence.Kind == RecurrenceKind.Every ? recurrence.Unit : RecurrenceUnit.Hours));
Every = new ScheduleField(Number(recurrence.Kind == RecurrenceKind.Every ? recurrence.Every : 6), ValidateEvery, () => Loc.L("Tooltips.Jobs.Editor.Every"));
Time = new ScheduleField(recurrence.Time.ToString("HH:mm", CultureInfo.InvariantCulture), ValidateTime, () => Loc.L("Tooltips.Jobs.Editor.Time"));
@@ -170,7 +167,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
Keep = new ScheduleField(string.Empty, v => ValidateNumber(v, 1, 100), () => Loc.L("Tooltips.Jobs.Editor.Keep"));
LoadParameters(schedule?.Parameters ?? ScheduleActions.Defaults(_action.Name));
- Priorities = [.. new[] { JobPriority.Background, JobPriority.Normal, JobPriority.User }.Select(p => new SettingsOption(p, ScheduleText.Priority(p)))];
+ Priorities = BuildPriorities();
var priority = schedule is not null && JobWire.TryParsePriority(schedule.Priority, out var stored) ? stored : JobPriority.Background;
_priority = Priorities.First(p => p.Value == priority);
_catchUp = schedule?.CatchUp ?? true;
@@ -196,7 +193,8 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
/// The name shown for a system schedule, which is not edited.
public string SystemName => _schedule is null ? string.Empty : ScheduleText.Name(_schedule);
- public IReadOnlyList ActionOptions { get; }
+ /// Every action, with whether this PC runs it as last read; built again when that or the UI language changes.
+ public IReadOnlyList ActionOptions { get; private set; }
public ScheduleActionOption SelectedAction
{
@@ -242,7 +240,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
public ScheduleField Every { get; }
- public IReadOnlyList> Units { get; }
+ public IReadOnlyList> Units { get; private set; }
public SettingsOption SelectedUnit
{
@@ -320,7 +318,7 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
// ---------------- Options ----------------
- public IReadOnlyList> Priorities { get; }
+ public IReadOnlyList> Priorities { get; private set; }
public SettingsOption SelectedPriority
{
@@ -434,14 +432,52 @@ public sealed class ScheduleEditorViewModel : LocalizedViewModel
internal UpdateScheduleRequest BuildUpdate() =>
new(IsSystem ? null : Name.Text.Trim(), IsSystem ? null : _action.Name, Recurrence(), Parameters(), _catchUp, JobWire.Priority(_priority.Value), _enabled);
+ /// Whether this PC runs each action was read again ().
+ internal void RefreshActions() => RebuildActionOptions();
+
protected override void OnLanguageChanged()
{
foreach (var field in new[] { Name, Every, Time, DayOfMonth, OlderThan, Percent, Keep }) field.Refresh();
foreach (var day in Days) day.Refresh();
foreach (var step in Steps) step.Refresh();
+ // The dropdowns' choices carry their labels: new ones in the new language, the same values chosen. Each list is
+ // announced before its choice, so a dropdown finds the choice among its items.
+ RebuildActionOptions();
+ Units = BuildUnits();
+ _unit = Units.First(u => u.Value == _unit.Value);
+ OnPropertyChanged(nameof(Units));
+ OnPropertyChanged(nameof(SelectedUnit));
+ Priorities = BuildPriorities();
+ _priority = Priorities.First(p => p.Value == _priority.Value);
+ OnPropertyChanged(nameof(Priorities));
+ OnPropertyChanged(nameof(SelectedPriority));
base.OnLanguageChanged();
}
+ /// The actions again, from the owner's last read; the chosen one stays chosen.
+ private void RebuildActionOptions()
+ {
+ ActionOptions = BuildActionOptions();
+ _action = ActionOptions.FirstOrDefault(o => o.Name == _action.Name) ?? _action;
+ OnPropertyChanged(nameof(ActionOptions));
+ OnPropertyChanged(nameof(SelectedAction));
+ OnPropertyChanged(nameof(ActionToolTip));
+ }
+
+ private ScheduleActionOption[] BuildActionOptions()
+ {
+ var available = _owner.Actions;
+ return [.. ScheduleActions.All.Select(a => available.FirstOrDefault(x => x.Name == a) is { } info
+ ? new ScheduleActionOption(a, info.Available, info.Reason)
+ : new ScheduleActionOption(a, true, null))];
+ }
+
+ private static SettingsOption[] BuildUnits() =>
+ [.. Enum.GetValues().Select(u => new SettingsOption(u, Loc.L("Jobs.Editor.Unit." + u)))];
+
+ private static SettingsOption[] BuildPriorities() =>
+ [.. new[] { JobPriority.Background, JobPriority.Normal, JobPriority.User }.Select(p => new SettingsOption(p, ScheduleText.Priority(p)))];
+
private bool IsVerify => _action.Name == ScheduleActions.Verify;
/// Save: the schedule as the fields hold it; the editor closes once it is stored, or says why it was not.
diff --git a/src/Chronos.App/Jobs/ScheduleRowViewModel.cs b/src/Chronos.App/Jobs/ScheduleRowViewModel.cs
index e7942033..a9efc077 100644
--- a/src/Chronos.App/Jobs/ScheduleRowViewModel.cs
+++ b/src/Chronos.App/Jobs/ScheduleRowViewModel.cs
@@ -18,6 +18,7 @@ public sealed class ScheduleRowViewModel : ObservableObject
private readonly SchedulesViewModel _owner;
private ScheduleDto _schedule;
private Job? _lastJob;
+ private long _lastJobStamp;
private bool _isEnabled;
internal ScheduleRowViewModel(ScheduleDto schedule, SchedulesViewModel owner)
@@ -105,16 +106,40 @@ public sealed class ScheduleRowViewModel : ObservableObject
/// A newer copy of the schedule (an edit, a run, a correction of its next run).
internal void Update(ScheduleDto schedule)
{
- if (schedule.LastJobId != _schedule.LastJobId) _lastJob = null;
+ if (schedule.LastJobId != _schedule.LastJobId)
+ {
+ // A read of the previous job no longer applies.
+ _lastJob = null;
+ _lastJobStamp++;
+ }
_schedule = schedule;
_isEnabled = schedule.Enabled;
OnAllPropertiesChanged();
}
- /// The job the last run queued changed (or was read): the last result follows its state.
+ /// The job the last run queued changed (live, from the engine): the last result follows its state.
internal void SetLastJob(Job? job)
{
if (job is not null && job.Id != _schedule.LastJobId) return;
+ _lastJobStamp++;
+ ShowLastJob(job);
+ }
+
+ ///
+ /// A read of the last job from the index starts; its result applies only while nothing newer arrived (a live change,
+ /// another job, a later read): see .
+ ///
+ internal long BeginLastJobRead() => ++_lastJobStamp;
+
+ /// The last job as the read begun at found it; ignored when that read is stale.
+ internal void SetLoadedLastJob(Job? job, long read)
+ {
+ if (read != _lastJobStamp || (job is not null && job.Id != _schedule.LastJobId)) return;
+ ShowLastJob(job);
+ }
+
+ private void ShowLastJob(Job? job)
+ {
_lastJob = job;
OnPropertyChanged(nameof(LastJob));
OnPropertyChanged(nameof(LastText));
diff --git a/src/Chronos.App/Jobs/ScheduleText.cs b/src/Chronos.App/Jobs/ScheduleText.cs
index da74732f..b3064aae 100644
--- a/src/Chronos.App/Jobs/ScheduleText.cs
+++ b/src/Chronos.App/Jobs/ScheduleText.cs
@@ -62,9 +62,15 @@ public static class ScheduleText
};
}
- /// "Mon, Thu": the days in the order of the week, short names of the UI language.
- public static string Days(IEnumerable days) =>
- days.Select(DayShort).Aggregate((a, b) => Loc.L("Jobs.Schedule.DayList", a, b));
+ ///
+ /// "Mon, Thu": the days in the order of the UI language's week, from its first day as the editor lists them (Sunday
+ /// first in English, Monday first in Italian), short names of the UI language.
+ ///
+ public static string Days(IEnumerable days)
+ {
+ var first = (int)Loc.Culture.DateTimeFormat.FirstDayOfWeek;
+ return days.OrderBy(d => ((int)d - first + 7) % 7).Select(DayShort).Aggregate((a, b) => Loc.L("Jobs.Schedule.DayList", a, b));
+ }
/// "Mon" in the UI language.
public static string DayShort(DayOfWeek day) => Loc.Culture.DateTimeFormat.GetAbbreviatedDayName(day);
diff --git a/src/Chronos.App/Jobs/SchedulesViewModel.cs b/src/Chronos.App/Jobs/SchedulesViewModel.cs
index e2349dab..e688e165 100644
--- a/src/Chronos.App/Jobs/SchedulesViewModel.cs
+++ b/src/Chronos.App/Jobs/SchedulesViewModel.cs
@@ -241,6 +241,30 @@ public sealed class SchedulesViewModel : LocalizedViewModel
if (_selected is not null) await LoadRunsAsync();
}
+ ///
+ /// Reads again whether this PC runs each action (Jobs › Scheduled is shown: proxies may have been turned on or off,
+ /// another archive chosen): the rows' Run now and tooltips, and the actions of the editor, follow it.
+ ///
+ public async Task RefreshActionsAsync()
+ {
+ if (_attached is not { } scheduler) return;
+ SchedulesDto list;
+ try
+ {
+ list = await Task.Run(() => scheduler.ListAsync());
+ }
+ catch (Exception ex) when (ex is DatabaseException or IOException or InvalidOperationException)
+ {
+ Log.Warning("schedules", "The actions could not be read again", ex);
+ return;
+ }
+ _actions = list.Actions;
+ _steps = list.Steps ?? [];
+ foreach (var row in Rows) row.Refresh();
+ _editor?.RefreshActions();
+ CommandManager.InvalidateRequerySuggested();
+ }
+
/// A job changed (UI thread, from the Jobs screen's flush): the last result and the last runs follow it.
public void OnJob(Job job)
{
@@ -287,6 +311,8 @@ public sealed class SchedulesViewModel : LocalizedViewModel
}
Apply(run.Schedule);
if (run.Outcome == ScheduleOutcome.Queued) return;
+ // This PC no longer runs the action: the row says so from now on.
+ if (run.Outcome == ScheduleOutcome.Unavailable) await RefreshActionsAsync();
_notify(Loc.L("Jobs.Row.Name", row.Name, ScheduleText.Outcome(run.Outcome, null)), ScheduleText.OutcomeToolTip(run.Outcome, run.Schedule.LastRun, null),
ScheduleOutcome.IsFailed(run.Outcome, out _) || run.Outcome == ScheduleOutcome.Unavailable);
}
@@ -326,7 +352,8 @@ public sealed class SchedulesViewModel : LocalizedViewModel
IsDestructive = true,
});
if (!confirmed) return;
- var outcome = await Call(() => scheduler.DeleteAsync(row.Id));
+ // Nullable: a failed call is null, not the enum's first value (Deleted), so its row stays.
+ var outcome = await Call(async () => await scheduler.DeleteAsync(row.Id));
if (outcome is ScheduleDeleteOutcome.Deleted or ScheduleDeleteOutcome.NotFound) Remove(row.Id);
}
@@ -443,12 +470,14 @@ public sealed class SchedulesViewModel : LocalizedViewModel
RaiseState();
}
+ /// Reads the job of the schedule's last run; a change of it announced meanwhile, or a later read, wins.
private async Task LoadLastJobAsync(ScheduleRowViewModel row)
{
if (row.Schedule.LastJobId is not { } id || _database() is not { } db) return;
+ var read = row.BeginLastJobRead();
try
{
- row.SetLastJob(await db.Jobs.GetAsync(id));
+ row.SetLoadedLastJob(await db.Jobs.GetAsync(id), read);
}
catch (DatabaseException ex)
{
@@ -479,7 +508,10 @@ public sealed class SchedulesViewModel : LocalizedViewModel
RaiseRuns();
}
- /// Runs a scheduler call off the UI thread; a failure becomes a toast and null.
+ ///
+ /// Runs a scheduler call off the UI thread; a failure becomes a toast and null (for a value type, ask for its nullable
+ /// type: its default would read as a result).
+ ///
private async Task Call(Func> call)
{
try
diff --git a/src/Chronos.App/Sections/ArchiveViewModel.cs b/src/Chronos.App/Sections/ArchiveViewModel.cs
index 0a1991b3..ba6e7f17 100644
--- a/src/Chronos.App/Sections/ArchiveViewModel.cs
+++ b/src/Chronos.App/Sections/ArchiveViewModel.cs
@@ -189,7 +189,7 @@ public sealed class ArchiveViewModel : SectionViewModel
public ICommand BackupCommand { get; }
- /// "Maintenance ▾ › Restore database…" (BRIEF §12.5): Settings › Advanced, where a daily copy is compared and restored (§6.2).
+ /// "Maintenance ▾ › Restore database…" (BRIEF §12.5): Settings › Advanced, where a backup copy is compared and restored (§6.2).
public ICommand RestoreCommand { get; }
public ICommand MaintenanceCommand { get; }
diff --git a/src/Chronos.App/Sections/JobsViewModel.cs b/src/Chronos.App/Sections/JobsViewModel.cs
index 89808a01..02cd1ac8 100644
--- a/src/Chronos.App/Sections/JobsViewModel.cs
+++ b/src/Chronos.App/Sections/JobsViewModel.cs
@@ -113,7 +113,7 @@ public sealed class JobsViewModel : SectionViewModel
/// Jobs › Scheduled.
public SchedulesViewModel Schedules { get; }
- /// 0 = Queue, 1 = Scheduled (the segmented control's index).
+ /// 0 = Queue, 1 = Scheduled (the segmented control's index). Scheduled, shown, reads the actions' availability again.
public int TabIndex
{
get => _tabIndex;
@@ -122,6 +122,7 @@ public sealed class JobsViewModel : SectionViewModel
if (value is < 0 or > 1 || !Set(ref _tabIndex, value)) return;
OnPropertyChanged(nameof(IsQueue));
OnPropertyChanged(nameof(IsScheduled));
+ if (IsScheduled) _ = Schedules.RefreshActionsAsync();
}
}
@@ -279,9 +280,13 @@ public sealed class JobsViewModel : SectionViewModel
UpdateShell();
}
- /// Failures seen on this screen no longer count on the rail.
+ ///
+ /// Failures seen on this screen no longer count on the rail; back on Scheduled (from Settings, say), the actions'
+ /// availability is read again.
+ ///
protected override void OnActivated()
{
+ if (IsScheduled) _ = Schedules.RefreshActionsAsync();
if (_unseenFailures.Count == 0) return;
_unseenFailures.Clear();
UpdateShell();
diff --git a/src/Chronos.App/Sections/SettingsView.xaml b/src/Chronos.App/Sections/SettingsView.xaml
index 07f1b56c..c6141a23 100644
--- a/src/Chronos.App/Sections/SettingsView.xaml
+++ b/src/Chronos.App/Sections/SettingsView.xaml
@@ -646,7 +646,7 @@
-
+
The copies of the index in the backups folder, newest first (Restore).
+ /// The copies of the index in the backups folder (the Index backup schedule's, Back up now's), newest first (Restore).
public IReadOnlyList Backups
{
get => _backups;
diff --git a/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs b/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs
index a9d1886a..fbb74243 100644
--- a/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs
+++ b/tests/Chronos.App.Tests/Infrastructure/AppServicesTests.cs
@@ -121,6 +121,47 @@ public sealed class AppServicesTests
}
}
+ ///
+ /// Owner review 2, R10: when the index does not open, the schedules are known not to run at once, so Jobs › Scheduled
+ /// says so instead of waiting for them with an empty tab.
+ ///
+ [Test]
+ [WindowsOnly]
+ public void AnIndexThatDoesNotOpenTellsTheScheduledTabTheSchedulesDoNotRun()
+ {
+ var environment = AppEnvironment.ForCapture();
+ try
+ {
+ SingleThreadedContext.Run(async () =>
+ {
+ // "File is not a database", and no staged restore to recover it.
+ Directory.CreateDirectory(Path.GetDirectoryName(environment.DatabasePath)!);
+ await File.WriteAllBytesAsync(environment.DatabasePath, [.. Enumerable.Repeat((byte)0x5A, 8192)]);
+ var services = new AppServices(environment, new AppSettings { Language = "en" }, () => { }, new NoDialogs());
+ try
+ {
+ await services.OpenAsync(environment.DatabasePath);
+ Assert.NotNull(services.OpenError);
+ var ready = services.SchedulerReady;
+ Assert.Same(ready, await Task.WhenAny(ready, Task.Delay(TimeSpan.FromSeconds(TestTiming.Budget(10)))));
+ Assert.False(await ready, "no schedules without an index");
+
+ using var schedules = new SchedulesViewModel(() => services.Scheduler, () => services.Database, _ => false, (_, _, _) => { }, _ => Task.CompletedTask);
+ await schedules.AttachAsync(services.SchedulerReady);
+ Assert.True(schedules.IsLoaded && schedules.IsUnavailable && !schedules.IsRunning, "the tab shows that the schedules do not run");
+ }
+ finally
+ {
+ Assert.True(services.DisposeAsync().AsTask().Wait(TimeSpan.FromSeconds(10)), "services stopped");
+ }
+ });
+ }
+ finally
+ {
+ environment.DeleteCaptureData();
+ }
+ }
+
/// BRIEF §6.2: a restore staged in Settings › Advanced recovers an index that no longer opens.
[Test]
[WindowsOnly]
diff --git a/tests/Chronos.App.Tests/Jobs/ScheduleLanguageTests.cs b/tests/Chronos.App.Tests/Jobs/ScheduleLanguageTests.cs
new file mode 100644
index 00000000..462798f5
--- /dev/null
+++ b/tests/Chronos.App.Tests/Jobs/ScheduleLanguageTests.cs
@@ -0,0 +1,79 @@
+using System.Globalization;
+using Chronos.App.Jobs;
+using Chronos.Core.Localization;
+using Chronos.Core.Model;
+using Chronos.Data.Scheduling;
+using Chronos.Protocol;
+using Chronos.Testing;
+
+namespace Chronos.App.Tests.Jobs;
+
+///
+/// Jobs › Scheduled in another language (owner review 2, R10). These switch the process-wide UI language, so the class is
+/// serial: in parallel it would race with the English assertions of the classes running beside it.
+///
+[Serial]
+public sealed class ScheduleLanguageTests(TestContext context)
+{
+ /// The days of a weekly schedule read in the order of the editor's toggles: from the UI language's first day.
+ [Test]
+ public void WeeklyDaysFollowTheWeekOfTheUiLanguage()
+ {
+ var weekend = ScheduleRecurrence.WeeklyAt([DayOfWeek.Saturday, DayOfWeek.Sunday], new TimeOnly(3, 0));
+ try
+ {
+ Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
+ Assert.Equal(DayOfWeek.Sunday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
+ Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Sunday), ScheduleText.DayShort(DayOfWeek.Saturday)),
+ ScheduleText.Days(weekend.Days));
+ Assert.Equal(Loc.L("Jobs.Schedule.When.Weekly", ScheduleText.Days(weekend.Days), ScheduleText.Time(new TimeOnly(3, 0))), ScheduleText.When(weekend));
+
+ Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
+ Assert.Equal(DayOfWeek.Monday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
+ Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Saturday), ScheduleText.DayShort(DayOfWeek.Sunday)),
+ ScheduleText.Days(weekend.Days));
+ Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Monday), ScheduleText.DayShort(DayOfWeek.Thursday)),
+ ScheduleText.Days([DayOfWeek.Thursday, DayOfWeek.Monday]));
+ }
+ finally
+ {
+ Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
+ }
+ }
+
+ /// The editor's dropdowns say their choices in the new language, and keep what was chosen.
+ [Test]
+ public async Task TheOpenEditorSaysItsChoicesInTheNewLanguage()
+ {
+ Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
+ await using var fx = await ScheduleFixture.CreateAsync(context);
+ using var vm = await fx.ViewModelAsync();
+ vm.NewCommand.Execute(null);
+ var editor = Assert.NotNull(vm.Editor);
+ editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Verify);
+ editor.SelectedUnit = editor.Units.Single(u => u.Value == RecurrenceUnit.Minutes);
+ editor.SelectedPriority = editor.Priorities.Single(p => p.Value == JobPriority.Normal);
+ Assert.Equal(("minutes", "Normal"), (editor.SelectedUnit.Label, editor.SelectedPriority.Label));
+ var actions = editor.ActionOptions;
+ try
+ {
+ Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
+
+ Assert.SequenceEqual(Enum.GetValues().Select(u => Loc.L("Jobs.Editor.Unit." + u)), editor.Units.Select(u => u.Label));
+ Assert.SequenceEqual(["In background", "Normale", "Alta"], editor.Priorities.Select(p => p.Label));
+ Assert.Equal((RecurrenceUnit.Minutes, "minuti"), (editor.SelectedUnit.Value, editor.SelectedUnit.Label));
+ Assert.Equal((JobPriority.Normal, "Normale"), (editor.SelectedPriority.Value, editor.SelectedPriority.Label));
+ Assert.True(editor.Units.Any(u => ReferenceEquals(u, editor.SelectedUnit)) && editor.Priorities.Any(p => ReferenceEquals(p, editor.SelectedPriority)),
+ "the choices are among the new options");
+
+ // The actions are new options too, so their dropdown reads their names again.
+ Assert.False(ReferenceEquals(actions, editor.ActionOptions), "the action list was built again");
+ Assert.Equal(("Scansione archivio", ScheduleActions.Verify), (editor.ActionOptions[0].Label, editor.SelectedAction.Name));
+ Assert.True(editor.ActionOptions.Any(o => ReferenceEquals(o, editor.SelectedAction)), "the action is among the new options");
+ }
+ finally
+ {
+ Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
+ }
+ }
+}
diff --git a/tests/Chronos.App.Tests/Jobs/SchedulesViewModelTests.cs b/tests/Chronos.App.Tests/Jobs/SchedulesViewModelTests.cs
index 7c55ccbb..495aeb9c 100644
--- a/tests/Chronos.App.Tests/Jobs/SchedulesViewModelTests.cs
+++ b/tests/Chronos.App.Tests/Jobs/SchedulesViewModelTests.cs
@@ -1,5 +1,7 @@
using System.Globalization;
+using System.IO;
using Chronos.App.Jobs;
+using Chronos.Core.Archiving;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data.Housekeeping;
@@ -153,6 +155,97 @@ public sealed class SchedulesViewModelTests
Assert.Equal(("Every 10 minutes", false), (scan.WhenText, scan.Schedule.CatchUp));
}
+ /// A delete the index refuses (busy, locked) keeps the row: the schedule still runs, so it stays in sight.
+ [Test]
+ public async Task ADeleteThatFailsKeepsTheRow()
+ {
+ await using var fx = await ScheduleFixture.CreateAsync(_context);
+ var toasts = new List();
+ using var vm = await fx.ViewModelAsync(toasts: toasts);
+ await fx.Scheduler!.CreateAsync(new CreateScheduleRequest("Orphans", ScheduleActions.Orphans, new RecurrenceDto("monthly", Time: "05:00", DayOfMonth: 1)), null);
+ var mine = vm.Rows.Single(r => !r.IsSystem);
+ await using (var session = await fx.Db.Database.OpenAsync(_context.Cancellation))
+ {
+ await session.ExecuteScriptAsync("CREATE TRIGGER refuse_delete BEFORE DELETE ON schedules BEGIN SELECT RAISE(ABORT, 'the index is busy'); END;",
+ _context.Cancellation);
+ }
+
+ await vm.DeleteAsync(mine);
+ Assert.SequenceEqual([Loc.L("Jobs.Schedule.Failed")], toasts);
+ Assert.Count(4, vm.Rows);
+ Assert.Contains(mine, vm.Rows);
+ Assert.NotNull(await fx.Db.Schedules.GetAsync(mine.Id));
+ }
+
+ ///
+ /// Whether this PC runs an action is read again when Jobs › Scheduled is shown: proxies turned on in Settings › Archive
+ /// make the Proxies schedule runnable and the action selectable, without a restart.
+ ///
+ [Test]
+ public async Task ShowingTheTabReadsTheActionsAgain()
+ {
+ await using var fx = await ScheduleFixture.CreateAsync(_context);
+ var archive = await fx.Archives.CreateAsync(Path.Combine(fx.Folder, "archive"), "archive", proxies: new ProxyPolicy { LongEdge = ProxyPolicy.Disabled });
+ fx.Settings.LastArchivePath = archive.RootPath;
+ using var vm = await fx.ViewModelAsync();
+ Assert.Null((await fx.Scheduler!.CreateAsync(new CreateScheduleRequest("Proxies", ScheduleActions.Proxies, new RecurrenceDto("daily", Time: "01:00")), null)).Problem);
+ var proxies = vm.Rows.Single(r => !r.IsSystem);
+ Assert.False(vm.IsAvailable(ScheduleActions.Proxies));
+ Assert.False(proxies.RunNowCommand.CanExecute(null));
+ Assert.Equal(Loc.L("Tooltips.Jobs.Schedule.Unavailable.ProxiesDisabled"), proxies.RunNowToolTip);
+ vm.NewCommand.Execute(null);
+ var editor = Assert.NotNull(vm.Editor);
+ Assert.False(editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies).IsAvailable);
+
+ await fx.Archives.UpdateSettingsAsync(archive.Id, a => a with { Proxies = a.Proxies with { LongEdge = 1920 } }, _context.Cancellation);
+ await vm.RefreshActionsAsync();
+ Assert.True(vm.IsAvailable(ScheduleActions.Proxies));
+ Assert.True(proxies.RunNowCommand.CanExecute(null));
+ Assert.Equal(Loc.L("Tooltips.Jobs.Schedule.RunNow"), proxies.RunNowToolTip);
+ Assert.Equal(ScheduleText.ActionToolTip(ScheduleActions.Proxies), proxies.ActionToolTip);
+ // The open editor follows too; what it had chosen stays chosen.
+ var chosen = editor.SelectedAction.Name;
+ Assert.True(editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies).IsAvailable);
+ Assert.Equal(chosen, editor.SelectedAction.Name);
+ Assert.True(editor.ActionOptions.Any(o => ReferenceEquals(o, editor.SelectedAction)), "the choice is one of the new options");
+ editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Proxies);
+ Assert.Equal(ScheduleActions.Proxies, editor.SelectedAction.Name);
+ }
+
+ ///
+ /// The last result follows the newest news of the last job: a read of it that started before a live change (or before
+ /// a later read) does not put back an older state.
+ ///
+ [Test]
+ public async Task AReadOfTheLastJobNeverUndoesANewerChange()
+ {
+ await using var fx = await ScheduleFixture.CreateAsync(_context);
+ using var vm = await fx.ViewModelAsync();
+ var job = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Backup, State = JobState.Running };
+ // A row of its own: the view model reads nothing into it meanwhile.
+ var row = new ScheduleRowViewModel(vm.Rows[1].Schedule with { LastOutcome = ScheduleOutcome.Queued, LastJobId = job.Id }, vm);
+
+ // The job ends while it is read: the engine's Done comes first, the read's Running after it.
+ var read = row.BeginLastJobRead();
+ row.SetLastJob(job with { State = JobState.Done });
+ row.SetLoadedLastJob(job, read);
+ Assert.Equal(("done", StatusKind.Done), (row.LastText, row.LastKind));
+
+ // Two reads: the later one wins, whichever ends first.
+ var first = row.BeginLastJobRead();
+ var second = row.BeginLastJobRead();
+ row.SetLoadedLastJob(job with { State = JobState.Failed }, second);
+ row.SetLoadedLastJob(job, first);
+ Assert.Equal(StatusKind.Failed, row.LastKind);
+
+ // A read of the job of the previous run does not apply once the schedule has run again.
+ var stale = row.BeginLastJobRead();
+ row.Update(row.Schedule with { LastJobId = Guid.CreateVersion7() });
+ row.SetLoadedLastJob(job with { State = JobState.Done }, stale);
+ Assert.Null(row.LastJob);
+ Assert.Equal(("queued", StatusKind.Queued), (row.LastText, row.LastKind));
+ }
+
[Test]
public async Task TheEditorChecksEachFieldAndBuildsTheRecurrence()
{