fix(copies): close the owner review 6 second verification findings

Upload again now deletes the gone pair row once the new sequence is linked, so
the pair stops reading "deleted on server" or "kept here". A linked upload the
server refuses into its sequence (403 for an account without Edit that does not
own it) falls back to ordinary uploads instead of failing; an Integrate that
would add photos to such a sequence is blocked in its plan (NoAddRight).
Automatic photo transfers pause on a metered connection whatever the option
says. Integrate trashes server photos only against the manifest version that
checked the winner, and a merge is blocked while the other sequence holds a
damaged photo nothing else holds (DamagedPhotos), so nothing unverified reaches
the trash.

The plan and the confirmations now say what really happens: replaced versions
are no longer counted as kept, a merge lists the kept sequence's replaced
photos, plan lines use the text colour, an integrated pair that left photos out
says new photos move by hand, and a merging pair reads "merging" with its
progress. The Compare dialog gets per-side tooltips, class sizes for both
sides, policy-aware class tooltips, column headings and readable file names;
the sync table shows "deleted there" with Review and warns on skipped rows; the
Edit picker names the server, the Library card shows the match status second,
a deleted server sequence is named instead of "0 photos", and the match
tooltips stop calling a sequence a copy. The capture scenes use the server
name, the link names and consistent sample sizes.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-17 16:08:49 +01:00
1 parent b34b6b6fe0
commit 9657c1711d
44 files changed
+802 -128

No files matched your search

