Skip to content

Commit 4a64eaa

Browse files
committed
feat: remove disconnected alert and add auto reconnect for #395
1 parent b1579c5 commit 4a64eaa

40 files changed

+244
-416
lines changed

Ui/AppInit.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.Globalization;
54
using System.IO;
65
using System.Linq;
76
using System.Threading.Tasks;
8-
using System.Windows;
97
using _1RM.Model;
10-
using _1RM.Model.DAO;
118
using _1RM.Service;
129
using _1RM.View;
1310
using _1RM.View.Guidance;
@@ -17,6 +14,8 @@
1714
using _1RM.Utils;
1815
using _1RM.Utils.KiTTY.Model;
1916
using _1RM.Utils.PRemoteM;
17+
using _1RM.Service.DataSource.DAO;
18+
using _1RM.View.Utils;
2019

2120
namespace _1RM
2221
{
@@ -75,7 +74,7 @@ public void InitOnStart()
7574

7675
LanguageService = new LanguageService(App.ResourceDictionary!);
7776
LanguageService.SetLanguage(CultureInfo.CurrentCulture.Name.ToLower());
78-
#region Portable mode or not
77+
#region Portable or not
7978
{
8079
var portablePaths = new AppPathHelper(Environment.CurrentDirectory);
8180
var appDataPaths = new AppPathHelper(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Assert.APP_NAME));
@@ -285,14 +284,6 @@ public void InitOnConfigure()
285284
_localDataConnectionStatus = dataSourceService.InitLocalDataSource(sqliteConfig);
286285
}
287286

288-
// read from primary database
289-
IoC.Get<GlobalData>().ReloadServerList(true);
290-
// read from AdditionalDataSource async
291-
Task.Factory.StartNew(() =>
292-
{
293-
Task.WaitAll(ConfigurationService!.AdditionalDataSource.Select(config => Task.Factory.StartNew(() => { dataSourceService.AddOrUpdateDataSource(config, doReload: false); })).ToArray());
294-
IoC.Get<GlobalData>().ReloadServerList();
295-
});
296287
// init session controller
297288
IoC.Get<SessionControlService>();
298289
}
@@ -327,10 +318,6 @@ public void InitOnLaunch()
327318
return;
328319
}
329320

330-
//#if DEBUG
331-
// MessageBoxHelper.ErrorAlert(LanguageService?.Translate(@"write permissions alert", "123") ?? "write permissions error:" + "123123");
332-
//#endif
333-
334321
if (IoC.Get<ConfigurationService>().General.AppStartMinimized == false || _isNewUser)
335322
{
336323
IoC.Get<MainWindowViewModel>().OnMainWindowViewLoaded += () =>
@@ -344,6 +331,25 @@ public void InitOnLaunch()
344331
};
345332
IoC.Get<MainWindowViewModel>().ShowMe();
346333
}
334+
335+
336+
337+
338+
MaskLayerController.ShowProcessingRing();
339+
Task.Factory.StartNew(() =>
340+
{
341+
//// read from primary database
342+
//IoC.Get<GlobalData>().ReloadServerList(true);
343+
// read from AdditionalDataSource async
344+
if (ConfigurationService!.AdditionalDataSource.Any())
345+
Task.WaitAll(ConfigurationService!.AdditionalDataSource.Select(config =>
346+
Task.Factory.StartNew(() =>
347+
{
348+
IoC.Get<DataSourceService>().AddOrUpdateDataSource(config, doReload: false);
349+
})).ToArray());
350+
IoC.Get<GlobalData>().ReloadServerList(true);
351+
MaskLayerController.HideMask();
352+
});
347353
}
348354
}
349355
}

Ui/AppVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class AppVersion
88
public const uint Minor = 0;
99
public const uint Patch = 0;
1010
public const uint Build = 0;
11-
public const string PreRelease = "beta.01"; // e.g. "alpha" "beta.2"
11+
public const string PreRelease = "beta.02"; // e.g. "alpha" "beta.2"
1212

1313

1414
public static readonly VersionHelper.Version VersionData = new VersionHelper.Version(Major, Minor, Patch, Build, PreRelease);

Ui/Model/GlobalData.cs

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
using System.Diagnostics;
55
using System.Linq;
66
using System.Timers;
7-
using _1RM.Model.DAO;
87
using _1RM.Model.Protocol.Base;
98
using _1RM.Service;
109
using _1RM.Service.DataSource;
10+
using _1RM.Service.DataSource.DAO;
1111
using _1RM.Service.DataSource.Model;
12+
using _1RM.Utils;
1213
using _1RM.View;
1314
using _1RM.View.Launcher;
1415
using Shawn.Utils;
16+
using Stylet;
1517
using ServerListPageViewModel = _1RM.View.ServerList.ServerListPageViewModel;
1618

