Selaa lähdekoodia

更新Server依赖项 独立启动(DB、SMS)

MIke 2 vuotta sitten
vanhempi
commit
9a39841290

+ 26 - 11
src/Process/ProcessStarter.cs

@@ -14,30 +14,45 @@ namespace WingCloudServer.Loader
         /// <param name="processName">工具程序名称</param>
         public static void StartTool(string processName, string paramsValue = "")
         {
-            var toolsRootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools");
-            var subPath = GetPlatfromTitle();
-            var tool = Path.Combine(toolsRootPath, subPath, $"{subPath}_{processName}");
-            if (Process.GetProcessesByName(Path.GetFileName(tool)).Length == 0)
+            if (!string.IsNullOrEmpty(processName))
             {
-                using (Process process = new Process())
+                var toolsRootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools");
+                var toolPath = string.Empty;
+                if (processName.Contains("\\")) //路径
+                {
+                    toolPath = Path.Combine(toolsRootPath, processName);
+                }
+                else
                 {
-                    process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
-                    process.StartInfo.FileName = tool;
-                    process.StartInfo.Arguments = paramsValue;
-                    process.Start();
+                    var subPath = GetPlatfromTitle();
+                    toolPath = Path.Combine(toolsRootPath, subPath, $"{subPath}_{processName}");
+                }
+
+                if (Process.GetProcessesByName(Path.GetFileName(toolPath)).Length == 0)
+                {
+                    using (Process process = new Process())
+                    {
+                        process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
+                        process.StartInfo.FileName = toolPath;
+                        process.StartInfo.Arguments = paramsValue;
+                        process.Start();
+                    }
                 }
             }
+
+
         }
 
         /// <summary>
         /// 开始执行工具程序
         /// </summary>
         /// <param name="processName">工具程序名称</param>
-        public static void StartProcess(string path)
+        public static void StartProcess(string namePath)
         {
+            var toolsRootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools");
             Process process = new Process();
             process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
-            process.StartInfo.FileName = path;
+            process.StartInfo.FileName = Path.Combine(toolsRootPath,namePath);
             //process.StartInfo.Arguments = paramsValue;
             process.Start();
         }

BIN
src/Tools/StartMongodTool/Newtonsoft.Json.dll


+ 8 - 0
src/Tools/StartMongodTool/appsettings.json

@@ -0,0 +1,8 @@
+{
+ 
+  "DBPath": "Mongodb\\Data",
+  "LogPath": "Mongodb\\Logs\\DBlog",
+  "Server": "127.0.0.1",
+  "Port": 8301,
+  "OtherParameters": "--nojournal  --quiet"
+}

+ 41 - 0
src/Tools/StartMongodTool/mongod.deps.json

@@ -0,0 +1,41 @@
+{
+  "runtimeTarget": {
+    "name": ".NETCoreApp,Version=v6.0",
+    "signature": ""
+  },
+  "compilationOptions": {},
+  "targets": {
+    ".NETCoreApp,Version=v6.0": {
+      "mongod/1.0.0": {
+        "dependencies": {
+          "Newtonsoft.Json": "13.0.1"
+        },
+        "runtime": {
+          "mongod.dll": {}
+        }
+      },
+      "Newtonsoft.Json/13.0.1": {
+        "runtime": {
+          "lib/netstandard2.0/Newtonsoft.Json.dll": {
+            "assemblyVersion": "13.0.0.0",
+            "fileVersion": "13.0.1.25517"
+          }
+        }
+      }
+    }
+  },
+  "libraries": {
+    "mongod/1.0.0": {
+      "type": "project",
+      "serviceable": false,
+      "sha512": ""
+    },
+    "Newtonsoft.Json/13.0.1": {
+      "type": "package",
+      "serviceable": true,
+      "sha512": "sha512-ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==",
+      "path": "newtonsoft.json/13.0.1",
+      "hashPath": "newtonsoft.json.13.0.1.nupkg.sha512"
+    }
+  }
+}

BIN
src/Tools/StartMongodTool/mongod.dll


BIN
src/Tools/WingStartTool/WingStartTool.exe → src/Tools/StartMongodTool/mongod.exe


+ 0 - 3
src/Tools/WingStartTool/WingStartTool.runtimeconfig.json → src/Tools/StartMongodTool/mongod.runtimeconfig.json

@@ -4,9 +4,6 @@
     "framework": {
       "name": "Microsoft.NETCore.App",
       "version": "6.0.0"
-    },
-    "configProperties": {
-      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false
     }
   }
 }

+ 0 - 23
src/Tools/WingStartTool/WingStartTool.deps.json

@@ -1,23 +0,0 @@
-{
-  "runtimeTarget": {
-    "name": ".NETCoreApp,Version=v6.0",
-    "signature": ""
-  },
-  "compilationOptions": {},
-  "targets": {
-    ".NETCoreApp,Version=v6.0": {
-      "WingStartTool/1.0.0": {
-        "runtime": {
-          "WingStartTool.dll": {}
-        }
-      }
-    }
-  },
-  "libraries": {
-    "WingStartTool/1.0.0": {
-      "type": "project",
-      "serviceable": false,
-      "sha512": ""
-    }
-  }
-}

BIN
src/Tools/WingStartTool/WingStartTool.dll


+ 44 - 14
src/WingApplicationBuilder.cs

