33using System . Collections . ObjectModel ;
44using System . Diagnostics ;
55using System . Linq ;
6+ using System . Text ;
67using System . Timers ;
7- using System . Windows . Interop ;
8- using System . Windows . Media ;
98using _1RM . Model . Protocol . Base ;
109using _1RM . Service ;
1110using _1RM . Service . DataSource ;
@@ -202,7 +201,7 @@ public Result UpdateServer(ProtocolBase protocolServer)
202201 try
203202 {
204203 Debug . Assert ( protocolServer . IsTmpSession ( ) == false ) ;
205- var source = protocolServer . GetDataSource ( ) ;
204+ var source = protocolServer . DataSource ;
206205 if ( source == null )
207206 {
208207 return Result . Fail ( info , protocolServer . DataSource , $ "`{ protocolServer . DataSource } ` is not initialized yet") ;
@@ -249,7 +248,7 @@ public Result UpdateServer(IEnumerable<ProtocolBase> protocolServers)
249248 var failMsgs = new List < string > ( ) ;
250249 foreach ( var groupedServer in groupedServers )
251250 {
252- var source = groupedServer . First ( ) . GetDataSource ( ) ;
251+ var source = groupedServer . First ( ) . DataSource ;
253252 if ( source ? . IsWritable == true )
254253 {
255254 needReload |= source . NeedRead ( ) ;
@@ -315,11 +314,12 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
315314 var failMsgs = new List < string > ( ) ;
316315 foreach ( var groupedServer in groupedServers )
317316 {
318- var source = groupedServer . First ( ) . GetDataSource ( ) ;
317+ var source = groupedServer . First ( ) . DataSource ;
319318 if ( source ? . IsWritable == true )
320319 {
321320 needReload |= source . NeedRead ( ) ;
322321 var tmp = source . Database_DeleteServer ( groupedServer . Select ( x => x . Id ) ) ;
322+ SimpleLogHelper . Debug ( $ "DeleteServer: { string . Join ( '、' , groupedServer . Select ( x => x . Id ) ) } , needReload = { needReload } , tmp.IsSuccess = { tmp . IsSuccess } ") ;
323323 if ( tmp . IsSuccess )
324324 {
325325 isAnySuccess = true ;
@@ -331,15 +331,19 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
331331 var old = GetItemById ( source . DataSourceName , protocolServer . Id ) ;
332332 if ( old != null )
333333 {
334+ SimpleLogHelper . Debug ( $ "Remote server { old . DisplayName } of `{ old . DataSourceName } ` removed from GlobalData") ;
334335 VmItemList . Remove ( old ) ;
336+ IoC . Get < ServerListPageViewModel > ( ) . DeleteServer ( old ) ; // invoke main list ui change
335337 Execute . OnUIThread ( ( ) =>
336338 {
337- if ( IoC . Get < ServerListPageViewModel > ( ) . VmServerList . Contains ( old ) )
338- IoC . Get < ServerListPageViewModel > ( ) . VmServerList . Remove ( old ) ; // invoke main list ui change
339339 if ( IoC . Get < ServerSelectionsViewModel > ( ) . VmServerList . Contains ( old ) )
340340 IoC . Get < ServerSelectionsViewModel > ( ) . VmServerList . Remove ( old ) ; // invoke launcher ui change
341341 } ) ;
342342 }
343+ else
344+ {
345+ SimpleLogHelper . Warning ( $ "Remote server { protocolServer . DisplayName } of `{ source . DataSourceName } ` removed from GlobalData but not found in VmItemList") ;
346+ }
343347 }
344348 }
345349 }
@@ -355,7 +359,7 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
355359 {
356360 if ( needReload )
357361 {
358- ReloadServerList ( ) ;
362+ ReloadServerList ( needReload ) ;
359363 }
360364 else
361365 {
@@ -406,6 +410,39 @@ public void StartTick()
406410 }
407411 }
408412
413+ /// <summary>
414+ /// return time string like 1d 2h 3m 4s
415+ /// </summary>
416+ /// <param name="seconds"></param>
417+ /// <returns></returns>
418+ private static string GetTime ( int seconds )
419+ {
420+ var sb = new StringBuilder ( ) ;
421+ if ( seconds > 86400 )
422+ {
423+ sb . Append ( $ "{ seconds / 86400 } d ") ;
424+ seconds %= 86400 ;
425+ }
426+
427+ if ( seconds > 3600 )
428+ {
429+ sb . Append ( $ "{ seconds / 3600 } h ") ;
430+ seconds %= 3600 ;
431+ }
432+
433+ if ( seconds > 60 )
434+ {
435+ sb . Append ( $ "{ seconds / 60 } m ") ;
436+ seconds %= 60 ;
437+ }
438+
439+ if ( seconds > 0 )
440+ {
441+ sb . Append ( $ "{ seconds } s ") ;
442+ }
443+ return sb . ToString ( ) ;
444+ }
445+
409446 public DateTime CheckUpdateTime ;
410447 private void TimerOnElapsed ( object ? sender , ElapsedEventArgs e )
411448 {
@@ -427,9 +464,10 @@ private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
427464 || listPageViewModel . VmServerList . Any ( x => x . IsSelected )
428465 || launcherWindowViewModel ? . View ? . IsVisible == true )
429466 {
467+ var pause = IoC . Get < LanguageService > ( ) . Translate ( "Pause" ) ;
430468 foreach ( var s in ds )
431469 {
432- s . ReconnectInfo = "TXT: pause" ;
470+ s . ReconnectInfo = pause ;
433471 }
434472 return ;
435473 }
@@ -455,21 +493,27 @@ private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
455493
456494 var minEtc = Math . Min ( checkUpdateEtc , minReconnectEtc ) ;
457495
496+
497+ var msgUpdating = IoC . Get < LanguageService > ( ) . Translate ( "Updating" ) ;
498+ var msgNextUpdate = IoC . Get < LanguageService > ( ) . Translate ( "Next update check" ) ;
499+ var msgNextReconnect = IoC . Get < LanguageService > ( ) . Translate ( "Next auto reconnect" ) ;
500+ var msgReconnecting = IoC . Get < LanguageService > ( ) . Translate ( "Reconnecting" ) ;
501+
458502 var msg = minEtc > 0
459- ? $ "TXT: check update in { minEtc } s "
460- : "TXT: checking" ;
503+ ? $ "{ msgNextUpdate } { GetTime ( minEtc ) } "
504+ : msgUpdating ;
461505
462506 foreach ( var s in ds )
463507 {
464508 if ( s . Status != EnumDatabaseStatus . OK )
465509 {
466510 if ( ( s . ReconnectTime - DateTime . Now ) . Seconds > 0 )
467511 {
468- s . ReconnectInfo = $ "TXT: reconnect in { ( s . ReconnectTime - DateTime . Now ) . Seconds } s ";
512+ s . ReconnectInfo = $ "{ msgNextReconnect } { GetTime ( ( s . ReconnectTime - DateTime . Now ) . Seconds ) } ";
469513 }
470514 else
471515 {
472- s . ReconnectInfo = $ "TXT: reconnecting" ;
516+ s . ReconnectInfo = msgReconnecting ;
473517 }
474518 }
475519 else
0 commit comments