1719
namespace _1RM.Model
@@ -34,7 +36,7 @@ public GlobalData(ConfigurationService configurationService)
3436
_timer.Start();
3537
}
3638

37-
private DataSourceService _sourceService;
39+
private DataSourceService? _sourceService;
3840
private readonly ConfigurationService _configurationService;
3941

4042
public void SetDataSourceService(DataSourceService sourceService)
@@ -112,13 +114,17 @@ public bool ReloadServerList(bool focus = false)
112114
foreach (var additionalSource in _sourceService.AdditionalSources)
113115
{
114116
// 对于断线的数据源,隔一段时间后尝试重连
115-
if (additionalSource.Value.Status == EnumDatabaseStatus.LostConnection)
117+
// TODO try to reconnect when network is available
118+
if (additionalSource.Value.Status != EnumDatabaseStatus.OK)
116119
{
120+
#if DEBUG
121+
if (additionalSource.Value.StatueTime.AddMinutes(1) < DateTime.Now)
122+
#else
117123
if (additionalSource.Value.StatueTime.AddMinutes(10) < DateTime.Now)
124+
#endif
118125
{
119126
additionalSource.Value.Database_SelfCheck();
120127
}
121-
continue;
122128
}
123129

124130
if (needRead == false)
@@ -287,53 +293,6 @@ public Result UpdateServer(IEnumerable<ProtocolBase> protocolServers)
287293
}
288294
}
289295

