@@ -12,7 +12,15 @@ public enum SyncSessionStatusCategory
12
12
{
13
13
Unknown ,
14
14
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 ,
15
20
Error ,
21
+
22
+ // If there are any conflicts, the state will be set to Conflicts,
23
+ // overriding Working and Ok.
16
24
Conflicts ,
17
25
Working ,
18
26
Ok ,
@@ -42,16 +50,17 @@ public class SyncSessionModel
42
50
public readonly string Identifier ;
43
51
public readonly string Name ;
44
52
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 ;
48
57
49
58
public readonly SyncSessionStatusCategory StatusCategory ;
50
59
public readonly string StatusString ;
51
60
public readonly string StatusDescription ;
52
61
53
- public readonly SyncSessionModelEndpointSize LocalSize ;
54
- public readonly SyncSessionModelEndpointSize RemoteSize ;
62
+ public readonly SyncSessionModelEndpointSize AlphaSize ;
63
+ public readonly SyncSessionModelEndpointSize BetaSize ;
55
64
56
65
public readonly string [ ] Errors = [ ] ;
57
66
@@ -69,33 +78,34 @@ public string SizeDetails
69
78
{
70
79
get
71
80
{
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 ( " " ) ;
74
83
return str ;
75
84
}
76
85
}
77
86
78
87
// 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 ,
80
89
SyncSessionStatusCategory statusCategory ,
81
90
string statusString , string statusDescription , string [ ] errors )
82
91
{
83
92
Identifier = "TODO" ;
84
93
Name = "TODO" ;
85
94
86
- LocalPath = localPath ;
87
- RemoteName = remoteName ;
88
- RemotePath = remotePath ;
95
+ AlphaName = "Local" ;
96
+ AlphaPath = alphaPath ;
97
+ BetaName = betaName ;
98
+ BetaPath = betaPath ;
89
99
StatusCategory = statusCategory ;
90
100
StatusString = statusString ;
91
101
StatusDescription = statusDescription ;
92
- LocalSize = new SyncSessionModelEndpointSize
102
+ AlphaSize = new SyncSessionModelEndpointSize
93
103
{
94
104
SizeBytes = ( ulong ) new Random ( ) . Next ( 0 , 1000000000 ) ,
95
105
FileCount = ( ulong ) new Random ( ) . Next ( 0 , 10000 ) ,
96
106
DirCount = ( ulong ) new Random ( ) . Next ( 0 , 10000 ) ,
97
107
} ;
98
- RemoteSize = new SyncSessionModelEndpointSize
108
+ BetaSize = new SyncSessionModelEndpointSize
99
109
{
100
110
SizeBytes = ( ulong ) new Random ( ) . Next ( 0 , 1000000000 ) ,
101
111
FileCount = ( ulong ) new Random ( ) . Next ( 0 , 10000 ) ,
@@ -110,131 +120,114 @@ public SyncSessionModel(State state)
110
120
Identifier = state . Session . Identifier ;
111
121
Name = state . Session . Name ;
112
122
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 )
118
127
{
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 ;
129
205
}
130
206
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 )
132
209
{
133
- // Disregard any status if it's paused.
134
210
StatusCategory = SyncSessionStatusCategory . Paused ;
135
211
StatusString = "Paused" ;
136
212
StatusDescription = "The session is paused." ;
137
213
}
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
- }
221
214
222
- // If there are any conflicts, set the status to Conflicts .
215
+ // If there are any conflicts, override Working and Ok .
223
216
if ( state . Conflicts . Count > 0 && StatusCategory > SyncSessionStatusCategory . Conflicts )
224
217
{
225
218
StatusCategory = SyncSessionStatusCategory . Conflicts ;
226
219
StatusString = "Conflicts" ;
227
220
StatusDescription = "The session has conflicts that need to be resolved." ;
228
221
}
229
222
230
- LocalSize = new SyncSessionModelEndpointSize
223
+ AlphaSize = new SyncSessionModelEndpointSize
231
224
{
232
225
SizeBytes = state . AlphaState . TotalFileSize ,
233
226
FileCount = state . AlphaState . Files ,
234
227
DirCount = state . AlphaState . Directories ,
235
228
SymlinkCount = state . AlphaState . SymbolicLinks ,
236
229
} ;
237
- RemoteSize = new SyncSessionModelEndpointSize
230
+ BetaSize = new SyncSessionModelEndpointSize
238
231
{
239
232
SizeBytes = state . BetaState . TotalFileSize ,
240
233
FileCount = state . BetaState . Files ,
@@ -246,4 +239,16 @@ public SyncSessionModel(State state)
246
239
// come from
247
240
if ( ! string . IsNullOrWhiteSpace ( state . LastError ) ) Errors = [ state . LastError ] ;
248
241
}
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
+ }
249
254
}
0 commit comments