Skip to content

Commit 4c37cab

Browse files
committed
Comments
1 parent 171c9e5 commit 4c37cab

File tree

4 files changed

+140
-128
lines changed

4 files changed

+140
-128
lines changed

App/Models/SyncSessionModel.cs

+121-116
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ public enum SyncSessionStatusCategory
1212
{
1313
Unknown,
1414
Paused,
15+
16+
// Halted is a combination of Error and Paused. If the session
17+
// automatically pauses due to a safety check, we want to show it as an
18+
// error, but also show that it can be resumed.
19+
Halted,
1520
Error,
21+
22+
// If there are any conflicts, the state will be set to Conflicts,
23+
// overriding Working and Ok.
1624
Conflicts,
1725
Working,
1826
Ok,
@@ -42,16 +50,17 @@ public class SyncSessionModel
4250
public readonly string Identifier;
4351
public readonly string Name;
4452

45-
public readonly string LocalPath = "Unknown";
46-
public readonly string RemoteName = "Unknown";
47-
public readonly string RemotePath = "Unknown";
53+
public readonly string AlphaName;
54+
public readonly string AlphaPath;
55+
public readonly string BetaName;
56+
public readonly string BetaPath;
4857

4958
public readonly SyncSessionStatusCategory StatusCategory;
5059
public readonly string StatusString;
5160
public readonly string StatusDescription;
5261

53-
public readonly SyncSessionModelEndpointSize LocalSize;
54-
public readonly SyncSessionModelEndpointSize RemoteSize;
62+
public readonly SyncSessionModelEndpointSize AlphaSize;
63+
public readonly SyncSessionModelEndpointSize BetaSize;
5564

5665
public readonly string[] Errors = [];
5766

@@ -69,33 +78,34 @@ public string SizeDetails
6978
{
7079
get
7180
{
72-
var str = "Local:\n" + LocalSize.Description(" ") + "\n\n" +
73-
"Remote:\n" + RemoteSize.Description(" ");
81+
var str = "Alpha:\n" + AlphaSize.Description(" ") + "\n\n" +
82+
"Remote:\n" + BetaSize.Description(" ");
7483
return str;
7584
}
7685
}
7786

7887
// TODO: remove once we process sessions from the mutagen RPC
79-
public SyncSessionModel(string localPath, string remoteName, string remotePath,
88+
public SyncSessionModel(string alphaPath, string betaName, string betaPath,
8089
SyncSessionStatusCategory statusCategory,
8190
string statusString, string statusDescription, string[] errors)
8291
{
8392
Identifier = "TODO";
8493
Name = "TODO";
8594

86-
LocalPath = localPath;
87-
RemoteName = remoteName;
88-
RemotePath = remotePath;
95+
AlphaName = "Local";
96+
AlphaPath = alphaPath;
97+
BetaName = betaName;
98+
BetaPath = betaPath;
8999
StatusCategory = statusCategory;
90100
StatusString = statusString;
91101
StatusDescription = statusDescription;
92-
LocalSize = new SyncSessionModelEndpointSize
102+
AlphaSize = new SyncSessionModelEndpointSize
93103
{
94104
SizeBytes = (ulong)new Random().Next(0, 1000000000),
95105
FileCount = (ulong)new Random().Next(0, 10000),
96106
DirCount = (ulong)new Random().Next(0, 10000),
97107
};
98-
RemoteSize = new SyncSessionModelEndpointSize
108+
BetaSize = new SyncSessionModelEndpointSize
99109
{
100110
SizeBytes = (ulong)new Random().Next(0, 1000000000),
101111
FileCount = (ulong)new Random().Next(0, 10000),
@@ -110,131 +120,114 @@ public SyncSessionModel(State state)
110120
Identifier = state.Session.Identifier;
111121
Name = state.Session.Name;
112122

113-
// If the protocol isn't what we expect for alpha or beta, show
114-
// "unknown".
115-
if (state.Session.Alpha.Protocol == Protocol.Local && !string.IsNullOrWhiteSpace(state.Session.Alpha.Path))
116-
LocalPath = state.Session.Alpha.Path;
117-
if (state.Session.Beta.Protocol == Protocol.Ssh)
123+
(AlphaName, AlphaPath) = NameAndPathFromUrl(state.Session.Alpha);
124+
(BetaName, BetaPath) = NameAndPathFromUrl(state.Session.Beta);
125+
126+
switch (state.Status)
118127
{
119-
if (string.IsNullOrWhiteSpace(state.Session.Beta.Host))
120-
{
121-
var name = state.Session.Beta.Host;
122-
// TODO: this will need to be compatible with custom hostname
123-
// suffixes
124-
if (name.EndsWith(".coder")) name = name[..^6];
125-
RemoteName = name;
126-
}
127-
128-
if (string.IsNullOrWhiteSpace(state.Session.Beta.Path)) RemotePath = state.Session.Beta.Path;
128+
case Status.Disconnected:
129+
StatusCategory = SyncSessionStatusCategory.Error;
130+
StatusString = "Disconnected";
131+
StatusDescription =
132+
"The session is unpaused but not currently connected or connecting to either endpoint.";
133+
break;
134+
case Status.HaltedOnRootEmptied:
135+
StatusCategory = SyncSessionStatusCategory.Halted;
136+
StatusString = "Halted on root emptied";
137+
StatusDescription = "The session is halted due to the root emptying safety check.";
138+
break;
139+
case Status.HaltedOnRootDeletion:
140+
StatusCategory = SyncSessionStatusCategory.Halted;
141+
StatusString = "Halted on root deletion";
142+
StatusDescription = "The session is halted due to the root deletion safety check.";
143+
break;
144+
case Status.HaltedOnRootTypeChange:
145+
StatusCategory = SyncSessionStatusCategory.Halted;
146+
StatusString = "Halted on root type change";
147+
StatusDescription = "The session is halted due to the root type change safety check.";
148+
break;
149+
case Status.ConnectingAlpha:
150+
StatusCategory = SyncSessionStatusCategory.Working;
151+
StatusString = "Connecting (alpha)";
152+
StatusDescription = "The session is attempting to connect to the alpha endpoint.";
153+
break;
154+
case Status.ConnectingBeta:
155+
StatusCategory = SyncSessionStatusCategory.Working;
156+
StatusString = "Connecting (beta)";
157+
StatusDescription = "The session is attempting to connect to the beta endpoint.";
158+
break;
159+
case Status.Watching:
160+
StatusCategory = SyncSessionStatusCategory.Ok;
161+
StatusString = "Watching";
162+
StatusDescription = "The session is watching for filesystem changes.";
163+
break;
164+
case Status.Scanning:
165+
StatusCategory = SyncSessionStatusCategory.Working;
166+
StatusString = "Scanning";
167+
StatusDescription = "The session is scanning the filesystem on each endpoint.";
168+
break;
169+
case Status.WaitingForRescan:
170+
StatusCategory = SyncSessionStatusCategory.Working;
171+
StatusString = "Waiting for rescan";
172+
StatusDescription =
173+
"The session is waiting to retry scanning after an error during the previous scanning operation.";
174+
break;
175+
case Status.Reconciling:
176+
StatusCategory = SyncSessionStatusCategory.Working;
177+
StatusString = "Reconciling";
178+
StatusDescription = "The session is performing reconciliation.";
179+
break;
180+
case Status.StagingAlpha:
181+
StatusCategory = SyncSessionStatusCategory.Working;
182+
StatusString = "Staging (alpha)";
183+
StatusDescription = "The session is staging files on alpha.";
184+
break;
185+
case Status.StagingBeta:
186+
StatusCategory = SyncSessionStatusCategory.Working;
187+
StatusString = "Staging (beta)";
188+
StatusDescription = "The session is staging files on beta.";
189+
break;
190+
case Status.Transitioning:
191+
StatusCategory = SyncSessionStatusCategory.Working;
192+
StatusString = "Transitioning";
193+
StatusDescription = "The session is performing transition operations on each endpoint.";
194+
break;
195+
case Status.Saving:
196+
StatusCategory = SyncSessionStatusCategory.Working;
197+
StatusString = "Saving";
198+
StatusDescription = "The session is recording synchronization history to disk.";
199+
break;
200+
default:
201+
StatusCategory = SyncSessionStatusCategory.Unknown;
202+
StatusString = state.Status.ToString();
203+
StatusDescription = "Unknown status message.";
204+
break;
129205
}
130206

131-
if (state.Session.Paused)
207+
// If the session is paused, override all other statuses except Halted.
208+
if (state.Session.Paused && StatusCategory is not SyncSessionStatusCategory.Halted)
132209
{
133-
// Disregard any status if it's paused.
134210
StatusCategory = SyncSessionStatusCategory.Paused;
135211
StatusString = "Paused";
136212
StatusDescription = "The session is paused.";
137213
}
138-
else
139-
{
140-
switch (state.Status)
141-
{
142-
case Status.Disconnected:
143-
StatusCategory = SyncSessionStatusCategory.Error;
144-
StatusString = "Disconnected";
145-
StatusDescription =
146-
"The session is unpaused but not currently connected or connecting to either endpoint.";
147-
break;
148-
case Status.HaltedOnRootEmptied:
149-
StatusCategory = SyncSessionStatusCategory.Error;
150-
StatusString = "Halted on root emptied";
151-
StatusDescription = "The session is halted due to the root emptying safety check.";
152-
break;
153-
case Status.HaltedOnRootDeletion:
154-
StatusCategory = SyncSessionStatusCategory.Error;
155-
StatusString = "Halted on root deletion";
156-
StatusDescription = "The session is halted due to the root deletion safety check.";
157-
break;
158-
case Status.HaltedOnRootTypeChange:
159-
StatusCategory = SyncSessionStatusCategory.Error;
160-
StatusString = "Halted on root type change";
161-
StatusDescription = "The session is halted due to the root type change safety check.";
162-
break;
163-
case Status.ConnectingAlpha:
164-
StatusCategory = SyncSessionStatusCategory.Working;
165-
StatusString = "Connecting (alpha)";
166-
StatusDescription = "The session is attempting to connect to the alpha endpoint.";
167-
break;
168-
case Status.ConnectingBeta:
169-
StatusCategory = SyncSessionStatusCategory.Working;
170-
StatusString = "Connecting (beta)";
171-
StatusDescription = "The session is attempting to connect to the beta endpoint.";
172-
break;
173-
case Status.Watching:
174-
StatusCategory = SyncSessionStatusCategory.Ok;
175-
StatusString = "Watching";
176-
StatusDescription = "The session is watching for filesystem changes.";
177-
break;
178-
case Status.Scanning:
179-
StatusCategory = SyncSessionStatusCategory.Working;
180-
StatusString = "Scanning";
181-
StatusDescription = "The session is scanning the filesystem on each endpoint.";
182-
break;
183-
case Status.WaitingForRescan:
184-
StatusCategory = SyncSessionStatusCategory.Working;
185-
StatusString = "Waiting for rescan";
186-
StatusDescription =
187-
"The session is waiting to retry scanning after an error during the previous scanning operation.";
188-
break;
189-
case Status.Reconciling:
190-
StatusCategory = SyncSessionStatusCategory.Working;
191-
StatusString = "Reconciling";
192-
StatusDescription = "The session is performing reconciliation.";
193-
break;
194-
case Status.StagingAlpha:
195-
StatusCategory = SyncSessionStatusCategory.Working;
196-
StatusString = "Staging (alpha)";
197-
StatusDescription = "The session is staging files on alpha.";
198-
break;
199-
case Status.StagingBeta:
200-
StatusCategory = SyncSessionStatusCategory.Working;
201-
StatusString = "Staging (beta)";
202-
StatusDescription = "The session is staging files on beta.";
203-
break;
204-
case Status.Transitioning:
205-
StatusCategory = SyncSessionStatusCategory.Working;
206-
StatusString = "Transitioning";
207-
StatusDescription = "The session is performing transition operations on each endpoint.";
208-
break;
209-
case Status.Saving:
210-
StatusCategory = SyncSessionStatusCategory.Working;
211-
StatusString = "Saving";
212-
StatusDescription = "The session is recording synchronization history to disk.";
213-
break;
214-
default:
215-
StatusCategory = SyncSessionStatusCategory.Unknown;
216-
StatusString = state.Status.ToString();
217-
StatusDescription = "Unknown status message.";
218-
break;
219-
}
220-
}
221214

222-
// If there are any conflicts, set the status to Conflicts.
215+
// If there are any conflicts, override Working and Ok.
223216
if (state.Conflicts.Count > 0 && StatusCategory > SyncSessionStatusCategory.Conflicts)
224217
{
225218
StatusCategory = SyncSessionStatusCategory.Conflicts;
226219
StatusString = "Conflicts";
227220
StatusDescription = "The session has conflicts that need to be resolved.";
228221
}
229222

230-
LocalSize = new SyncSessionModelEndpointSize
223+
AlphaSize = new SyncSessionModelEndpointSize
231224
{
232225
SizeBytes = state.AlphaState.TotalFileSize,
233226
FileCount = state.AlphaState.Files,
234227
DirCount = state.AlphaState.Directories,
235228
SymlinkCount = state.AlphaState.SymbolicLinks,
236229
};
237-
RemoteSize = new SyncSessionModelEndpointSize
230+
BetaSize = new SyncSessionModelEndpointSize
238231
{
239232
SizeBytes = state.BetaState.TotalFileSize,
240233
FileCount = state.BetaState.Files,
@@ -246,4 +239,16 @@ public SyncSessionModel(State state)
246239
// come from
247240
if (!string.IsNullOrWhiteSpace(state.LastError)) Errors = [state.LastError];
248241
}
242+
243+
private static (string, string) NameAndPathFromUrl(URL url)
244+
{
245+
var name = "Local";
246+
var path = !string.IsNullOrWhiteSpace(url.Path) ? url.Path : "Unknown";
247+
248+
if (url.Protocol is not Protocol.Local)
249+
name = !string.IsNullOrWhiteSpace(url.Host) ? url.Host : "Unknown";
250+
if (string.IsNullOrWhiteSpace(url.Host)) name = url.Host;
251+
252+
return (name, path);
253+
}
249254
}

App/Services/MutagenController.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ public async Task<SyncSessionModel> CreateSyncSession(CreateSyncSessionRequest r
122122
_sessionCount += 1;
123123
}
124124

125-
throw new NotImplementedException();
125+
// TODO: implement this
126+
return new SyncSessionModel(@"C:\path", "remote", "~/path", SyncSessionStatusCategory.Ok, "Watching",
127+
"Description", []);
126128
}
127129

128130
public async Task<IEnumerable<SyncSessionModel>> ListSyncSessions(CancellationToken ct)
@@ -138,7 +140,8 @@ public async Task<IEnumerable<SyncSessionModel>> ListSyncSessions(CancellationTo
138140
return [];
139141
}
140142

141-
throw new NotImplementedException();
143+
// TODO: implement this
144+
return [];
142145
}
143146

144147
public async Task Initialize(CancellationToken ct)

App/ViewModels/FileSyncListViewModel.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@ public partial class FileSyncListViewModel : ObservableObject
2727
[NotifyPropertyChangedFor(nameof(ShowLoading))]
2828
[NotifyPropertyChangedFor(nameof(ShowError))]
2929
[NotifyPropertyChangedFor(nameof(ShowSessions))]
30-
public partial bool Loading { get; set; } = true;
30+
public partial string? UnavailableMessage { get; set; } = null;
3131

3232
[ObservableProperty]
33-
[NotifyPropertyChangedFor(nameof(ShowUnavailable))]
3433
[NotifyPropertyChangedFor(nameof(ShowLoading))]
35-
[NotifyPropertyChangedFor(nameof(ShowError))]
3634
[NotifyPropertyChangedFor(nameof(ShowSessions))]
37-
public partial string? UnavailableMessage { get; set; } = null;
35+
public partial bool Loading { get; set; } = true;
3836

3937
[ObservableProperty]
40-
[NotifyPropertyChangedFor(nameof(ShowUnavailable))]
4138
[NotifyPropertyChangedFor(nameof(ShowLoading))]
4239
[NotifyPropertyChangedFor(nameof(ShowError))]
4340
[NotifyPropertyChangedFor(nameof(ShowSessions))]
@@ -98,8 +95,10 @@ public FileSyncListViewModel(ISyncSessionController syncSessionController, IRpcC
9895
"Some description", []),
9996
new SyncSessionModel(@"C:\Users\dean\git\coder", "pog", "~/coder", SyncSessionStatusCategory.Conflicts,
10097
"Conflicts", "Some description", []),
101-
new SyncSessionModel(@"C:\Users\dean\git\coder", "pog", "~/coder", SyncSessionStatusCategory.Error,
98+
new SyncSessionModel(@"C:\Users\dean\git\coder", "pog", "~/coder", SyncSessionStatusCategory.Halted,
10299
"Halted on root emptied", "Some description", []),
100+
new SyncSessionModel(@"C:\Users\dean\git\coder", "pog", "~/coder", SyncSessionStatusCategory.Error,
101+
"Some error", "Some description", []),
103102
new SyncSessionModel(@"C:\Users\dean\git\coder", "pog", "~/coder", SyncSessionStatusCategory.Unknown,
104103
"Unknown", "Some description", []),
105104
new SyncSessionModel(@"C:\Users\dean\git\coder", "pog", "~/coder", SyncSessionStatusCategory.Working,
@@ -110,6 +109,8 @@ public FileSyncListViewModel(ISyncSessionController syncSessionController, IRpcC
110109
public void Initialize(DispatcherQueue dispatcherQueue)
111110
{
112111
_dispatcherQueue = dispatcherQueue;
112+
if (!_dispatcherQueue.HasThreadAccess)
113+
throw new InvalidOperationException("Initialize must be called from the UI thread");
113114

114115
_rpcController.StateChanged += RpcControllerStateChanged;
115116
_credentialManager.CredentialsChanged += CredentialManagerCredentialsChanged;

0 commit comments

Comments
 (0)