jimmy.jiang@vinno.com 8 mēneši atpakaļ
vecāks
revīzija
48a45ce62d

+ 85 - 2
Client/PC/vStation/App.xaml.cs

@@ -17,6 +17,11 @@ using vStation.URMStationRelevant;
 using Newtonsoft.Json;
 using System.Collections.Generic;
 using URMServiceConfig;
+using JsonRpcLite.Rpc;
+using JsonRpcLite.Network;
+using WingInterfaceLibrary.Interface;
+using JsonRpcLite.Services;
+using NPOI.SS.Formula.Functions;
 namespace vStation
 {
     /// <summary>
@@ -53,7 +58,7 @@ namespace vStation
             Current.Exit += OnExit;
           
             AppManager.Instance.RegisterFunction(typeof(IDbService), new DbService());
-            AppManager.Instance.RegisterFunction(typeof(ILoginService), new LoginService());
+            AppManager.Instance.RegisterFunction(typeof(Module.Login.ILoginService), new LoginService());
             AppManager.Instance.RegisterFunction(typeof(ISystemSettingManager), new SystemSettingManager());
             AppManager.Instance.RegisterFunction(typeof(ISystemSettingExamPointFee), new SystemSettingExamPointFee());
             Config.IsURMStation = true;
@@ -80,6 +85,16 @@ namespace vStation
                     root.server.current = "http://127.0.0.1:8303";
                     var txt = JsonConvert.SerializeObject(root);
                     File.WriteAllText(URMConfig.ConfigPath, txt );
+                    if (ValidateServerAddress(root.server.current).Result)
+                    {
+                        Logger.WriteLineInfo("Server already start");
+                    }
+                    else
+                    {
+                        Logger.WriteLineInfo("Server on reachable, try to start it");
+                        ControlServer(true);
+                    }
+
                 }
             }
             else {
@@ -100,7 +115,75 @@ namespace vStation
             URMConfig.RPCAddress = root.server.current;
 
         }
-      
+
+
+        private void ControlServer(bool isOpen, bool isRestart = false)
+        {
+            var targetPath = isOpen ? URMConfig.StartServerBatchFile : URMConfig.CloseServerBatchFile;
+            ProcessStartInfo processInfo2 = new ProcessStartInfo(targetPath)
+            {
+                CreateNoWindow = true,
+                UseShellExecute = false,
+                RedirectStandardError = true,
+                RedirectStandardOutput = true,
+                Verb = "runas",
+                // 不使用操作系统外壳程序启动进程
+            };
+            Process.Start(processInfo2);
+
+
+        }
+
+
+
+        private async Task<bool> ValidateServerAddress(string address)
+        {
+            try
+            {
+                var client = new JsonRpcClient();
+                var clientEngine = new JsonRpcHttpClientEngine(address);
+                client.UseEngine(clientEngine);
+
+                var loginService = client?.CreateProxy<WingInterfaceLibrary.Interface.ILoginService>();
+                if (loginService == null)
+                {
+                    return false;
+                }
+               
+                var result = await loginService.CommonLoginAsync(new WingInterfaceLibrary.Request.User.CommonLoginRequest()
+                {
+
+                });
+                if (result == null)
+                {
+                    return false;
+                }
+                if (result.LoginState == WingInterfaceLibrary.Enum.LoginStateEnum.SignOrLoginFail ||
+                    result.LoginState == WingInterfaceLibrary.Enum.LoginStateEnum.PasswordIncorrect
+                    )
+                {
+
+                    return true;
+                }
+
+            }
+            catch (RpcException ex)
+            {
+                return true;
+            }
+            catch (Exception ex)
+            {
+               
+                return false;
+            }
+            finally
+            {
+
+            }
+            return true;
+
+
+        }
 
         /// <summary>
         /// 判断是否重复打开

+ 6 - 0
Client/PC/vStation/URMStationRelevant/URMConfig.cs

@@ -42,6 +42,12 @@ namespace vStation.URMStationRelevant
 
         public static string StationVersionPath=> Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StationVersion.txt");
 
+        public static string ServerPath=> Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FlyinsonoLabServer");
+
+        public static string StartServerBatchFile => Path.Combine(ServerPath, "start - 1.bat");
+
+        public static string CloseServerBatchFile => Path.Combine(ServerPath, "close - 1.bat");
+
         public static bool GetIsSingleMode()
         {
             if (File.Exists(StationVersionPath))

+ 1 - 0
Client/PC/vStation/ViewModel/MainWindowViewModel.cs

@@ -250,6 +250,7 @@ namespace vStation.ViewModel
             }
         }
 
+
         private void StopDicomServer()
         {
             if (_dicomServer != null && _dicomServer.IsStarted)