Преглед на файлове

优化重连机制,及测试选择连接新老服务器的方式。

felix преди 1 година
родител
ревизия
0c26670949

+ 1 - 1
FISSDK/FISIMPL/TestService.cs

@@ -81,7 +81,7 @@ namespace FISIMPL
                         {
                             isTestInOldMode = true;
                         }
-                        else if (vCloudPort == 80)
+                        else if (vCloudPort == 80 || vCloudPort == 8303)
                         {
                             isTestInOldMode = false;
                             isUseHttps = false;

+ 17 - 4
Vinno.vCloud.Common.FIS/ConnectionCheckerV2.cs

@@ -4,6 +4,7 @@ using System.Threading.Tasks;
 using Vinno.IUS.Common.Log;
 using Vinno.vCloud.Common.FIS.Helper;
 using Vinno.vCloud.FIS.CrossPlatform.Common;
+using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
 using WingInterfaceLibrary.DTO.ServerInfo;
 using WingInterfaceLibrary.Interface;
 
@@ -22,12 +23,16 @@ namespace Vinno.vCloud.Common.FIS
 
         private bool _defaultStatus;
 
+        private bool _checkLoginStatus;
+
         public event EventHandler Offlined;
 
         public ConnectionCheckerV2(IVinnoServerService vinnoServerService, int connectionCheckCycle)
         {
             _vinnoServerService = vinnoServerService;
             _connectionCheckCycle = connectionCheckCycle;
+            _defaultStatus = false;
+            _checkLoginStatus = false;
         }
 
         /// <summary>
@@ -36,6 +41,7 @@ namespace Vinno.vCloud.Common.FIS
         public void Start(bool defaultStatus)
         {
             _defaultStatus = defaultStatus;
+            _checkLoginStatus = defaultStatus;
             Task.Run(() =>
             {
                 while (!_waitEvent.WaitOne(TimeSpan.FromSeconds(_connectionCheckCycle)))
@@ -59,7 +65,7 @@ namespace Vinno.vCloud.Common.FIS
             {
                 if (_defaultStatus)
                 {
-                    if (!Check(true, true))
+                    if (!Check(true))
                     {
                         OnOfflined();
                     }
@@ -75,13 +81,20 @@ namespace Vinno.vCloud.Common.FIS
             }
         }
 
-        public bool Check(bool doubleCheck = true, bool checkLoginStatus = false)
+        public bool Check(bool doubleCheck = true)
         {
             try
             {
-                if (!CommonParameter.Instance.IsLogon && checkLoginStatus)
+                if (_checkLoginStatus)
                 {
-                    return false;
+                    if (CommonParameter.Instance.DeviceStatus == EnumDeviceStatus.Offline || CommonParameter.Instance.DeviceStatus == EnumDeviceStatus.LoginFailed)
+                    {
+                        return false;
+                    }
+                    else
+                    {
+                        _checkLoginStatus = false;
+                    }
                 }
                 EchoResult result = JsonRpcHelper.Echo(_vinnoServerService);
                 if (result == null || result.Code != 0)

+ 73 - 46
Vinno.vCloud.Common.FIS/vCloudServerSelector.cs

@@ -75,7 +75,12 @@ namespace Vinno.vCloud.Common.FIS
             var result = LeafTest();
             stopwatch.Stop();
             Logger.WriteLineInfo($"LeafTest 1st Time Cost {stopwatch.ElapsedMilliseconds}ms,result is {result}");
-            if (!result && !_cts.IsCancellationRequested)
+            if (_cts.IsCancellationRequested)
+            {
+                Logger.WriteLineInfo($"LeafTest 2nd Time Cancelled");
+                return;
+            }
+            else if (!result)
             {
                 stopwatch.Restart();
                 result = LeafTest();
@@ -88,20 +93,26 @@ namespace Vinno.vCloud.Common.FIS
         {
             try
             {
-                if (_leaf != null)
+                _leaf?.Close();
+                _leaf = null;
+                var url = $"{_host}:{_port}";
+                _leaf = new ClientLeaf(new LeafIdContext(), LeafMode.Dual, new TcpCreator(url));
+                if (_cts.IsCancellationRequested)
                 {
-                    _leaf.Close();
+                    _leaf?.Close();
                     _leaf = null;
+                    return false;
                 }
-                var url = $"{_host}:{_port}";
-                _leaf = new ClientLeaf(new LeafIdContext(), LeafMode.Dual, new TcpCreator(url));
-                if (_leaf.Online)
+                else
                 {
-                    _testResult = ServerTestResult.OldServer;
-                    _manualResetEvent.Set();
-                    return true;
+                    if (_leaf.Online)
+                    {
+                        _testResult = ServerTestResult.OldServer;
+                        _manualResetEvent.Set();
+                        return true;
+                    }
+                    return false;
                 }
-                return false;
             }
             catch
             {
@@ -123,7 +134,20 @@ namespace Vinno.vCloud.Common.FIS
             {
                 Logger.WriteLineInfo($"JsonRpcTest For Http 1st Time Cost {stopwatch.ElapsedMilliseconds}ms,result is {result}");
             }
-            if (!result && !_cts.IsCancellationRequested)
+            if (_cts.IsCancellationRequested)
+            {
+                if (isUseHttps)
+                {
+                    Logger.WriteLineInfo($"JsonRpcTest For Https 2nd Time Cancelled");
+                    return;
+                }
+                else
+                {
+                    Logger.WriteLineInfo($"JsonRpcTest For Http 2nd Time Cancelled");
+                    return;
+                }
+            }
+            else if (!result)
             {
                 stopwatch.Restart();
                 result = isUseHttps ? JsonRpcTestWithHttps() : JsonRpcTestWithHttp();
@@ -143,24 +167,30 @@ namespace Vinno.vCloud.Common.FIS
         {
             try
             {
-                if (_clientForHttp != null)
-                {
-                    _clientForHttp.Dispose();
-                    _clientForHttp = null;
-                }
+                _clientForHttp?.Dispose();
+                _clientForHttp = null;
                 var url = $"http://{_host}:{_port}";
                 _clientForHttp = new JsonRpcClient();
                 var clientEngine = new JsonRpcHttpClientEngine(url);
                 _clientForHttp.UseEngine(clientEngine);
                 var vinnoServerService = _clientForHttp.CreateProxy<IVinnoServerService>(5000);
                 var echoResult = JsonRpcHelper.Echo(vinnoServerService);
-                if (echoResult != null && echoResult.Code == 0)
+                if (_cts.IsCancellationRequested)
                 {
-                    _testResult = ServerTestResult.NewServerWithHttp;
-                    _manualResetEvent.Set();
-                    return true;
+                    _clientForHttp?.Dispose();
+                    _clientForHttp = null;
+                    return false;
+                }
+                else
+                {
+                    if (echoResult != null && echoResult.Code == 0)
+                    {
+                        _testResult = ServerTestResult.NewServerWithHttp;
+                        _manualResetEvent.Set();
+                        return true;
+                    }
+                    return false;
                 }
-                return false;
             }
             catch
             {
@@ -172,24 +202,30 @@ namespace Vinno.vCloud.Common.FIS
         {
             try
             {
-                if (_clientForHttps != null)
-                {
-                    _clientForHttps.Dispose();
-                    _clientForHttps = null;
-                }
+                _clientForHttps?.Dispose();
+                _clientForHttps = null;
                 var url = $"https://{_host}:{_port}";
                 _clientForHttps = new JsonRpcClient();
                 var clientEngine = new JsonRpcHttpClientEngine(url);
                 _clientForHttps.UseEngine(clientEngine);
                 var vinnoServerService = _clientForHttps.CreateProxy<IVinnoServerService>(5000);
                 var echoResult = JsonRpcHelper.Echo(vinnoServerService);
-                if (echoResult != null && echoResult.Code == 0)
+                if (_cts.IsCancellationRequested)
                 {
-                    _testResult = ServerTestResult.NewServerWithHttps;
-                    _manualResetEvent.Set();
-                    return true;
+                    _clientForHttps?.Dispose();
+                    _clientForHttps = null;
+                    return false;
+                }
+                else
+                {
+                    if (echoResult != null && echoResult.Code == 0)
+                    {
+                        _testResult = ServerTestResult.NewServerWithHttps;
+                        _manualResetEvent.Set();
+                        return true;
+                    }
+                    return false;
                 }
-                return false;
             }
             catch
             {
@@ -203,21 +239,12 @@ namespace Vinno.vCloud.Common.FIS
             {
                 _manualResetEvent.Set();
                 _cts?.Cancel();
-                if (_leaf != null)
-                {
-                    _leaf.Close();
-                    _leaf = null;
-                }
-                if (_clientForHttp != null)
-                {
-                    _clientForHttp.Dispose();
-                    _clientForHttp = null;
-                }
-                if (_clientForHttps != null)
-                {
-                    _clientForHttps.Dispose();
-                    _clientForHttps = null;
-                }
+                _clientForHttp?.Dispose();
+                _clientForHttp = null;
+                _clientForHttps?.Dispose();
+                _clientForHttps = null;
+                _leaf?.Close();
+                _leaf = null;
             }
             catch (Exception ex)
             {

+ 1 - 1
Vinno.vCloud.Common.FIS/vCloudTerminal.cs

@@ -84,7 +84,7 @@ namespace Vinno.vCloud.Common.FIS
                 if (_status != value)
                 {
                     _status = value;
-                    CommonParameter.Instance.IsLogon = _status == TerminalStatus.Logon;
+                    CommonParameter.Instance.DeviceStatus = (EnumDeviceStatus)_status;
                     OnStatusChanged();
                 }
             }

+ 2 - 2
Vinno.vCloud.Common.FIS/vCloudTerminalV2.cs

@@ -91,7 +91,7 @@ namespace Vinno.vCloud.Common.FIS
                 if (_status != value)
                 {
                     _status = value;
-                    CommonParameter.Instance.IsLogon = _status == TerminalStatus.Logon;
+                    CommonParameter.Instance.DeviceStatus = (EnumDeviceStatus)_status;
                     OnStatusChanged();
                 }
             }
@@ -593,7 +593,7 @@ namespace Vinno.vCloud.Common.FIS
         {
             _connectionChecker = new ConnectionCheckerV2(_vinnoServerService, _connectionCheckCycle);
             var defaultStatus = false;
-            if (!_connectionChecker.Check(false, false))
+            if (!_connectionChecker.Check(false))
             {
                 Status = TerminalStatus.Offline;
             }

+ 1 - 0
Vinno.vCloud.FIS.CrossPlatform.Common.Android/Vinno.vCloud.FIS.CrossPlatform.Common.Android.csproj

@@ -28,6 +28,7 @@
     <Compile Include="..\Vinno.vCloud.FIS.CrossPlatform.Common\Enum\EnumClientOSType.cs" Link="Enum\EnumClientOSType.cs" />
     <Compile Include="..\Vinno.vCloud.FIS.CrossPlatform.Common\Enum\EnumCpuLevel.cs" Link="Enum\EnumCpuLevel.cs" />
     <Compile Include="..\Vinno.vCloud.FIS.CrossPlatform.Common\Enum\EnumDeviceLiveState.cs" Link="Enum\EnumDeviceLiveState.cs" />
+    <Compile Include="..\Vinno.vCloud.FIS.CrossPlatform.Common\Enum\EnumDeviceStatus.cs" Link="Enum\EnumDeviceStatus.cs" />
     <Compile Include="..\Vinno.vCloud.FIS.CrossPlatform.Common\Enum\EnumFrameRateMode.cs" Link="Enum\EnumFrameRateMode.cs" />
     <Compile Include="..\Vinno.vCloud.FIS.CrossPlatform.Common\Enum\EnumHardwareType.cs" Link="Enum\EnumHardwareType.cs" />
     <Compile Include="..\Vinno.vCloud.FIS.CrossPlatform.Common\Enum\EnumHeartRateType.cs" Link="Enum\EnumHeartRateType.cs" />

+ 4 - 2
Vinno.vCloud.FIS.CrossPlatform.Common/CommonParameter.cs

@@ -1,4 +1,6 @@
-namespace Vinno.vCloud.FIS.CrossPlatform.Common
+using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
+
+namespace Vinno.vCloud.FIS.CrossPlatform.Common
 {
     public class CommonParameter
     {
@@ -25,7 +27,7 @@
         /// <summary>
         /// 是否登录
         /// </summary>
-        public bool IsLogon { get; set; }
+        public EnumDeviceStatus DeviceStatus { get; set; }
 
         private static CommonParameter _instance;
         public static CommonParameter Instance => _instance ?? (_instance = new CommonParameter());

+ 18 - 0
Vinno.vCloud.FIS.CrossPlatform.Common/Enum/EnumDeviceStatus.cs

@@ -0,0 +1,18 @@
+namespace Vinno.vCloud.FIS.CrossPlatform.Common.Enum
+{
+    public enum EnumDeviceStatus
+    {
+        Offline, //Terminal is offline.
+        Online, //Terminal connected.
+        Logoning,//At the beginning terminal login success
+        Logon, //Terminal already logon
+        ReLogin, // Terminal is going to relogin.
+        ReplacedNotification,
+        LoginFailed,
+        OrganizationMissing,
+        WrongAccount,
+        WrongPassword,
+        Reconnecting,//Reconnect after newtwork offline
+        Logoff
+    }
+}