From 2f197337e0ad57140eec9f565ab4d4129d64ef20 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Thu, 25 May 2023 16:42:33 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20IPC=20=E5=AD=90=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E4=B8=BB=E8=BF=9B=E7=A8=8B=E9=80=80=E5=87=BA?= =?UTF-8?q?=E6=97=B6=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BD.WTTS.Client.AppHost/Program.cs | 2 +- .../Services/IPCSubProcessService.cs | 17 ++++++++-------- .../IPC/IPCMainProcessServiceImpl.cs | 4 +++- .../Startup/Startup.Commands.cs | 20 +++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/BD.WTTS.Client.AppHost/Program.cs b/src/BD.WTTS.Client.AppHost/Program.cs index 4e5e1abf7..1d7ee8a21 100644 --- a/src/BD.WTTS.Client.AppHost/Program.cs +++ b/src/BD.WTTS.Client.AppHost/Program.cs @@ -12,7 +12,7 @@ static unsafe partial class Program { public const string dotnet_version_major = "7"; public const string dotnet_version_minor = "0"; - public const string dotnet_version_build = "4"; + public const string dotnet_version_build = "5"; public const string dotnet_version = $"{dotnet_version_major}.{dotnet_version_minor}.{dotnet_version_build}"; const string dotnet_runtime = "Microsoft.NETCore.App"; diff --git a/src/BD.WTTS.Client.IPC/Services/IPCSubProcessService.cs b/src/BD.WTTS.Client.IPC/Services/IPCSubProcessService.cs index e43d7fb4f..cb9f93907 100644 --- a/src/BD.WTTS.Client.IPC/Services/IPCSubProcessService.cs +++ b/src/BD.WTTS.Client.IPC/Services/IPCSubProcessService.cs @@ -26,8 +26,8 @@ public interface IPCSubProcessService : IDisposable const int ExitCode_EmptyArrayArgs = 4001; const int ExitCode_EmptyPipeName = 4002; - const int ExitCode_EmptyProcessId = 4003; - const int ExitCode_NotFoundProcessId = 4004; + const int ExitCode_EmptyMainProcessId = 4003; + const int ExitCode_NotFoundMainProcessId = 4004; /// /// 子进程 IPC 程序启动通用函数 @@ -49,15 +49,16 @@ public interface IPCSubProcessService : IDisposable if (string.IsNullOrWhiteSpace(pipeName)) return ExitCode_EmptyPipeName; if (!int.TryParse(args[1], out var pid)) - return ExitCode_EmptyProcessId; - var process = Process.GetProcessById(pid); - if (process == null) - return ExitCode_NotFoundProcessId; + return ExitCode_EmptyMainProcessId; + var mainProcess = Process.GetProcessById(pid); + if (mainProcess == null) + return ExitCode_NotFoundMainProcessId; TaskCompletionSource tcs = new(); - process.Exited += (_, _) => + mainProcess.EnableRaisingEvents = true; + mainProcess.Exited += (_, _) => { - tcs.TrySetResult(); + tcs.TrySetResult(); // 监听主进程退出时关闭当前子进程 }; IPCSubProcessServiceImpl? ipc = null; diff --git a/src/BD.WTTS.Client/Services.Implementation/IPC/IPCMainProcessServiceImpl.cs b/src/BD.WTTS.Client/Services.Implementation/IPC/IPCMainProcessServiceImpl.cs index c82309bfe..7210dbe3f 100644 --- a/src/BD.WTTS.Client/Services.Implementation/IPC/IPCMainProcessServiceImpl.cs +++ b/src/BD.WTTS.Client/Services.Implementation/IPC/IPCMainProcessServiceImpl.cs @@ -79,8 +79,10 @@ public sealed partial class IPCMainProcessServiceImpl : IPCMainProcessService public void Run() { + var tickCount64 = Environment.TickCount64; + var pid = Environment.ProcessId; ipcProvider = new IpcProvider( - $"wtts_ipc_{_()}_{Environment.TickCount64}_{Environment.ProcessId}", + $"ipc_{_()}{tickCount64}{pid / 3}{pid % 3}", new IpcConfiguration { IpcLoggerProvider = _ => new IpcLogger_(loggerFactory, nameof(IPCMainProcessServiceImpl)), diff --git a/src/BD.WTTS.Client/Startup/Startup.Commands.cs b/src/BD.WTTS.Client/Startup/Startup.Commands.cs index 528ea2685..e0d672ff6 100644 --- a/src/BD.WTTS.Client/Startup/Startup.Commands.cs +++ b/src/BD.WTTS.Client/Startup/Startup.Commands.cs @@ -295,6 +295,26 @@ partial class Startup // 自定义控制台命令参数 }), }; rootCommand.AddCommand(shutdown); + + // -clt sudo + var sudo = new Command("sudo", "使用管理员权限启动 IPC 服务进程") + { + Handler = CommandHandler.Create(() => + { + // TODO + }), + }; + rootCommand.AddCommand(sudo); + + // -clt plugins {插件名} {插件需要解析的参数} + var plugins = new Command("plugins", "插件使用的 IPC 服务进程") + { + Handler = CommandHandler.Create(() => + { + // TODO + }), + }; + rootCommand.AddCommand(plugins); } } #endif \ No newline at end of file