|
@@ -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>
|
|
|
/// 判断是否重复打开
|