290-
public Result DeleteServer(ProtocolBase protocolServer)
291-
{
292-
StopTick();
293-
try
294-
{
295-
Debug.Assert(protocolServer.IsTmpSession() == false);
296-
297-
var source = protocolServer.GetDataSource();
298-
var needReload = source?.NeedRead() ?? false;
299-
if (source == null || source.IsWritable == false)
300-
{
301-
// 正常情况下,不应该执行到这个地方
302-
return Result.Fail($"TXT: We can not delete on `{protocolServer.DataSourceName}` because `{protocolServer.DataSourceName}` is readonly for you");
303-
};
304-
305-
var ret = source.Database_DeleteServer(protocolServer.Id);
306-
if (ret.IsSuccess)
307-
{
308-
if (needReload == false)
309-
{
310-
var old = GetItemById(source.DataSourceName, protocolServer.Id);
311-
if (old != null)
312-
{
313-
VmItemList.Remove(old);
314-
IoC.Get<ServerListPageViewModel>()?.VmServerList?.Remove(old); // invoke main list ui change
315-
IoC.Get<ServerSelectionsViewModel>()?.VmServerList?.Remove(old); // invoke launcher ui change
316-
}
317-
}
318-
319-
if (needReload)
320-
{
321-
ReloadServerList();
322-
}
323-
else
324-
{
325-
ReadTagsFromServers();
326-
IoC.Get<ServerListPageViewModel>().ClearSelection();
327-
}
328-
}
329-
return ret;
330-
}
331-
finally
332-
{
333-
StartTick();
334-
}
335-
}
336-
337296
public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
338297
{
339298
StopTick();
@@ -362,8 +321,13 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
362321
if (old != null)
363322
{
364323
VmItemList.Remove(old);
365-
IoC.Get<ServerListPageViewModel>().VmServerList.Remove(old); // invoke main list ui change
366-
IoC.Get<ServerSelectionsViewModel>().VmServerList.Remove(old); // invoke launcher ui change
324+
Execute.OnUIThread(() =>
325+
{
326+
if (IoC.Get<ServerListPageViewModel>().VmServerList.Contains(old))
327+
IoC.Get<ServerListPageViewModel>().VmServerList.Remove(old); // invoke main list ui change
328+
if (IoC.Get<ServerSelectionsViewModel>().VmServerList.Contains(old))
329+
IoC.Get<ServerSelectionsViewModel>().VmServerList.Remove(old); // invoke launcher ui change
330+
});
367331
}
368332
}
369333
}
@@ -398,6 +362,11 @@ public Result DeleteServer(IEnumerable<ProtocolBase> protocolServers)
398362
return Result.Success();
399363
}
400364
}
365+
catch (Exception e)
366+
{
367+
MsAppCenterHelper.Error(e);
368+
throw;
369+
}
401370
finally
402371
{
403372
StartTick();
@@ -444,13 +413,18 @@ private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
444413

445414
if (ReloadServerList())
446415
{
447-
SimpleLogHelper.Debug("check database update - reload data" + _timer.GetHashCode());
416+
SimpleLogHelper.Debug("check database update - reload data by timer " + _timer.GetHashCode());
448417
}
449418
else
450419
{
451-
SimpleLogHelper.Debug("check database update - no need reload" + _timer.GetHashCode());
420+
SimpleLogHelper.Debug("check database update - no need reload by timer " + _timer.GetHashCode());
452421
}
453422
}
423+
catch (Exception ex)
424+
{
425+
MsAppCenterHelper.Error(ex);
426+
throw;
427+
}
454428
finally
455429
{
456430
lock (this)

Ui/Model/GlobalEventHelper.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ public static class GlobalEventHelper
4747
public delegate void OnRequestGoToServerMultipleEditPageDelegate(IEnumerable<ProtocolBase> servers, bool showAnimation = true);
4848
public static OnRequestGoToServerMultipleEditPageDelegate? OnRequestGoToServerMultipleEditPage { get; set; } = null;
4949

50-
public delegate void OnRequestDeleteServerDelegate(ProtocolBase server);
51-
public static OnRequestDeleteServerDelegate? OnRequestDeleteServer { get; set; } = null;
52-
5350

5451
/// <summary>
5552
/// Invoke to notify language was changed.

Ui/Model/Protocol/Base/Credential.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Net.Sockets;
55
using System.Reflection;
66
using _1Remote.Security;
7-
using _1RM.Model.DAO.Dapper;
7+
using _1RM.Service.DataSource.DAO.Dapper;
88
using _1RM.Utils;
99
using JsonKnownTypes;
1010
using Newtonsoft.Json;

Ui/Service/ConfigurationService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4-
using System.Diagnostics;
5-
using System.Globalization;
64
using System.IO;
75
using System.Linq;
86
using System.Text;
9-
using System.Threading.Tasks;
107
using System.Windows.Input;
118
using Newtonsoft.Json;
12-
using _1RM.Model.DAO;
139
using _1RM.Service.DataSource;
1410
using _1RM.Service.DataSource.Model;
1511
using _1RM.Utils;
1612
using Shawn.Utils;
1713
using Shawn.Utils.Wpf;
18-
using Shawn.Utils.Wpf.FileSystem;
1914
using VariableKeywordMatcher.Provider.DirectMatch;
2015
using SetSelfStartingHelper = _1RM.Utils.SetSelfStartingHelper;
2116

Ui/Service/ConnectionTimeRecorder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
using System.Collections.Generic;
44
using System.IO;
55
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
8-
using _1RM.Model.DAO.Dapper;
96
using _1RM.Model.Protocol.Base;
107
using _1RM.Utils;
118
using _1RM.View;
@@ -14,6 +11,9 @@
1411

1512
namespace _1RM.Service
1613
{
14+
/// <summary>
15+
/// keep the last connect time of each server, in order to sort the server list
16+
/// </summary>
1717
public static class ConnectTimeRecorder
1818
{
1919
public static string Path { get; private set; } = "";

Ui/Service/DataBaseService.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Diagnostics;
3-
using System.IO;
4-
using com.github.xiangyuecn.rsacsharp;
5-
using _1RM.Model.DAO;
6-
using _1RM.Model.DAO.Dapper;
7-
using _1RM.Model.Protocol;
1+
using _1RM.Model.Protocol;
82
using _1RM.Model.Protocol.Base;
93
using _1RM.Utils;
104

115
namespace _1RM.Service
126
{
13-
147
public static class DataService
158
{
169
public static void EncryptToDatabaseLevel(this ProtocolBase server)
@@ -28,15 +21,15 @@ public static void EncryptToDatabaseLevel(this ProtocolBase server)
2821
switch (server)
2922
{
3023
case SSH ssh when !string.IsNullOrWhiteSpace(ssh.PrivateKey):
31-
{
32-
ssh.PrivateKey = UnSafeStringEncipher.EncryptOnce(ssh.PrivateKey);
33-
break;
34-
}
24+
{
25+
ssh.PrivateKey = UnSafeStringEncipher.EncryptOnce(ssh.PrivateKey);
26+
break;
27+
}
3528
case RDP rdp when !string.IsNullOrWhiteSpace(rdp.GatewayPassword):
36-
{
37-
rdp.GatewayPassword = UnSafeStringEncipher.EncryptOnce(rdp.GatewayPassword);
38-
break;
39-
}
29+
{
30+
rdp.GatewayPassword = UnSafeStringEncipher.EncryptOnce(rdp.GatewayPassword);
31+
break;
32+
}
4033
}
4134
}
4235

Ui/Model/DAO/Dapper/Config.cs renamed to Ui/Service/DataSource/DAO/Dapper/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace _1RM.Model.DAO.Dapper
1+
namespace _1RM.Service.DataSource.DAO.Dapper
22
{
33
public class Config
44
{

0 commit comments

Comments
 (0)