Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit01e7e6d

Browse files
committed
PR comments
1 parent81f8c02 commit01e7e6d

File tree

4 files changed

+165
-217
lines changed

4 files changed

+165
-217
lines changed

‎App/Models/SyncSessionModel.cs

Lines changed: 60 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
usingSystem;
22
usingSystem.Collections.Generic;
3-
usingSystem.Collections.ObjectModel;
43
usingSystem.Linq;
54
usingCoder.Desktop.App.Converters;
65
usingCoder.Desktop.MutagenSdk.Proto.Synchronization;
@@ -49,163 +48,9 @@ public string Description(string linePrefix = "")
4948
}
5049
}
5150

52-
publicenumSyncSessionModelEntryKind
53-
{
54-
Unknown,
55-
Directory,
56-
File,
57-
SymbolicLink,
58-
Untracked,
59-
Problematic,
60-
PhantomDirectory,
61-
}
62-
63-
publicsealedclassSyncSessionModelEntry
64-
{
65-
publicreadonlySyncSessionModelEntryKindKind;
66-
67-
// For Kind == Directory only.
68-
publicreadonlyReadOnlyDictionary<string,SyncSessionModelEntry>Contents;
69-
70-
// For Kind == File only.
71-
publicreadonlystringDigest="";
72-
publicreadonlyboolExecutable;
73-
74-
// For Kind = SymbolicLink only.
75-
publicreadonlystringTarget="";
76-
77-
// For Kind = Problematic only.
78-
publicreadonlystringProblem="";
79-
80-
publicSyncSessionModelEntry(EntryprotoEntry)
81-
{
82-
Kind=protoEntry.Kindswitch
83-
{
84-
EntryKind.Directory=>SyncSessionModelEntryKind.Directory,
85-
EntryKind.File=>SyncSessionModelEntryKind.File,
86-
EntryKind.SymbolicLink=>SyncSessionModelEntryKind.SymbolicLink,
87-
EntryKind.Untracked=>SyncSessionModelEntryKind.Untracked,
88-
EntryKind.Problematic=>SyncSessionModelEntryKind.Problematic,
89-
EntryKind.PhantomDirectory=>SyncSessionModelEntryKind.PhantomDirectory,
90-
_=>SyncSessionModelEntryKind.Unknown,
91-
};
92-
93-
switch(Kind)
94-
{
95-
caseSyncSessionModelEntryKind.Directory:
96-
{
97-
varcontents=newDictionary<string,SyncSessionModelEntry>();
98-
foreach(var(key,value)inprotoEntry.Contents)
99-
contents[key]=newSyncSessionModelEntry(value);
100-
Contents=newReadOnlyDictionary<string,SyncSessionModelEntry>(contents);
101-
break;
102-
}
103-
caseSyncSessionModelEntryKind.File:
104-
Digest=BitConverter.ToString(protoEntry.Digest.ToByteArray()).Replace("-","").ToLower();
105-
Executable=protoEntry.Executable;
106-
break;
107-
caseSyncSessionModelEntryKind.SymbolicLink:
108-
Target=protoEntry.Target;
109-
break;
110-
caseSyncSessionModelEntryKind.Problematic:
111-
Problem=protoEntry.Problem;
112-
break;
113-
}
114-
}
115-
116-
publicnewstringToString()
117-
{
118-
varstr=Kind.ToString();
119-
switch(Kind)
120-
{
121-
caseSyncSessionModelEntryKind.Directory:
122-
str+=$" ({Contents.Count} entries)";
123-
break;
124-
caseSyncSessionModelEntryKind.File:
125-
str+=$" ({Digest}, executable:{Executable})";
126-
break;
127-
caseSyncSessionModelEntryKind.SymbolicLink:
128-
str+=$" (target:{Target})";
129-
break;
130-
caseSyncSessionModelEntryKind.Problematic:
131-
str+=$" ({Problem})";
132-
break;
133-
}
134-
135-
returnstr;
136-
}
137-
}
138-
139-
publicsealedclassSyncSessionModelConflictChange
140-
{
141-
publicreadonlystringPath;// relative to sync root
142-
143-
// null means non-existent:
144-
publicreadonlySyncSessionModelEntry?Old;
145-
publicreadonlySyncSessionModelEntry?New;
146-
147-
publicSyncSessionModelConflictChange(ChangeprotoChange)
148-
{
149-
Path=protoChange.Path;
150-
Old=protoChange.Old!=null?newSyncSessionModelEntry(protoChange.Old):null;
151-
New=protoChange.New!=null?newSyncSessionModelEntry(protoChange.New):null;
152-
}
153-
154-
publicnewstringToString()
155-
{
156-
conststringnonExistent="<non-existent>";
157-
varoldStr=Old!=null?Old.ToString():nonExistent;
158-
varnewStr=New!=null?New.ToString():nonExistent;
159-
return$"{Path} ({oldStr} ->{newStr})";
160-
}
161-
}
162-
163-
publicsealedclassSyncSessionModelConflict
164-
{
165-
publicreadonlystringRoot;// relative to sync root
166-
publicreadonlyList<SyncSessionModelConflictChange>AlphaChanges;
167-
publicreadonlyList<SyncSessionModelConflictChange>BetaChanges;
168-
169-
publicSyncSessionModelConflict(ConflictprotoConflict)
170-
{
171-
Root=protoConflict.Root;
172-
AlphaChanges=protoConflict.AlphaChanges.Select(change=>newSyncSessionModelConflictChange(change)).ToList();
173-
BetaChanges=protoConflict.BetaChanges.Select(change=>newSyncSessionModelConflictChange(change)).ToList();
174-
}
175-
176-
privatestring?FriendlyProblem()
177-
{
178-
// If the change is <non-existent> -> !<non-existent>.
179-
if(AlphaChanges.Count==1&&BetaChanges.Count==1&&
180-
AlphaChanges[0].Old==null&&
181-
BetaChanges[0].Old==null&&
182-
AlphaChanges[0].New!=null&&
183-
BetaChanges[0].New!=null)
184-
return
185-
"An entry was created on both endpoints and they do not match. You can resolve this conflict by deleting one of the entries on either side.";
186-
187-
returnnull;
188-
}
189-
190-
publicstringDescription()
191-
{
192-
// This formatting is very similar to Mutagen.
193-
varstr=$"Conflict at path '{Root}':";
194-
foreach(varchangeinAlphaChanges)
195-
str+=$"\n (alpha){change.ToString()}";
196-
foreach(varchangeinAlphaChanges)
197-
str+=$"\n (beta){change.ToString()}";
198-
if(FriendlyProblem()is{}friendlyProblem)
199-
str+=$"\n\n{friendlyProblem}";
200-
201-
returnstr;
202-
}
203-
}
204-
20551
publicclassSyncSessionModel
20652
{
20753
publicreadonlystringIdentifier;
208-
publicreadonlystringName;
20954

21055
publicreadonlystringAlphaName;
21156
publicreadonlystringAlphaPath;
@@ -219,8 +64,8 @@ public class SyncSessionModel
21964
publicreadonlySyncSessionModelEndpointSizeAlphaSize;
22065
publicreadonlySyncSessionModelEndpointSizeBetaSize;
22166

222-
publicreadonlyIReadOnlyList<SyncSessionModelConflict>Conflicts;
223-
publiculongOmittedConflicts;
67+
publicreadonlyIReadOnlyList<string>Conflicts;// Conflict descriptions
68+
publicreadonlyulongOmittedConflicts;
22469
publicreadonlyIReadOnlyList<string>Errors;
22570

22671
// If Paused is true, the session can be resumed. If false, the session can
@@ -231,10 +76,12 @@ public string StatusDetails
23176
{
23277
get
23378
{
234-
varstr=$"{StatusString} ({StatusCategory})\n\n{StatusDescription}";
235-
foreach(varerrinErrors)str+=$"\n\nError:{err}";
236-
foreach(varconflictinConflicts)str+=$"\n\n{conflict.Description()}";
237-
if(OmittedConflicts>0)str+=$"\n\n{OmittedConflicts:N0} conflicts omitted";
79+
varstr=StatusString;
80+
if(StatusCategory.ToString()!=StatusString)str+=$" ({StatusCategory})";
81+
str+=$"\n\n{StatusDescription}";
82+
foreach(varerrinErrors)str+=$"\n\n-----\n\n{err}";
83+
foreach(varconflictinConflicts)str+=$"\n\n-----\n\n{conflict}";
84+
if(OmittedConflicts>0)str+=$"\n\n-----\n\n{OmittedConflicts:N0} conflicts omitted";
23885
returnstr;
23986
}
24087
}
@@ -252,7 +99,6 @@ public string SizeDetails
25299
publicSyncSessionModel(Statestate)
253100
{
254101
Identifier=state.Session.Identifier;
255-
Name=state.Session.Name;
256102

257103
(AlphaName,AlphaPath)=NameAndPathFromUrl(state.Session.Alpha);
258104
(BetaName,BetaPath)=NameAndPathFromUrl(state.Session.Beta);
@@ -354,7 +200,7 @@ public SyncSessionModel(State state)
354200
StatusDescription="The session has conflicts that need to be resolved.";
355201
}
356202

357-
Conflicts=state.Conflicts.Select(c=>newSyncSessionModelConflict(c)).ToList();
203+
Conflicts=state.Conflicts.Select(ConflictToString).ToList();
358204
OmittedConflicts=state.ExcludedConflicts;
359205

360206
AlphaSize=newSyncSessionModelEndpointSize
@@ -403,4 +249,55 @@ private static (string, string) NameAndPathFromUrl(URL url)
403249

404250
return(name,path);
405251
}
252+
253+
privatestaticstringConflictToString(Conflictconflict)
254+
{
255+
string?friendlyProblem=null;
256+
if(conflict.AlphaChanges.Count==1&&conflict.BetaChanges.Count==1&&
257+
conflict.AlphaChanges[0].Old==null&&
258+
conflict.BetaChanges[0].Old==null&&
259+
conflict.AlphaChanges[0].New!=null&&
260+
conflict.BetaChanges[0].New!=null)
261+
friendlyProblem=
262+
"An entry was created on both endpoints and they do not match. You can resolve this conflict by deleting one of the entries on either side.";
263+
264+
varstr=$"Conflict at path '{conflict.Root}':";
265+
foreach(varchangeinconflict.AlphaChanges)
266+
str+=$"\n (alpha){ChangeToString(change)}";
267+
foreach(varchangeinconflict.BetaChanges)
268+
str+=$"\n (beta){ChangeToString(change)}";
269+
if(friendlyProblem!=null)
270+
str+=$"\n\n{friendlyProblem}";
271+
272+
returnstr;
273+
}
274+
275+
privatestaticstringChangeToString(Changechange)
276+
{
277+
return$"{change.Path} ({EntryToString(change.Old)} ->{EntryToString(change.New)})";
278+
}
279+
280+
privatestaticstringEntryToString(Entry?entry)
281+
{
282+
if(entry==null)return"<non-existent>";
283+
varstr=entry.Kind.ToString();
284+
switch(entry.Kind)
285+
{
286+
caseEntryKind.Directory:
287+
str+=$" ({entry.Contents.Count} entries)";
288+
break;
289+
caseEntryKind.File:
290+
vardigest=BitConverter.ToString(entry.Digest.ToByteArray()).Replace("-","").ToLower();
291+
str+=$" ({digest}, executable:{entry.Executable})";
292+
break;
293+
caseEntryKind.SymbolicLink:
294+
str+=$" (target:{entry.Target})";
295+
break;
296+
caseEntryKind.Problematic:
297+
str+=$" ({entry.Problem})";
298+
break;
299+
}
300+
301+
returnstr;
302+
}
406303
}