+13 -4
View File
@@ -100,7 +100,11 @@ internal sealed class SampleCopyEngine : ICopyEngine
return Task.FromResult(new MergePlan(copyId, keep ?? Guid.Empty, keepsHere ? pair.Copy.OtherId ?? Guid.Empty : pair.Copy.LocalId, choices, steps, [],
[new RenderStep(Guid.CreateVersion7(), "Alps 2025 4K.mp4", 640_000_000, null)], null, choices.Details.Count, projects,
["card:CANON-EOS-R5:2025-07-14"], [], [pair.Copy.Server ?? "nas"], new DeletePlan([], []), drop.Bytes / 20, 1_240_000_000_000, blocks,
1, 1, 1, 1, "sample"));
1, 1, 1, 1, "sample")
{
// The link that moves is shown by the server's name, as SequenceMerger names it.
LinkNames = [drop.Servers.FirstOrDefault() ?? pair.Copy.Server ?? "nas"],
});
}
public async Task<Job> EnqueueMergeAsync(JobEngine engine, MergePlan plan, CancellationToken ct)
@@ -152,7 +156,8 @@ internal sealed class SampleCopyEngine : ICopyEngine
public Task<IReadOnlyList<CopyTwin>> TwinsAsync(CancellationToken ct) => Task.FromResult<IReadOnlyList<CopyTwin>>(
[.. _pairs.Where(p => p.Copy is { Kind: CopyKind.LocalServer, State: CopyState.Integrated or CopyState.Linked })
.Select(p => new CopyTwin(p.Copy.Id, p.Copy.LocalId, p.Here.Where, "Main", p.Copy.Server ?? string.Empty, p.Copy.RemoteId ?? Guid.Empty, "Vertical"))]);
.Select(p => new CopyTwin(p.Copy.Id, p.Copy.LocalId, p.Here.Where, "Main", p.Copy.Server ?? string.Empty, p.Copy.RemoteId ?? Guid.Empty, "Vertical",
p.There.Where))]);
/// <summary>
/// The photo steps of the choices: photos only on one side travel to the other (unless Choose each leaves them out);
@@ -236,7 +241,7 @@ internal static class SampleCopies
{
var at = start.AddSeconds((from + i) * 10);
var name = $"{prefix}{from + i + 1:0000}.CR3";
var size = 24_000_000L + (from + i) % 7 * 310_000;
var size = Size(from + i);
var sha = $"{cls}{from + i:x8}".PadRight(64, '0');
var h = here ? new CopyPhotoInput(Guid.CreateVersion7(), from + i, name, sha, size, at, false) : null;
var t = there ? new CopyPhotoInput(Guid.CreateVersion7(), from + i, name, cls == PhotoClass.Differs ? sha.Replace('0', '1') : sha, size + (cls == PhotoClass.Differs ? 4_096 : 0), at, false) : null;
@@ -256,8 +261,12 @@ internal static class SampleCopies
Math.Min(1000, shared * 1000 / smaller), shared * 1000 / Math.Max(1, local + other - shared), hints);
}
/// <summary>The size of the sample photo at <paramref name="index"/> (24.0 to 25.9 MB).</summary>
private static long Size(int index) => 24_000_000L + index % 7 * 310_000;
/// <summary>A side's facts; its bytes are the sum of its photos' sizes, so the class table adds up to the header.</summary>
internal static CopyFacts Facts(Sequence sequence, string where, int photos, bool originals = false, IReadOnlyList<string>? servers = null) =>
new(sequence.DisplayTitle, where, sequence.ArchiveId, photos, photos * 24_000_000L, sequence.FirstCapture, sequence.LastCapture,
new(sequence.DisplayTitle, where, sequence.ArchiveId, photos, Enumerable.Range(0, photos).Sum(i => Size(i)), sequence.FirstCapture, sequence.LastCapture,
sequence.CameraModel, photos, sequence.Origin, servers ?? [], originals);
internal static ProjectLine Project(string name, bool main, int versions, int daysAgo) =>
+2
View File
@@ -341,6 +341,8 @@ public sealed class SampleData
FoundAt = Now.AddDays(-2),
UpdatedAt = Now.AddHours(-3),
AnsweredAt = state == CopyState.KeptApart ? Now.AddDays(-12) : null,
// The sample's integrated pair left nothing out: new photos move by themselves.
AutoPhotos = state == CopyState.Integrated,
};
CopyProjectsView Projects(bool other) => new(
[SampleCopies.Project("Main", true, 4, 2), SampleCopies.Project("Vertical", false, 3, 5)],
@@ -254,7 +254,8 @@ public sealed class AppServices : IAsyncDisposable
/// <summary>
/// What the planners know of this PC and the signed-in account. The account's rights stand for its rights over the
/// server's sequence: the server enforces ownership itself, so OwnsOrAdmin reads Delete or an admin right.
/// server's sequence: the server enforces ownership itself, so OwnsOrAdmin reads Delete or an admin right; the account's
/// id lets the Integrate planner see the sequences it owns (sending into one it neither owns nor may edit is refused).
/// </summary>
private CopyPlanContext CopyContext(ISyncRemote? remote)
{
@@ -266,7 +267,10 @@ public sealed class AppServices : IAsyncDisposable
return new CopyPlanContext(System.Environment.MachineName, remote is null ? null : Server.ServerName, rights.CanUpload, rights.CanFetchOriginals,
rights.CanEdit, Has(Permissions.Delete), Has(Permissions.Delete) || Has(Permissions.ManageArchive) || Has(Permissions.ManageUsers),
remote is not null && Sync.HasProjects, user is { QuotaBytes: > 0 } ? Math.Max(0, user.QuotaBytes - user.UsedBytes) : null, new HashSet<Guid>(),
originals);
originals)
{
UserId = user?.Id,
};
}
/// <summary>The name a server key is shown by: the known server's name (by its id), else none (the key is shown).</summary>
+9 -2
View File
@@ -100,8 +100,15 @@ public sealed class SequenceItem : ObservableObject
public string TagsText => string.Join(", ", _sequence.Tags);
/// <summary>Status glyphs of the card and the list (DESIGN §4: glyph + word, never colour alone).</summary>
public IReadOnlyList<CardStatus> Statuses => _match is { } match ? [.. BuildStatuses(_sequence, _isAnalysing), match] : BuildStatuses(_sequence, _isAnalysing);
/// <summary>
/// Status glyphs of the card and the list (DESIGN §4: glyph + word, never colour alone). The match status, the one that
/// asks for a choice, follows the analysis status, so a narrow card cuts the others first.
/// </summary>
public IReadOnlyList<CardStatus> Statuses => WithMatch(BuildStatuses(_sequence, _isAnalysing), _match);
/// <summary><paramref name="statuses"/> with <paramref name="match"/> second (right after the analysis status).</summary>
internal static IReadOnlyList<CardStatus> WithMatch(IReadOnlyList<CardStatus> statuses, CardStatus? match) => match is null ? statuses
: statuses.Count == 0 ? [match] : [statuses[0], match, .. statuses.Skip(1)];
/// <summary>
/// "Also elsewhere" or "Deleted there" (owner review 6, #73): the sequence is in a pair that asks for a choice; set by the
@@ -343,7 +343,7 @@ public sealed class SequencePickerViewModel : LocalizedViewModel
: twins.FirstOrDefault(t => t.LocalId == item.SequenceId && t.ServerProject is not null);
if (twin is null) continue;
var server = string.Equals(twin.Server, Shell.Services.Sync.Server, StringComparison.OrdinalIgnoreCase)
? Shell.Services.Server.Flow.Info?.Name ?? twin.Server : twin.Server;
? Shell.Services.Server.Flow.Info?.Name ?? twin.ServerName : twin.ServerName;
if (item.Entry.IsServerHome) item.SetTwin(twin.LocalHome, twin.LocalProject);
else item.SetTwin(server, twin.ServerProject);
}
@@ -158,6 +158,7 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
if (value is null || !Set(ref _policy, value)) return;
OnPropertyChanged(nameof(PolicyToolTip));
OnPropertyChanged(nameof(IsChoosing));
foreach (var row in _classes) row.Policy = value.Value;
BuildPhotos();
Changed();
}
@@ -209,6 +210,18 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
public string AllHereText => Loc.L(IsMerge ? "Server.Copies.Detail.AllKept" : "Server.Copies.Detail.AllThisPc");
public string AllThereText => Loc.L(IsMerge ? "Server.Copies.Detail.AllOther" : "Server.Copies.Detail.AllServer");
/// <summary>"Take this PC's value for every difference." (a merge: the kept sequence's).</summary>
public string AllHereToolTip => Loc.L(IsMerge ? "Tooltips.Server.Copies.Detail.AllKept" : "Tooltips.Server.Copies.Detail.AllHere");
/// <summary>"Take the server's value for every difference." (a merge: the other sequence's).</summary>
public string AllThereToolTip => Loc.L(IsMerge ? "Tooltips.Server.Copies.Detail.AllOther" : "Tooltips.Server.Copies.Detail.AllThere", ServerName);
/// <summary>The Details part's first value column: this PC, or the kept sequence ("Into Old archive"); the pair's first before one is kept.</summary>
public string DetailHereHeading => IsMerge && _keepId is null ? Here.Where : HereHeading;
/// <summary>The Details part's second value column: the server, or the other sequence.</summary>
public string DetailThereHeading => ThereHeading;
/// <summary>A merge keeping the pair's other sequence: the review compares the pair's first with it, so its two columns swap.</summary>
private bool Swapped => IsMerge && _keepId is { } keep && keep == Copy.OtherId;
@@ -340,7 +353,7 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
private void Build(CopyReview review)
{
Classes = [.. review.Photos.Totals.Where(t => t.Count > 0).Select(t => new CopyClassRow(t))];
Classes = [.. review.Photos.Totals.Where(t => t.Count > 0).Select(t => new CopyClassRow(t, _policy.Value, IsMerge) { Swapped = Swapped })];
_class = _classes.FirstOrDefault(c => c.Class == _startClass)
?? _classes.FirstOrDefault(c => c.Class is not (PhotoClass.Same or PhotoClass.Converted))
?? _classes.FirstOrDefault();
@@ -430,10 +443,18 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
var wasSwapped = Swapped;
_keepId = option.SequenceId;
foreach (var other in _keep.Where(o => !ReferenceEquals(o, option))) other.SetQuietly(false);
foreach (var row in _classes) row.Swapped = Swapped;
Reorient(wasSwapped);
RaiseHeadings();
Changed();
}
private void RaiseHeadings()
{
OnPropertyChanged(nameof(HereHeading));
OnPropertyChanged(nameof(ThereHeading));
Changed();
OnPropertyChanged(nameof(DetailHereHeading));
OnPropertyChanged(nameof(DetailThereHeading));
}
/// <summary>A choice changed: the plan follows once the user pauses.</summary>
@@ -503,6 +524,7 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
var wasSwapped = Swapped;
_keepId = merge.KeepId;
foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
foreach (var row in _classes) row.Swapped = Swapped;
Reorient(wasSwapped);
}
}
@@ -555,11 +577,12 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
var blocks = new List<CopyBlockLine>();
if (_plan is { } plan)
{
// Warnings lead each column: last copies, then the trash.
Lasts(plan.LastCopies, here, there);
Photos(plan.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
Photos(plan.Photos, PhotoAction.Send, PhotoAction.SendVersion, "Server.Copies.Plan.Receives", there);
Trash(plan.Photos, PhotoAction.TrashHere, here);
Trash(plan.Photos, PhotoAction.TrashThere, there);
Photos(plan.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, PhotoAction.TrashHere, "Server.Copies.Plan.Receives", here);
Photos(plan.Photos, PhotoAction.Send, PhotoAction.SendVersion, PhotoAction.TrashThere, "Server.Copies.Plan.Receives", there);
var versions = plan.Photos.Count(p => p.Action == PhotoAction.SendVersion);
if (versions > 0) there.Add(new(Loc.Plural("Server.Copies.Plan.ServerUsesOurs", versions, ServerName), Loc.L("Tooltips.Server.Copies.Plan.ServerUsesOurs")));
// A detail changes on the side that does not keep its own value: this PC takes the server's, the server this PC's.
@@ -580,7 +603,9 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
else if (_merge is { } merge)
{
Lasts(merge.LastCopies, here, there);
Photos(merge.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
// The kept sequence's versions the other's replace go to its archive's trash (Other one wins, or chosen so).
Trash(merge.Photos, PhotoAction.TrashHere, here);
Photos(merge.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, PhotoAction.TrashHere, "Server.Copies.Plan.Receives", here);
if (merge.DetailChanges > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Details", merge.DetailChanges)));
if (merge.Renders.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Renders", merge.Renders.Count)));
if (merge.Projects.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Projects", merge.Projects.Count)));
@@ -601,8 +626,7 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
HereLines = here;
ThereLines = there;
Blocks = blocks;
OnPropertyChanged(nameof(HereHeading));
OnPropertyChanged(nameof(ThereHeading));
RaiseHeadings();
OnPropertyChanged(nameof(ApplyToolTip));
_apply.RaiseCanExecuteChanged();
@@ -614,11 +638,12 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
if (theirs > 0) t.Add(new(Loc.Plural("Server.Copies.Plan.LastCopies", theirs), Loc.L("Tooltips.Server.Copies.Plan.LastCopies"), true));
}
static void Photos(IReadOnlyList<PhotoStep> steps, PhotoAction a, PhotoAction b, string key, List<CopyPlanLine> lines)
// A version step whose photo has a trash step on the same side replaces it: received, not kept as a second version.
static void Photos(IReadOnlyList<PhotoStep> steps, PhotoAction a, PhotoAction b, PhotoAction trash, string key, List<CopyPlanLine> lines)
{
var moving = steps.Where(s => s.Action == a || s.Action == b).ToList();
if (moving.Count > 0) lines.Add(new(Loc.Plural(key, moving.Count, Formatting.Bytes(moving.Sum(s => s.Bytes)))));
var kept = steps.Count(s => s.Action == b);
var kept = KeptVersions(steps, b, trash);
if (kept > 0) lines.Add(new(Loc.Plural("Server.Copies.Plan.Versions", kept)));
}
@@ -665,7 +690,7 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
{
if (_plan is { CanApply: true } plan)
{
if (plan.Destructive && !_shell.Services.Dialogs.Confirm(ReplaceRequest(plan, plan.Context?.ServerName ?? ServerName))) return;
if (plan.Destructive && !_shell.Services.Dialogs.Confirm(ReplaceRequest(plan))) return;
IsBusy = true;
await _engine.EnqueueIntegrateAsync(jobs, plan, CancellationToken.None);
}
@@ -808,11 +833,24 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
await LoadAsync();
}
/// <summary>
/// The second versions <paramref name="version"/> steps keep beside their pair: a version step whose photo has a
/// <paramref name="trash"/> step on the same side replaces it instead (This PC wins, Server wins, Other one wins).
/// </summary>
internal static int KeptVersions(IReadOnlyList<PhotoStep> steps, PhotoAction version, PhotoAction trash)
{
var replaced = steps.Where(s => s.Action == trash).Select(s => s.Key).ToHashSet(StringComparer.Ordinal);
return steps.Count(s => s.Action == version && !replaced.Contains(s.Key));
}
/// <summary>
/// "Replace photos?" (design §8.5): the losing versions under the side that loses them ("On this PC", "On Studio NAS"),
/// each side's last copies named first, every photo once.
/// </summary>
internal static ConfirmRequest ReplaceRequest(IntegratePlan plan, string? server = null)
internal ConfirmRequest ReplaceRequest(IntegratePlan plan) => ReplaceRequest(plan, plan.Context?.ServerName ?? ServerName);
/// <inheritdoc cref="ReplaceRequest(IntegratePlan)"/>
internal static ConfirmRequest ReplaceRequest(IntegratePlan plan, string? server)
{
var trashed = plan.Photos.Where(p => p.Action is PhotoAction.TrashHere or PhotoAction.TrashThere).ToList();
var name = server ?? plan.Context?.ServerName ?? string.Empty;
@@ -836,6 +874,14 @@ public sealed class CopyDialogViewModel : ArchiveDialogViewModel
var drop = plan.KeepId == Copy.LocalId ? There : Here;
var only = _review?.Photos.Of(plan.KeepId == Copy.LocalId ? PhotoClass.OnlyThere : PhotoClass.OnlyHere).Count() ?? 0;
var facts = new List<string> { Loc.Plural("Server.Copies.Plan.DropToTrash", drop.Photos, Formatting.Bytes(drop.Bytes)) };
// The kept sequence's own versions the other's replace go to its trash too: named, the last copies among them first.
var lastKeys = plan.LastCopies.Where(l => l.Side == CopySide.ThisPc).Select(l => l.Key).ToHashSet(StringComparer.Ordinal);
var replaced = plan.Photos.Where(p => p.Action == PhotoAction.TrashHere).ToList();
if (replaced.Count > 0)
{
facts.Add(Loc.Plural("Server.Copies.Confirm.Merge.Replaced", replaced.Count, keep.Where));
facts.AddRange(replaced.Where(p => !lastKeys.Contains(p.Key) && !lastKeys.Contains(p.Sha256 ?? string.Empty)).Select(p => " " + p.FileName));
}
if (only > 0) facts.Add(Loc.Plural("Server.Copies.Confirm.Merge.OnlyHere", only, drop.Where));
if (plan.Renders.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Renders", plan.Renders.Count));
if (plan.Projects.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Projects", plan.Projects.Count));
+73 -34
View File
@@ -27,6 +27,18 @@
<Setter Property="ToolTip" Value="{Binding ToolTip}" />
</Style>
<!-- A plan line reads as text to act on, not as a disabled one: the ring stays, the words take the text colour (a
style trigger outranks the glyph template's Queued colour); warnings keep theirs. -->
<Style x:Key="Status.PlanLine" TargetType="ui:StatusGlyph" BasedOn="{StaticResource {x:Type ui:StatusGlyph}}">
<Setter Property="FontSize" Value="12" />
<Setter Property="Margin" Value="0,0,0,4" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsWarning}" Value="False">
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
</DataTrigger>
</Style.Triggers>
</Style>
<DataTemplate DataType="{x:Type cp:CopyDialogViewModel}">
<Border Style="{StaticResource Border.Dialog}" Width="920" MaxHeight="600">
<Grid>
@@ -73,24 +85,36 @@
<ComboBox Width="170" ItemsSource="{Binding Policies}" SelectedItem="{Binding Policy}" DisplayMemberPath="Label" ToolTip="{Binding PolicyToolTip}"
ItemContainerStyle="{StaticResource ComboBoxItem.Option}" AutomationProperties.Name="{l:Loc Server.Copies.Policy.Label}" />
</StackPanel>
<ListBox Grid.Row="1" ItemsSource="{Binding Classes}" SelectedItem="{Binding SelectedClass}" ItemContainerStyle="{StaticResource ListBoxItem.CopyClass}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" AutomationProperties.Name="{l:Loc Server.Copies.Part.Photos}" Margin="0,0,14,0">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type cp:CopyClassRow}">
<Grid Height="28">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="56" />
<ColumnDefinition Width="70" />
</Grid.ColumnDefinitions>
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" FontSize="12" VerticalAlignment="Center" />
<TextBlock Grid.Column="1" Text="{Binding CountText}" TextAlignment="Right" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
<TextBlock Grid.Column="2" Text="{Binding HereBytesText}" TextAlignment="Right" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}"
Typography.NumeralAlignment="Tabular" FontSize="12" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<DockPanel Grid.Row="1" Margin="0,0,14,0">
<!-- Column headings: the class, how many photos, their size (on the side that holds them). -->
<Grid DockPanel.Dock="Top" Margin="15,0,15,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="56" />
<ColumnDefinition Width="70" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Text="{l:Loc Server.Copies.Part.Photos}" Style="{StaticResource Text.ColumnHeader}" TextAlignment="Right" TextTrimming="CharacterEllipsis" />
<TextBlock Grid.Column="2" Text="{l:Loc Server.Copies.Photo.Size}" Style="{StaticResource Text.ColumnHeader}" TextAlignment="Right" TextTrimming="CharacterEllipsis" />
</Grid>
<ListBox ItemsSource="{Binding Classes}" SelectedItem="{Binding SelectedClass}" ItemContainerStyle="{StaticResource ListBoxItem.CopyClass}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" AutomationProperties.Name="{l:Loc Server.Copies.Part.Photos}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type cp:CopyClassRow}">
<Grid Height="28">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="56" />
<ColumnDefinition Width="70" />
</Grid.ColumnDefinitions>
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" FontSize="12" VerticalAlignment="Center" />
<TextBlock Grid.Column="1" Text="{Binding CountText}" TextAlignment="Right" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" />
<TextBlock Grid.Column="2" Text="{Binding BytesText}" ToolTip="{Binding BytesToolTip}" TextAlignment="Right" VerticalAlignment="Center"
Foreground="{DynamicResource Brush.TextMuted}" Typography.NumeralAlignment="Tabular" FontSize="12" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
<!-- Bring all / Bring none, All: keep both, To trash…, Delete on server…: above the list they act on. -->
<WrapPanel Grid.Column="1" VerticalAlignment="Center" Margin="0,0,0,8">
<Button Style="{StaticResource Button.Link}" Content="{l:Loc Server.Copies.Photo.BringAll}" Command="{Binding BringAllCommand}"
@@ -114,22 +138,23 @@
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type cp:CopyPhotoRow}">
<Grid MinHeight="28" ToolTip="{Binding ToolTip}">
<!-- A Different photo is on both sides: under Choose each its side cell gives way to the name (the choice says the side). -->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="110" />
<ColumnDefinition Width="140" />
<ColumnDefinition Width="*" MinWidth="110" />
<ColumnDefinition Width="72" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<CheckBox IsChecked="{Binding Bring}" ToolTip="{l:Loc Tooltips.Server.Copies.Bring}" AutomationProperties.Name="{Binding BringAccessibleName}"
VerticalAlignment="Center" Margin="0,0,8,0" Visibility="{Binding CanBring, Converter={StaticResource CopyBoolToVisibility}}" />
<TextBlock Grid.Column="1" Text="{Binding TimeText}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" FontSize="12" />
<TextBlock Grid.Column="1" Text="{Binding TimeText}" VerticalAlignment="Center" Typography.NumeralAlignment="Tabular" FontSize="12" TextTrimming="CharacterEllipsis" />
<TextBlock Grid.Column="2" Text="{Binding Name}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" FlowDirection="LeftToRight" FontSize="12" />
<TextBlock Grid.Column="3" Text="{Binding SizeText}" VerticalAlignment="Center" TextAlignment="Right" Typography.NumeralAlignment="Tabular" FontSize="12" />
<TextBlock Grid.Column="4" Text="{Binding SideText}" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0"
TextTrimming="CharacterEllipsis" FontSize="12" />
<ComboBox Grid.Column="5" Width="150" ItemsSource="{Binding Choices}" SelectedItem="{Binding Choice}" DisplayMemberPath="Label"
<TextBlock Grid.Column="4" Width="110" Text="{Binding SideText}" VerticalAlignment="Center" Foreground="{DynamicResource Brush.TextMuted}" Margin="10,0,0,0"
TextTrimming="CharacterEllipsis" FontSize="12" Visibility="{Binding CanChoose, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
<ComboBox Grid.Column="5" Width="150" Margin="10,0,0,0" ItemsSource="{Binding Choices}" SelectedItem="{Binding Choice}" DisplayMemberPath="Label"
ItemContainerStyle="{StaticResource ComboBoxItem.Option}" ToolTip="{l:Loc Tooltips.Server.Copies.Version}"
AutomationProperties.Name="{Binding ChoiceAccessibleName}" Visibility="{Binding CanChoose, Converter={StaticResource CopyBoolToVisibility}}" />
<Button Grid.Column="5" Style="{StaticResource Button.Row}" Content="{l:Loc Server.Copies.Action.Drop}" Command="{Binding DropCommand}"
@@ -144,16 +169,30 @@
</Grid>
<!-- Details: one line per difference, nothing preselected. -->
<Grid Visibility="{Binding IsDetails, Converter={StaticResource CopyBoolToVisibility}}">
<Grid Visibility="{Binding IsDetails, Converter={StaticResource CopyBoolToVisibility}}" Grid.IsSharedSizeScope="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="0,0,0,8" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
<Button Style="{StaticResource Button.Link}" Content="{Binding AllHereText}" Command="{Binding AllHereCommand}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail.All}" Margin="0,0,14,0" />
<Button Style="{StaticResource Button.Link}" Content="{Binding AllThereText}" Command="{Binding AllThereCommand}" ToolTip="{l:Loc Tooltips.Server.Copies.Detail.All}" />
<Button Style="{StaticResource Button.Link}" Content="{Binding AllHereText}" Command="{Binding AllHereCommand}" ToolTip="{Binding AllHereToolTip}" Margin="0,0,14,0" />
<Button Style="{StaticResource Button.Link}" Content="{Binding AllThereText}" Command="{Binding AllThereCommand}" ToolTip="{Binding AllThereToolTip}" />
</StackPanel>
<ItemsControl Grid.Row="1" ItemsSource="{Binding Details}" Focusable="False" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
<!-- Whose value each column holds: this PC and the server, or the kept sequence and the other (they follow the kept one). -->
<Grid Grid.Row="1" Margin="0,0,0,6" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="180" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" SharedSizeGroup="CopyDetailChoice" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Text="{Binding DetailHereHeading}" ToolTip="{Binding DetailHereHeading}" Style="{StaticResource Text.ColumnHeader}"
TextTrimming="CharacterEllipsis" Margin="10,0,0,0" />
<TextBlock Grid.Column="2" Text="{Binding DetailThereHeading}" ToolTip="{Binding DetailThereHeading}" Style="{StaticResource Text.ColumnHeader}"
TextTrimming="CharacterEllipsis" Margin="10,0,0,0" />
</Grid>
<ItemsControl Grid.Row="2" ItemsSource="{Binding Details}" Focusable="False" Visibility="{Binding HasDetails, Converter={StaticResource CopyBoolToVisibility}}">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer VerticalScrollBarVisibility="Auto" Focusable="False">
@@ -168,7 +207,7 @@
<ColumnDefinition Width="180" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" SharedSizeGroup="CopyDetailChoice" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Label}" Style="{StaticResource Text.DialogLabel}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding Label}" />
<TextBlock Grid.Column="1" Text="{Binding HereText}" ToolTip="{Binding HereToolTip}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Margin="10,0,0,0" />
@@ -181,7 +220,7 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock Grid.Row="1" Text="{Binding DetailsEmptyText}" Foreground="{DynamicResource Brush.TextMuted}"
<TextBlock Grid.Row="2" Text="{Binding DetailsEmptyText}" Foreground="{DynamicResource Brush.TextMuted}"
Visibility="{Binding DetailsEmptyText, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
</Grid>
@@ -257,7 +296,7 @@
<ItemsControl ItemsSource="{Binding HereLines}" Focusable="False">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type cp:CopyPlanLine}">
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" FontSize="12" Margin="0,0,0,4" />
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" Style="{StaticResource Status.PlanLine}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
@@ -267,7 +306,7 @@
<ItemsControl ItemsSource="{Binding ThereLines}" Focusable="False">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type cp:CopyPlanLine}">
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" FontSize="12" Margin="0,0,0,4" />
<ui:StatusGlyph Kind="{Binding Kind}" Text="{Binding Text}" ToolTip="{Binding ShownToolTip}" Style="{StaticResource Status.PlanLine}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
@@ -180,10 +180,10 @@ public sealed class CopyListViewModel : ObservableObject, IDisposable
}
/// <summary>Opens the Compare dialog of the pair the sequence is in (Library › Compare…); false when it is in none.</summary>
public bool Compare(Guid sequenceId)
public bool Compare(Guid sequenceId, PhotoClass? photos = null)
{
if (_pairs.FirstOrDefault(p => p.Copy.Id == PairOf(sequenceId)?.Id) is not { } pair) return false;
Open(pair, CopyDialogPart.Photos);
Open(pair, CopyDialogPart.Photos, photos);
return true;
}
@@ -431,7 +431,7 @@ public sealed class CopyListViewModel : ObservableObject, IDisposable
private void OnJobChanged(Job job)
{
if (job.Kind is not (JobKind.Integrate or JobKind.MergeSequences)) return;
if (!Follows(job.Kind)) return;
Dispatch(() =>
{
foreach (var row in Rows.Where(r => r.Copy.JobId == job.Id)) row.UpdateJob(job.State, job.ProgressDone, job.ProgressTotal);
@@ -441,13 +441,16 @@ public sealed class CopyListViewModel : ObservableObject, IDisposable
private void OnProgress(JobProgressInfo info)
{
if (info.Kind is not JobKind.Integrate) return;
if (!Follows(info.Kind)) return;
Dispatch(() =>
{
foreach (var row in Rows.Where(r => r.Copy.JobId == info.JobId)) row.UpdateJob(JobState.Running, info.Done, info.Total);
});
}
/// <summary>The jobs a pair's row follows: an Integrate, and a Merge, whose steps come through Progress only (MergeJobHandler).</summary>
internal static bool Follows(JobKind kind) => kind is JobKind.Integrate or JobKind.MergeSequences;
private static void Dispatch(Action action)
{
if (System.Windows.Application.Current?.Dispatcher is not { } dispatcher || dispatcher.CheckAccess()) action();
+59 -3
View File
@@ -9,17 +9,73 @@ using Chronos.Ui.Mvvm;
namespace Chronos.App.Server.Copies;
/// <summary>A line of the Photos part's class table: glyph and class, count, bytes on each side, what it means.</summary>
public sealed class CopyClassRow(PhotoClassTotal total) : ObservableObject
/// <summary>
/// A line of the Photos part's class table: glyph and class, count, size (this side's, else the other side's; both in the
/// tooltip when both sides hold bytes), and what the run does with it under the chosen policy.
/// </summary>
public sealed class CopyClassRow(PhotoClassTotal total, CopyPhotoPolicy policy = CopyPhotoPolicy.Union, bool isMerge = false) : ObservableObject
{
private CopyPhotoPolicy _policy = policy;
private bool _swapped;
public PhotoClass Class { get; } = total.Class;
public StatusKind Kind => CopyText.ClassKind(Class);
public string Text => CopyText.Class(Class);
public string CountText => Formatting.Count(total.Count);
public string HereBytesText => total.HereBytes > 0 ? Formatting.Bytes(total.HereBytes) : string.Empty;
public string ThereBytesText => total.ThereBytes > 0 ? Formatting.Bytes(total.ThereBytes) : string.Empty;
public string ToolTip => CopyText.ClassToolTip(Class);
/// <summary>The size cell: this side's bytes, or the other side's when this side holds none (Only there, Deleted here).</summary>
public string BytesText => total.HereBytes > 0 ? HereBytesText : ThereBytesText;
/// <summary>"This PC 51.4 MB · Server 51.8 MB" when both sides hold bytes (Different); otherwise the side the cell shows.</summary>
public string? BytesToolTip
{
get
{
var here = total.HereBytes > 0 ? Side(true) + " " + HereBytesText : null;
var there = total.ThereBytes > 0 ? Side(false) + " " + ThereBytesText : null;
return here is null && there is null ? null : string.Join(Loc.Separator, new[] { here, there }.Where(s => s is not null));
}
}
/// <summary>The policy the dialog runs with; the tooltip follows it.</summary>
public CopyPhotoPolicy Policy
{
get => _policy;
set
{
if (Set(ref _policy, value)) OnPropertyChanged(nameof(ToolTip));
}
}
/// <summary>A merge keeping the pair's other sequence: this PC's side is the dropped one.</summary>
public bool Swapped
{
get => _swapped;
set
{
if (!Set(ref _swapped, value)) return;
OnPropertyChanged(nameof(ToolTip));
OnPropertyChanged(nameof(BytesToolTip));
}
}
public string ToolTip => CopyText.ClassToolTip(Oriented, _policy, isMerge);
public int Count => total.Count;
/// <summary>The class seen from the kept sequence (a swapped merge reads Only here as the other's photos).</summary>
private PhotoClass Oriented => !isMerge || !_swapped ? Class : Class switch
{
PhotoClass.OnlyHere => PhotoClass.OnlyThere,
PhotoClass.OnlyThere => PhotoClass.OnlyHere,
PhotoClass.DeletedHere => PhotoClass.DeletedThere,
PhotoClass.DeletedThere => PhotoClass.DeletedHere,
_ => Class,
};
private string Side(bool here) => Loc.L(isMerge ? (here != _swapped ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other")
: here ? "Server.Copies.Detail.ThisPc" : "Server.Copies.Detail.Server");
}
/// <summary>
+1 -1
View File
@@ -82,7 +82,7 @@ public sealed class CopyRow : ObservableObject
: string.Join(Loc.Separator, _view.Here.Title, _view.There.Title);
public string HereText => CopyText.Where(_view.Here, isServer: false);
public string ThereText => CopyText.Where(_view.There, isServer: Copy.Kind == CopyKind.LocalServer);
public string ThereText => CopyText.Where(_view.There, isServer: Copy.Kind == CopyKind.LocalServer, Copy.RemoteGone);
public StatusKind StateKind => CopyText.State(Copy, _rights.ServerName, _progress).Kind;
public string StateText => CopyText.State(Copy, _rights.ServerName, _progress).Text;
+2 -1
View File
@@ -90,7 +90,8 @@ public static class CopyScenes
if (await ShowAsync(shell, "server-copies-plan") is not { } dialog) return null;
dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ThisPcWins);
await dialog.PlanNowAsync();
var request = dialog.Plan is { } plan ? CopyDialogViewModel.ReplaceRequest(plan) : null;
// Worded as the dialog words it: the plan's server name, else the signed-in one's.
var request = dialog.Plan is { } plan ? dialog.ReplaceRequest(plan) : null;
shell.Server.CloseDialog(dialog);
return request;
}
+40 -12
View File
@@ -54,17 +54,23 @@ public static class CopyText
CopyState.KeptApart => (StatusKind.Offline, Loc.L("Server.Copies.State.KeptApart"),
Loc.L("Tooltips.Server.Copies.State.KeptApart", Formatting.Date(copy.AnsweredAt ?? copy.UpdatedAt))),
CopyState.Linked => (StatusKind.Synced, Loc.L("Server.Copies.State.Linked"), Loc.L("Tooltips.Server.Copies.State.Linked")),
// The share in the cell (it fits the column in both languages); "1,234 of 2,400" in the tooltip.
CopyState.Integrating => (StatusKind.Running,
Loc.L("Server.Copies.State.Integrating", Percent(progress)),
progress is { Total: > 0 } p
? string.Join(Environment.NewLine, Loc.L("Tooltips.Server.Copies.State.Integrating"),
Loc.L("Server.Copies.State.Progress", Formatting.Count(p.Done), Formatting.Count(p.Total)))
: Loc.L("Tooltips.Server.Copies.State.Integrating")),
// The share in the cell (it fits the column in both languages); "1,234 of 2,400" in the tooltip. A pair of this
// PC's archives is being merged, not integrated.
CopyState.Integrating => Running(copy.Kind == CopyKind.LocalLocal ? "Merging" : "Integrating", progress),
// An Integrate that left photos out moves new photos only on Upload and Download (IntegrateJobHandler).
_ when copy.Kind == CopyKind.LocalServer && !copy.AutoPhotos =>
(StatusKind.Done, Loc.L("Server.Copies.State.Integrated"), Loc.L("Tooltips.Server.Copies.State.IntegratedByHand")),
_ => (StatusKind.Done, Loc.L("Server.Copies.State.Integrated"), Loc.L("Tooltips.Server.Copies.State.Integrated")),
};
}
private static (StatusKind, string, string) Running(string word, (long Done, long Total)? progress) => (StatusKind.Running,
Loc.L("Server.Copies.State." + word, Percent(progress)),
progress is { Total: > 0 } p
? string.Join(Environment.NewLine, Loc.L("Tooltips.Server.Copies.State." + word),
Loc.L("Server.Copies.State.Progress", Formatting.Count(p.Done), Formatting.Count(p.Total)))
: Loc.L("Tooltips.Server.Copies.State." + word));
/// <summary>How far an Integrate or Merge job came, in whole per cent ("51"); "0" before it reports.</summary>
private static string Percent((long Done, long Total)? progress) => progress is { Total: > 0 } p
? Math.Clamp(p.Done * 100 / p.Total, 0, 100).ToString("0", Loc.Culture)
@@ -74,9 +80,12 @@ public static class CopyText
public static string SharedPercent(CopyScore score) =>
Math.Round(Math.Clamp(score.Containment, 0, 1000) / 10.0).ToString("0", Loc.Culture);
/// <summary>"Main archive · 1,204 photos": where one side of a pair lies.</summary>
public static string Where(CopyFacts facts, bool isServer) =>
Loc.Plural(isServer ? "Server.Copies.Where.Server" : "Server.Copies.Where.Archive", facts.Photos, facts.Where);
/// <summary>
/// "Main archive · 1,204 photos": where one side of a pair lies; the server's name alone once it deleted its sequence
/// (<paramref name="gone"/>: no count is known, and "0 photos" would read as an empty sequence).
/// </summary>
public static string Where(CopyFacts facts, bool isServer, bool gone = false) => gone && facts.Where.Length > 0 ? facts.Where
: Loc.Plural(isServer ? "Server.Copies.Where.Server" : "Server.Copies.Where.Archive", facts.Photos, facts.Where);
/// <summary>
/// "Main archive · 1,204 photos · 18.2 GB": a side of the dialog's header; "Lighthouse · Main archive · 1,204 photos ·
@@ -159,7 +168,26 @@ public static class CopyText
/// <summary>The word of a photo class ("Only here").</summary>
public static string Class(PhotoClass c) => Loc.L("Server.Copies.Class." + c);
public static string ClassToolTip(PhotoClass c) => Loc.L("Tooltips.Server.Copies.Class." + c);
/// <summary>
/// What a class means and what the run does with it under <paramref name="policy"/>: Different by the winning side or
/// the per-photo choice, Only here and Only there ticked under Choose each, and a merge's own wording (the other
/// sequence's photos all come in; the kept one's stay). A merge's classes are read from the kept sequence's side.
/// </summary>
public static string ClassToolTip(PhotoClass c, CopyPhotoPolicy policy = CopyPhotoPolicy.Union, bool isMerge = false)
{
var variant = (c, policy) switch
{
(PhotoClass.Differs, CopyPhotoPolicy.ThisPcWins) => isMerge ? ".KeptWins" : ".ThisPcWins",
(PhotoClass.Differs, CopyPhotoPolicy.OtherWins) => isMerge ? ".OtherCopyWins" : ".OtherWins",
(PhotoClass.Differs, CopyPhotoPolicy.ChoosePerPhoto) => ".Choose",
(PhotoClass.Differs, _) when isMerge => ".Merge",
(PhotoClass.OnlyHere or PhotoClass.OnlyThere, _) when isMerge => ".Merge",
(PhotoClass.OnlyHere or PhotoClass.OnlyThere, CopyPhotoPolicy.ChoosePerPhoto) => ".Choose",
(PhotoClass.SameUnhashed, _) when !isMerge => ".Integrate",
_ => string.Empty,
};
return Loc.L("Tooltips.Server.Copies.Class." + c + variant);
}
/// <summary>The glyph of a photo class: what an Integrate settles by itself is fine; what waits for a choice is a warning.</summary>
public static StatusKind ClassKind(PhotoClass c) => c switch
@@ -177,7 +205,7 @@ public static class CopyText
CopyBlock.NeedsNewerServer => Loc.L("Errors.Copies.NeedsNewerServer", server ?? string.Empty),
CopyBlock.LinkTaken => Loc.L("Errors.Copies.LinkTaken", title, server ?? string.Empty),
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", title, need ?? string.Empty),
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile => Loc.L("Errors.Copies." + block, title),
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile or CopyBlock.DamagedPhotos => Loc.L("Errors.Copies." + block, title),
CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", title),
CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", server ?? string.Empty),
CopyBlock.TrashBlocked => Loc.L("Errors.Copies.TrashBlocked", title, need ?? string.Empty),
+1 -1
View File
@@ -22,7 +22,7 @@ public sealed class SyncRowAction : ObservableObject
}
public SyncAction Action { get; }
public string Text => Action == SyncAction.Compare ? Loc.L("Server.Copies.Action.Compare") : Loc.L("Server.Sync.Action." + Action);
public string Text => Action is SyncAction.Compare or SyncAction.Review ? Loc.L("Server.Copies.Action." + Action) : Loc.L("Server.Sync.Action." + Action);
public ICommand Command => _command;
public string ToolTip
@@ -435,6 +435,9 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
case SyncAction.Compare:
Copies.Compare(entry.Local?.Id ?? entry.Id);
return;
case SyncAction.Review:
Copies.Compare(entry.Local?.Id ?? entry.Id, PhotoClass.DeletedThere);
return;
case SyncAction.Upload:
await service.EnqueueUploadAsync(engine, server, entry.Local!);
break;
+17 -2
View File
@@ -46,6 +46,9 @@ public enum SyncAction
/// <summary>Compare the row's sequence with its match (owner review 6, #73).</summary>
Compare,
/// <summary>Open Compare on the photos the match deleted (design §6.2: "deleted there · n" with Review).</summary>
Review,
}
/// <summary>
@@ -196,6 +199,12 @@ public static class SyncText
? (StatusKind.Offline, Loc.L("Server.Sync.State.KeptHere"), Loc.L("Tooltips.Server.Copies.State.KeptHere"))
: (StatusKind.Warning, Loc.L("Server.Sync.State.RemoteGone"), Loc.L("Tooltips.Server.Copies.State.RemoteGone"));
}
// The match deleted photos this side still holds: the pair row's words, with Review among the actions.
if (DeletedThere(mark) is > 0 and var deleted)
{
var key = mark.Copy!.Kind == Data.Copies.CopyKind.LocalLocal ? "Server.Copies.State.DeletedOther" : "Server.Copies.State.DeletedThere";
return (StatusKind.Warning, Loc.L(key, Formatting.Count(deleted)), Loc.Plural("Tooltips.Server.Copies.State.DeletedThere", deleted));
}
if (mark.NotSent is { Count: >= SyncAgent.NotSentAfter } failure)
return (StatusKind.Warning, Loc.L("Server.Sync.State.NotSent"), Loc.L("Tooltips.Server.Sync.State.NotSent", failure.Reason));
// A match between two of this PC's archives names the other archive, not the server.
@@ -204,22 +213,27 @@ public static class SyncText
? Loc.L("Tooltips.Library.Status.CopyFoundLocal", mark.OtherWhere ?? string.Empty)
: Loc.L("Tooltips.Server.Sync.State.CopyFound", mark.ServerName ?? mark.Copy.Server ?? string.Empty));
if (mark.Skipped is { } why && entry.Status == SyncStatus.LocalOnly)
return (StatusKind.Offline, Loc.L("Server.Sync.State.Skipped"), Loc.L("Tooltips.Server.Sync.State.Skipped", Loc.L("Tooltips.Server.Sync.Skip." + why)));
return (StatusKind.Warning, Loc.L("Server.Sync.State.Skipped"), Loc.L("Tooltips.Server.Sync.State.Skipped", Loc.L("Tooltips.Server.Sync.Skip." + why)));
return State(entry);
}
/// <summary>
/// The row's buttons with its match (design §8.1): a sequence in an unanswered pair offers Compare… first, then its usual
/// buttons; a linked one offers Compare… last.
/// buttons; a linked one offers Compare… last, and Review… after it when the match deleted photos.
/// </summary>
public static IReadOnlyList<SyncAction> Actions(SyncEntry entry, SyncRights rights, SyncMark mark)
{
var actions = Actions(entry, rights);
if (entry.Transfer is not null || mark.Copy is null || mark.Copy.RemoteGone) return actions;
if (mark.IsCandidate) return [SyncAction.Compare, .. actions];
if (DeletedThere(mark) > 0) return [.. actions, SyncAction.Compare, SyncAction.Review];
return entry.Link is not null ? [.. actions, SyncAction.Compare] : actions;
}
/// <summary>The photos a linked or integrated match deleted that this side still holds; 0 otherwise.</summary>
private static int DeletedThere(SyncMark mark) =>
mark.Copy is { RemoteGone: false, State: Data.Copies.CopyState.Linked or Data.Copies.CopyState.Integrated } copy ? copy.Score.DeletedThere : 0;
/// <summary>The label of a detail line of the Compare dialog ("Deflicker window"); "Other setting" when unknown.</summary>
public static string DetailLabel(string path)
{
@@ -417,6 +431,7 @@ public static class SyncText
SyncAction.SendExports => Loc.Plural("Tooltips.Server.Sync.SendExports", entry.Link!.ExportsToSend, Formatting.Bytes(Size(entry, action))),
SyncAction.OpenInWorkspace when !rights.KeepsProjects => Loc.L("Tooltips.Server.Sync.OpenInWorkspace.NoProjects"),
SyncAction.Compare => Loc.L("Tooltips.Server.Copies.Compare"),
SyncAction.Review => Loc.L("Tooltips.Server.Copies.Review"),
_ => Loc.L("Tooltips.Server.Sync." + action),
};
+25 -11
View File
@@ -4,6 +4,7 @@ using Chronos.App.Infrastructure;
using Chronos.Core.Diagnostics;
using Chronos.Core.Model;
using Chronos.Data.Jobs;
using Chronos.Data.Sync;
using Chronos.Data.Workspaces;
namespace Chronos.App.Server;
@@ -12,9 +13,11 @@ namespace Chronos.App.Server;
/// "Pause metered transfers" (Server.html): while <see cref="AppSettings.PauseUploadsOnMetered"/> is on and Windows reports
/// the connection as metered, the transfers with a server are paused (a running one stops after its current chunk or file
/// and keeps its checkpoint): upload jobs, the sync's downloads, and since phase 5c the workspace's copies from a server and
/// its renders sent to one, and since owner review 6 the integration of a pair with a server sequence (<see cref="Holds"/>); a copy from or a send to this PC's archive is never held. They are resumed when the connection
/// is no longer metered or the option goes off. Only the jobs it paused are resumed. Checked when the network or one of
/// those jobs changes, and every minute.
/// its renders sent to one, and since owner review 6 the integration of a pair with a server sequence (<see cref="Holds"/>); a copy from or a send to this PC's archive is never held.
/// The automatic transfers of an integrated pair's new photos are held on a metered connection even with the option off
/// (owner review 6, Q6; <see cref="HeldNow"/>). They are resumed when the connection is no longer metered or the option
/// goes off (for the jobs only it holds). Only the jobs it paused are resumed. Checked when the network or one of those
/// jobs changes, and every minute.
/// </summary>
public sealed class UploadHold : IDisposable
{
@@ -55,8 +58,6 @@ public sealed class UploadHold : IDisposable
if (_engine is not null) _engine.JobChanged -= OnJobChanged;
}
private bool Holding => _services.Settings.PauseUploadsOnMetered && MeteredNetwork.IsMetered();
private void OnNetworkChanged(object? sender, EventArgs e) => Request();
private void OnJobChanged(Job job)
@@ -86,32 +87,45 @@ public sealed class UploadHold : IDisposable
};
}
/// <summary>
/// Whether <paramref name="job"/> is held now: on a metered connection, a job <see cref="Holds"/> names while the option
/// is on, and an automatic transfer of an integrated pair's new photos whatever the option says (owner review 6, Q6:
/// new photos move by themselves "paused on metered connections").
/// </summary>
internal static bool HeldNow(Job job, bool metered, bool optionOn) =>
metered && Holds(job) && (optionOn || SyncService.IsAutomaticTransfer(job));
private async Task ApplyAsync()
{
if (_engine is not { } engine || _services.Database is not { } db) return;
await _gate.WaitAsync();
try
{
if (Holding)
// Read once per pass: the connection's cost and the option.
var metered = MeteredNetwork.IsMetered();
var optionOn = _services.Settings.PauseUploadsOnMetered;
if (metered)
{
foreach (var state in new[] { JobState.Queued, JobState.Running })
{
foreach (var kind in Kinds)
{
foreach (var job in (await db.Jobs.ListAsync(state, kind, 500)).Items.Where(Holds))
foreach (var job in (await db.Jobs.ListAsync(state, kind, 500)).Items.Where(j => HeldNow(j, metered, optionOn)))
{
await engine.PauseAsync(job.Id);
_held.Add(job.Id);
}
}
}
return;
}
foreach (var id in _held)
// The jobs this hold paused that no longer need holding (the connection, or the option for a job only it holds) resume.
foreach (var id in _held.ToList())
{
if (await db.Jobs.GetAsync(id) is { State: JobState.Paused }) await engine.ResumeAsync(id);
var job = await db.Jobs.GetAsync(id);
if (job is not null && HeldNow(job, metered, optionOn)) continue;
if (job is { State: JobState.Paused }) await engine.ResumeAsync(id);
_held.Remove(id);
}
_held.Clear();
}
catch (Data.DatabaseException ex)
{
+34 -1
View File
@@ -144,6 +144,10 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
var losers = steps.Where(s => s.Action == PhotoAction.TrashHere).Select(s => s.FrameId!.Value).ToHashSet();
var keepHolds = here.Photos.Where(p => !p.Unusable && p.Sha256 is { Length: > 0 } && !losers.Contains(p.FrameId))
.Select(p => p.Sha256!.ToLowerInvariant()).ToHashSet(StringComparer.Ordinal);
// Photos of the other a verify flagged Corrupt (changed since import, or damaged) whose file is still there: the
// comparison leaves them out, so nothing would copy or hash-verify them before their folder goes to the trash. One
// whose content now nothing else holds (an edited photo's only copy) blocks the merge until it is resolved.
if (online && await DamagedAsync(drop, dropPaths, keepHolds, ct).ConfigureAwait(false)) blocks.Add(CopyBlock.DamagedPhotos);
var absent = new List<CopyPhotoInput>();
foreach (var frame in there.Photos.Where(p => !p.Unusable && p.Sha256 is { Length: > 0 }))
{
@@ -276,6 +280,35 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
return changed ? there with { Photos = photos } : null;
}
/// <summary>
/// Whether the other sequence holds a frame flagged Corrupt (not Missing) whose file is still there and whose content,
/// hashed now (in memory), neither the kept sequence (<paramref name="keepHolds"/>) nor any other sequence of this
/// index holds; an unreadable such file counts too.
/// </summary>
private async Task<bool> DamagedAsync(Guid drop, ArchivePaths dropPaths, IReadOnlySet<string> keepHolds, CancellationToken ct)
{
var flagged = (await _db.Frames.ListBySequenceAsync(drop, cancellationToken: ct).ConfigureAwait(false))
.Where(f => (f.Flags & FrameFlags.Corrupt) != 0 && (f.Flags & FrameFlags.Missing) == 0).ToList();
var hashes = new List<string>();
foreach (var frame in flagged)
{
var path = dropPaths.FromRelative(frame.RelativePath);
if (!File.Exists(path)) continue;
try
{
var sha = (await ContentHash.Sha256Async(path, null, ct).ConfigureAwait(false)).ToLowerInvariant();
if (!keepHolds.Contains(sha)) hashes.Add(sha);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
return true;
}
}
if (hashes.Count == 0) return false;
var held = await _sides.HeldElsewhereAsync(hashes, [drop], ct).ConfigureAwait(false);
return hashes.Any(h => !held.Contains(h));
}
/// <summary>
/// Queues the job that applies <paramref name="plan"/>: the pair goes to <see cref="CopyState.Integrating"/> (its state
/// before kept as the previous one), the job targets the kept sequence, then the other (both held from other jobs).
@@ -326,7 +359,7 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
return block switch
{
CopyBlock.Busy => Loc.L("Errors.Copies.Busy"),
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile => Loc.L("Errors.Copies." + block, dropTitle),
CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile or CopyBlock.DamagedPhotos => Loc.L("Errors.Copies." + block, dropTitle),
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", keepTitle, Size(plan.CopyBytes + SpaceReserve)),
CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", plan.BothLinkedServer ?? string.Empty),
CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", dropTitle),
+1 -1
View File
@@ -503,7 +503,7 @@ public sealed class CopyEngine(SyncService sync, ArchiveService archives, Integr
if (here is null && there is null) continue;
var local = await Db.Sequences.GetAsync(pair.LocalId, ct).ConfigureAwait(false);
twins.Add(new CopyTwin(pair.Id, pair.LocalId, local is null ? string.Empty : archives.GetValueOrDefault(local.ArchiveId) ?? string.Empty, here, pair.Server!,
pair.RemoteId!.Value, there));
pair.RemoteId!.Value, there, ServerName(pair.Server!)));
}
return twins;
}
+11 -1
View File
@@ -46,6 +46,12 @@ public enum CopyBlock
TrashBlocked,
KeptUnchosen,
ChangedFile,
/// <summary>Photos sent into a server sequence the account neither owns nor may edit (the server refuses that, 403).</summary>
NoAddRight,
/// <summary>The other sequence of a merge holds photos a verify flagged changed or damaged: they would go to the trash unchecked.</summary>
DamagedPhotos,
}
/// <summary>The choices of an Integrate: photo policy, per-photo choices (by photo key), per-detail sides (by path), projects.</summary>
@@ -114,7 +120,11 @@ public sealed record MergePlan(Guid CopyId, Guid KeepId, Guid DropId, MergeChoic
/// </summary>
public sealed record CopyPlanContext(string PcName, string? ServerName, bool CanUpload, bool CanFetch, bool CanEdit, bool CanDelete,
bool OwnsOrAdmin, bool KeepsProjects, long? QuotaLeft, IReadOnlySet<Guid> UnsentWorkspaceSequences,
IReadOnlySet<Guid> ServerOriginalsArchives);
IReadOnlySet<Guid> ServerOriginalsArchives)
{
/// <summary>The signed-in account's id: it owns a server sequence whose owner it is (null: unknown, signed out).</summary>
public Guid? UserId { get; init; }
}
/// <summary>The server-side dry run of moving photos of a pair's server sequence to the server's trash (design §6.2).</summary>
public sealed record TrashTherePlan(Guid CopyId, string Server, Guid RemoteId, IReadOnlyList<Guid> FrameIds, IReadOnlyList<string> Keys, int Photos,
+3 -1
View File
@@ -38,5 +38,7 @@ public sealed record FoundCopyView(FoundCopy Copy, CopyFacts Here, CopyFacts The
/// <summary>
/// The same time-lapse with workspace projects at two homes (a linked or integrated pair): the Edit picker marks each as the
/// other's twin. LocalHome names the local copy's archive; a project name is null when that home has no workspace project.
/// ServerName is the name shown for Server (the key itself when no name is known).
/// </summary>
public sealed record CopyTwin(Guid CopyId, Guid LocalId, string LocalHome, string? LocalProject, string Server, Guid RemoteId, string? ServerProject);
public sealed record CopyTwin(Guid CopyId, Guid LocalId, string LocalHome, string? LocalProject, string Server, Guid RemoteId, string? ServerProject,
string ServerName);
+8 -1
View File
@@ -163,7 +163,8 @@ public sealed class FoundCopyStore(ChronosDatabase db, TimeProvider? time = null
/// <summary>
/// The row of a link (evidence Link, state Linked) when it has none; the link's row otherwise kept (moved to Linked when it
/// was a Candidate). Any other Linked or Integrated row of the same server sequence, or of the same local sequence and
/// server, is demoted to Candidate (a link re-pointed to another copy: sync_links holds one link per side and server).
/// server, is demoted to Candidate (a link re-pointed to another copy: sync_links holds one link per side and server); the
/// local copy's rows with another server sequence that answered 404 are deleted (Upload again).
/// </summary>
public Task<FoundCopy> EnsureLinkedAsync(string server, Guid remoteId, Guid localId, CancellationToken ct)
{
@@ -186,6 +187,12 @@ public sealed class FoundCopyStore(ChronosDatabase db, TimeProvider? time = null
[row.Id, false, now], ct).ConfigureAwait(false);
}
await DemoteAsync(inner, server, remoteId, localId, now, ct).ConfigureAwait(false);
// The rows of the local copy with a server sequence that server answered 404 for (design §6.3, "Upload again
// deletes the gone row"), Candidate and Kept apart included: the local copy is linked to another sequence now, and a
// gone sequence listed again is found anew.
await inner.ExecuteAsync(
$"DELETE FROM found_copies WHERE kind = 0 AND server = $1 AND local_id = $3 AND remote_id <> $2 AND remote_gone_hits >= 1 AND {Effective} <> 3",
[server, remoteId, localId], ct).ConfigureAwait(false);
return (await inner.SingleAsync($"{Select} WHERE id = $1", [row.Id], Map, ct).ConfigureAwait(false))!;
}
@@ -349,8 +349,10 @@ internal sealed class IntegrateJobHandler(SyncService sync, IntegratePlanner pla
}
try
{
var dryRun = await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], null, DryRun: true), _ct).ConfigureAwait(false);
await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], dryRun.FramesVersion, DryRun: false), _ct).ConfigureAwait(false);
// At the frames version of the manifest that showed the winner in place: a server sequence changed since (the
// winner trashed or replaced by another client) refuses the delete, and the loser stays.
await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], manifest.FramesVersion, DryRun: true), _ct).ConfigureAwait(false);
await remote.DeleteFramesAsync(journal.RemoteId, new FrameDeleteRequest([step.FrameId], manifest.FramesVersion, DryRun: false), _ct).ConfigureAwait(false);
journal.TrashedThere.Add(step.Key);
Save();
}
@@ -199,6 +199,10 @@ public sealed class IntegratePlanner(SyncService sync, CopySides sides, ProjectS
// Rights.
if (steps.Any(s => s.Action is PhotoAction.Send or PhotoAction.SendVersion) && !context.CanUpload) blocks.Add(CopyBlock.NoUploadRight);
// Sent into the server sequence: the server allows that to its owner, an admin or an account with Edit only.
var owns = context.OwnsOrAdmin || (context.UserId is { } me && dto.OwnerUserId == me);
if (steps.Any(s => s.Action is PhotoAction.Send or PhotoAction.SendVersion) && context.CanUpload && !owns && !context.CanEdit)
blocks.Add(CopyBlock.NoAddRight);
if (steps.Any(s => s.Action is PhotoAction.Fetch or PhotoAction.FetchVersion) && !context.CanFetch) blocks.Add(CopyBlock.NoFetchRight);
// Nothing left but versions whose loser stays for want of the Delete right: there is nothing to integrate.
if (dropped.Count > 0 && steps.All(s => dropped.Contains(s.Key)) && payload is null && projectSteps.Count == 0) blocks.Add(CopyBlock.NoDeleteRight);
@@ -232,6 +236,7 @@ public sealed class IntegratePlanner(SyncService sync, CopySides sides, ProjectS
CopyBlock.NoUploadRight => Loc.L("Errors.Copies.NoUploadRight"),
CopyBlock.NoFetchRight => Loc.L("Errors.Copies.NoFetchRight"),
CopyBlock.NoEditRight => Loc.L("Errors.Copies.NoEditRight"),
CopyBlock.NoAddRight => Loc.L("Errors.Copies.NoAddRight"),
CopyBlock.NoDeleteRight => Loc.L("Errors.Copies.NoDeleteRight"),
CopyBlock.LinkTaken => Loc.L("Errors.Copies.LinkTaken", title, server),
CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", title, Size(plan.FetchBytes + SpaceReserve)),
+11
View File
@@ -405,6 +405,17 @@ public sealed class SyncService
EnqueueAsync(engine, JobKind.Download, remoteId, title, new SyncJobParameters(server, SyncDownloadMode.Originals, archiveId, Automatic: true),
JobPriority.Background, cancellationToken);
/// <summary>
/// Whether <paramref name="job"/> is an automatic transfer of an integrated pair's new photos
/// (<see cref="EnqueueAutomaticUploadAsync"/>, <see cref="EnqueueAutomaticDownloadAsync"/>): a metered connection pauses
/// those whatever the option says (owner review 6, Q6).
/// </summary>
public static bool IsAutomaticTransfer(Job job)
{
ArgumentNullException.ThrowIfNull(job);
return SyncJobParameters.Read(job)?.IsAutomatic == true;
}
/// <summary>Queues sending the renders of a local copy the server lacks (BRIEF §14.5), unless that is already waiting or running.</summary>
public Task<Job> EnqueueSendExportsAsync(JobEngine engine, string server, Sequence local, CancellationToken cancellationToken = default) =>
EnqueueAsync(engine, JobKind.UploadCommit, local.Id, local.DisplayTitle, new SyncJobParameters(server, Upload: SyncUploadMode.Exports), JobPriority.User,
+42 -5
View File
@@ -98,12 +98,15 @@ internal sealed class SyncTransfers(SyncService sync)
// A server that files a photo it holds in another sequence into this one (owner review 6): the map's "missing on the
// server" reaches 0 once every original is in the target, not merely somewhere on the server.
var into = (await remote.CapabilitiesAsync(ct).ConfigureAwait(false)).Contains(ServerCapabilities.UploadInto);
if (into)
// An account that may upload but neither owns the target nor may edit it is refused that (403): the originals then go
// as before, each to the target unless the server holds it elsewhere (IntoRefusal).
var into = (await remote.CapabilitiesAsync(ct).ConfigureAwait(false)).Contains(ServerCapabilities.UploadInto) ? new IntoRefusal() : null;
if (into is not null)
{
// Counted already (they reached the server before the target existed): filed into it now, nothing stepped again.
foreach (var frame in heldElsewhere)
{
if (into.Refused) break;
if (await UploadFrameAsync(context, remote, target, null, paths.FromRelative(frame.RelativePath), frame, tombstones, hashes, ct, into)
.ConfigureAwait(false) is null)
skipped++;
@@ -978,8 +981,18 @@ internal sealed class SyncTransfers(SyncService sync)
/// original the index has none for goes into <paramref name="hashes"/>; known by content only now, such an original
/// the server deleted (<paramref name="tombstones"/>) is not sent back.
/// </summary>
private static Task<CompleteUploadResponse?> UploadFrameAsync(JobContext context, ISyncRemote remote, Guid? sequenceId, string? sessionKey, string path,
Frame frame, SyncTombstones tombstones, ConcurrentDictionary<Guid, string> hashes, CancellationToken cancellationToken, IntoRefusal? into) =>
UploadFrameAsync(context, remote, sequenceId, sessionKey, path, frame, tombstones, hashes, cancellationToken, into is not null, into);
/// <summary>
/// <paramref name="into"/>: through <see cref="ISyncRemote.UploadFileIntoAsync"/>; with <paramref name="fallback"/>, a
/// 403 for that (an account that neither owns the target nor may edit it) sends this original and every later one of
/// the job the plain way instead (<see cref="IntoRefusal"/>).
/// </summary>
private static async Task<CompleteUploadResponse?> UploadFrameAsync(JobContext context, ISyncRemote remote, Guid? sequenceId, string? sessionKey, string path,
Frame frame, SyncTombstones tombstones, ConcurrentDictionary<Guid, string> hashes, CancellationToken cancellationToken, bool into = false)
Frame frame, SyncTombstones tombstones, ConcurrentDictionary<Guid, string> hashes, CancellationToken cancellationToken, bool into = false,
IntoRefusal? fallback = null)
{
if (!File.Exists(path))
{
@@ -1002,11 +1015,35 @@ internal sealed class SyncTransfers(SyncService sync)
context.Log(Loc.L("Archive.Log.SyncChanged", frame.FileName));
return null;
}
if (into && sequenceId is { } target)
return await remote.UploadFileIntoAsync(path, target, sha, frame.CapturedAt, cancellationToken).ConfigureAwait(false) ?? notSent;
if (into && sequenceId is { } target && fallback is not { Refused: true })
{
try
{
return await remote.UploadFileIntoAsync(path, target, sha, frame.CapturedAt, cancellationToken).ConfigureAwait(false) ?? notSent;
}
catch (ChronosApiException ex) when (fallback is not null && ex.Status == HttpStatusCode.Forbidden
&& string.Equals(ex.Error.Code, "forbidden", StringComparison.Ordinal))
{
if (fallback.Refuse()) context.Log(Loc.L("Archive.Log.SyncIntoRefused"));
}
}
return await remote.UploadFileAsync(path, sequenceId, sessionKey, sha, frame.CapturedAt, cancellationToken).ConfigureAwait(false) ?? notSent;
}
/// <summary>
/// Whether the server refused an upload into the target to this account (owner review 6, #73): set once, by the first
/// refusal; the job's later originals go the plain way, as before the server could file into a target.
/// </summary>
private sealed class IntoRefusal
{
private int _refused;
public bool Refused => Volatile.Read(ref _refused) == 1;
/// <summary>Records the refusal; true for the first one.</summary>
public bool Refuse() => Interlocked.Exchange(ref _refused, 1) == 0;
}
/// <summary>Commits one original from staging into the local sequence (created from the server id when null).</summary>
private async Task<IngestResult> CommitAsync(Guid remoteId, Guid archiveId, Guid? sequenceId, ManifestFrame frame, string staged, string sha,
IReadOnlyDictionary<Guid, DateTime?> captured, CancellationToken cancellationToken)