@@ -1,3 +1,4 @@
+using System.Diagnostics;
 using System;
 using System.Collections.Generic;
 using System.IO;
@@ -18,6 +19,7 @@ namespace WingCloudServer
     internal class WingApplicationBuilder
     {
         private WingApplication _app;
+        private List<string> _dependencieNames = new List<string>();
         public WingApplicationBuilder(string[] args)
         {
             //TODO args ?  when to use   
@@ -39,16 +41,36 @@ namespace WingCloudServer
             //=========================================================================//         
 
             //启动 工具
-            if (ConfigurationManager.GetParammeter<BoolParameter>("StartTool", "Enable").Value)
+            var _dependencies = ConfigurationManager.GetParammeter<StringParameter>("Dependencies", "Data").Value;
+            if (!string.IsNullOrEmpty(_dependencies))
             {
-                //TODO 跨平台
-                var startToolName = ConfigurationManager.GetParammeter<StringParameter>("StartTool", "StartToolName").Value;
-                if (string.IsNullOrEmpty(startToolName))
+                var items = _dependencies.Split(',');
+                foreach (var item in items)
                 {
-                    startToolName = "startTool.bat";
+                    var array = item.Split('-');
+                    if (array == null || array.Length <= 1)
+                    {
+                        if (item.Contains('\\'))
+                        {
+                            ProcessStarter.StartProcess(item);
+                            var arrayexe = item.Split('\\');
+                            if (arrayexe.Length > 0)
+                            {
+                                _dependencieNames.Add(arrayexe[1]);
+                            }
+                        }
+                        else
+                        {
+                            ProcessStarter.StartTool(item);
+                            _dependencieNames.Add(item);
+                        }
+                    }
+                    if (array.Length == 2)
+                    {
+                        ProcessStarter.StartTool(array[0], array[1]);
+                        _dependencieNames.Add(array[0]);
+                    }
                 }
-                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, startToolName);
-                ProcessStarter.StartProcess(path);
             }
             _app.Run();
         }
@@ -56,16 +78,24 @@ namespace WingCloudServer
         internal void Stop()
         {
             _app?.Stop();
-             if (ConfigurationManager.GetParammeter<BoolParameter>("StartTool", "Enable").Value)
+
+            foreach (var processName in _dependencieNames)
             {
-                //TODO 跨平台
-                var startToolName = ConfigurationManager.GetParammeter<StringParameter>("StartTool", "ClosedToolName").Value;
-                if (string.IsNullOrEmpty(startToolName))
+                var proc = Process.GetProcesses();
+                foreach (var p in proc)
                 {
-                    startToolName = "closedTool.bat";
+                    try
+                    {
+                        if (p.ProcessName.Contains(processName))
+                        {
+                            Process.GetProcessById(p.Id).Kill();
+                        }
+                    }
+                    catch (Exception pex)
+                    {
+                        Console.WriteLine($"{pex}");
+                    }
                 }
-                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, startToolName);
-                ProcessStarter.StartProcess(path);
             }
         }
     }

+ 3 - 5
src/appsettings.json

@@ -6,7 +6,7 @@
     "MasterUrl": ""
   },
   "Gateway": {
-    "Host": "http://192.168.6.69/"    
+    "Host": "http://192.168.6.20:8303/"
   },
   "Log": {
     "Level": "info",
@@ -72,10 +72,8 @@
   "User": {
     "HeartRateSeconds": 300
   },
-  "StartTool":{
-    "Enable": true,
-    "StartToolName":"startTool.bat",
-    "ClosedToolName":"closedTool.bat"
+  "Dependencies":{
+      "Data": "StartMongodTool\\mongod,Sms.Tool-http://*:8302/"
   },
   "FastServer": {
     "ServerHost": "http://*:9304/"

+ 0 - 3
src/closedTool.bat

@@ -1,3 +0,0 @@
-@echo off
-taskkill /f /im  win_Sms.Tool.exe
-taskkill /f /im  win_mongod.exe

+ 1 - 1
src/startMongoDB.bat

@@ -1,3 +1,3 @@
 @echo off
 cd %~dp0Tools\WingStartTool
-start /b  WingStartTool.exe "%~dp0Tools "  "--dbpath  %~dp0Mongodb\Data  --logpath  %~dp0Mongodb\Logs\DBLog   --port 8301  --nojournal  --quiet "
+start /b  mongod.exe "%~dp0Tools "  "--dbpath  %~dp0Mongodb\Data  --logpath  %~dp0Mongodb\Logs\DBLog   --port 8301  --nojournal  --quiet "

+ 3 - 0
src/startSmsTool.bat

@@ -0,0 +1,3 @@
+@echo off
+cd %~dp0Tools\win
+start /b win_Sms.Tool.exe  "http://*:8302/"

+ 0 - 9
src/startTool.bat

@@ -1,9 +0,0 @@
-@echo off
-cd %~dp0Tools\win
-taskkill /f /im  win_Sms.Tool.exe
-start /b win_Sms.Tool.exe  "http://*:8302/"
-cd %~dp0Tools\WingStartTool
-
- start /b  WingStartTool.exe "%~dp0Tools "  "--dbpath  %~dp0Mongodb\Data  --logpath  %~dp0Mongodb\Logs\DBLog   --port 8301  --nojournal  --quiet "
- 
-