‎App/Services/MutagenController.cs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,55 @@
1818
usingGrpc.Core;
1919
usingMicrosoft.Extensions.Options;
2020
usingDaemonTerminateRequest=Coder.Desktop.MutagenSdk.Proto.Service.Daemon.TerminateRequest;
21+
usingMutagenProtocol=Coder.Desktop.MutagenSdk.Proto.Url.Protocol;
2122
usingSynchronizationTerminateRequest=Coder.Desktop.MutagenSdk.Proto.Service.Synchronization.TerminateRequest;
2223

2324
namespaceCoder.Desktop.App.Services;
2425

25-
publicclassCreateSyncSessionRequest
26+
publicenumCreateSyncSessionRequestEndpointProtocol
2627
{
27-
publicUriAlpha{get;init;}
28-
publicUriBeta{get;init;}
28+
Local,
29+
Ssh,
30+
}
2931

30-
publicURLAlphaMutagenUrl=>MutagenUrl(Alpha);
31-
publicURLBetaMutagenUrl=>MutagenUrl(Beta);
32+
publicclassCreateSyncSessionRequestEndpoint
33+
{
34+
publicrequiredCreateSyncSessionRequestEndpointProtocolProtocol{get;init;}
35+
publicstringUser{get;init;}="";
36+
publicstringHost{get;init;}="";
37+
publicuintPort{get;init;}=0;
38+
publicstringPath{get;init;}="";
3239

33-
privatestaticURLMutagenUrl(Uriuri)
40+
publicURLMutagenUrl
3441
{
35-
varprotocol=uri.Schemeswitch
36-
{
37-
"file"=>Protocol.Local,
38-
"ssh"=>Protocol.Ssh,
39-
_=>thrownewArgumentException("Only 'file' and 'ssh' URLs are supported",nameof(uri)),
40-
};
41-
42-
returnnewURL
43-
{
44-
Kind=Kind.Synchronization,
45-
Protocol=protocol,
46-
User=uri.UserInfo,
47-
Host=uri.Host,
48-
Port=uri.Port<0?0:(uint)uri.Port,
49-
Path=protocolisProtocol.Local?uri.LocalPath:uri.AbsolutePath,
50-
};
42+
get
43+
{
44+
varprotocol=Protocolswitch
45+
{
46+
CreateSyncSessionRequestEndpointProtocol.Local=>MutagenProtocol.Local,
47+
CreateSyncSessionRequestEndpointProtocol.Ssh=>MutagenProtocol.Ssh,
48+
_=>thrownewArgumentException($"Invalid protocol '{Protocol}'",nameof(Protocol)),
49+
};
50+
51+
returnnewURL
52+
{
53+
Kind=Kind.Synchronization,
54+
Protocol=protocol,
55+
User=User,
56+
Host=Host,
57+
Port=Port,
58+
Path=Path,
59+
};
60+
}
5161
}
5262
}
5363

64+
publicclassCreateSyncSessionRequest
65+
{
66+
publicrequiredCreateSyncSessionRequestEndpointAlpha{get;init;}
67+
publicrequiredCreateSyncSessionRequestEndpointBeta{get;init;}
68+
}
69+
5470
publicinterfaceISyncSessionController:IAsyncDisposable
5571
{
5672
Task<IEnumerable<SyncSessionModel>>ListSyncSessions(CancellationTokenct=default);
@@ -152,8 +168,8 @@ public async Task<SyncSessionModel> CreateSyncSession(CreateSyncSessionRequest r
152168
Prompter=prompter.Identifier,
153169
Specification=newCreationSpecification
154170
{
155-
Alpha=req.AlphaMutagenUrl,
156-
Beta=req.BetaMutagenUrl,
171+
Alpha=req.Alpha.MutagenUrl,
172+
Beta=req.Beta.MutagenUrl,
157173
// TODO: probably should set these at some point
158174
Configuration=newConfiguration(),
159175
ConfigurationAlpha=newConfiguration(),
@@ -637,7 +653,6 @@ await _dup.RequestStream.WriteAsync(new HostRequest
637653
catch
638654
{
639655
await_dup.RequestStream.CompleteAsync();
640-
_dup.Dispose();
641656
// TODO: log?
642657
}
643658
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp