diff --git a/ref/DirectoryPackages b/ref/DirectoryPackages index 97814a26b..27d1ee5a5 160000 --- a/ref/DirectoryPackages +++ b/ref/DirectoryPackages @@ -1 +1 @@ -Subproject commit 97814a26b0e4ee51e46a790c282b7613b941a706 +Subproject commit 27d1ee5a5f6b1b3f538a79cd7ee92de0c2f7a12c diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10222.11540.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10222.11540.nupkg deleted file mode 100644 index 8a49c6dc2..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10222.11540.nupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10222.11540.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10222.11540.snupkg deleted file mode 100644 index fa9ff0f43..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10222.11540.snupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10329.11240.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10329.11240.nupkg new file mode 100644 index 000000000..011472d3c Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10329.11240.nupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10329.11240.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10329.11240.snupkg new file mode 100644 index 000000000..937d4d267 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.ClientSDK.1.23.10329.11240.snupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10222.11540.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10222.11540.nupkg deleted file mode 100644 index d448260cf..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10222.11540.nupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10222.11540.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10222.11540.snupkg deleted file mode 100644 index d7a7b3d63..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10222.11540.snupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10329.11240.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10329.11240.nupkg new file mode 100644 index 000000000..379b2db8d Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10329.11240.nupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10329.11240.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10329.11240.snupkg new file mode 100644 index 000000000..176463962 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.1.23.10329.11240.snupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10222.11540.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10222.11540.nupkg deleted file mode 100644 index 6f962def2..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10222.11540.nupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10222.11540.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10222.11540.snupkg deleted file mode 100644 index 7e54824b7..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10222.11540.snupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10329.11240.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10329.11240.nupkg new file mode 100644 index 000000000..4185b10f0 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10329.11240.nupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10329.11240.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10329.11240.snupkg new file mode 100644 index 000000000..3ae61dac6 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.Resources.1.23.10329.11240.snupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10222.11540.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10222.11540.nupkg deleted file mode 100644 index 4313559c2..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10222.11540.nupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10222.11540.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10222.11540.snupkg deleted file mode 100644 index 95fe09205..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10222.11540.snupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10329.11240.nupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10329.11240.nupkg new file mode 100644 index 000000000..5e6cdc4b9 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10329.11240.nupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10329.11240.snupkg b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10329.11240.snupkg new file mode 100644 index 000000000..8756ec061 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.MicroServices.Primitives.ViewModels.1.23.10329.11240.snupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10222.11540.nupkg b/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10222.11540.nupkg deleted file mode 100644 index 18fce3ba1..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10222.11540.nupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10222.11540.snupkg b/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10222.11540.snupkg deleted file mode 100644 index aa1348da8..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10222.11540.snupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10329.11240.nupkg b/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10329.11240.nupkg new file mode 100644 index 000000000..f02e4e9ac Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10329.11240.nupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10329.11240.snupkg b/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10329.11240.snupkg new file mode 100644 index 000000000..10f6c4224 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.Primitives.1.23.10329.11240.snupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10222.11540.nupkg b/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10222.11540.nupkg deleted file mode 100644 index 5e2ce9bfb..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10222.11540.nupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10222.11540.snupkg b/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10222.11540.snupkg deleted file mode 100644 index 03ebfc3f8..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10222.11540.snupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10329.11240.nupkg b/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10329.11240.nupkg new file mode 100644 index 000000000..df2209663 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10329.11240.nupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10329.11240.snupkg b/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10329.11240.snupkg new file mode 100644 index 000000000..8fef7c401 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.Primitives.Resources.1.23.10329.11240.snupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10222.11540.nupkg b/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10222.11540.nupkg deleted file mode 100644 index 2e34b9320..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10222.11540.nupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10222.11540.snupkg b/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10222.11540.snupkg deleted file mode 100644 index 5988dc240..000000000 Binary files a/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10222.11540.snupkg and /dev/null differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10329.11240.nupkg b/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10329.11240.nupkg new file mode 100644 index 000000000..d383911a3 Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10329.11240.nupkg differ diff --git a/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10329.11240.snupkg b/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10329.11240.snupkg new file mode 100644 index 000000000..f72fb3adb Binary files /dev/null and b/ref/pkg/wtts/BD.WTTS.Primitives.ViewModels.1.23.10329.11240.snupkg differ diff --git a/src/BD.WTTS.Client.IPC/Services.Implementation/IPCServiceImpl.cs b/src/BD.WTTS.Client.IPC/Services.Implementation/IPCServiceImpl.cs index 72b06511c..68538e0b1 100644 --- a/src/BD.WTTS.Client.IPC/Services.Implementation/IPCServiceImpl.cs +++ b/src/BD.WTTS.Client.IPC/Services.Implementation/IPCServiceImpl.cs @@ -7,18 +7,21 @@ public abstract class IPCServiceImpl : IPCService, IDisposable public async ValueTask RunAsync(string? pipeName) { - if (pipeClient != null) + if (pipeClient != null) // 此函数应仅调用一次 return (int)IPCExitCode.Ok; if (string.IsNullOrWhiteSpace(pipeName)) return (int)IPCExitCode.EmptyPipeName; + // 命名管道实现 IPC pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation); try { - // 尝试在 45 秒内连接主进程 - pipeClient.Connect(TimeSpan.FromSeconds(45d)); + // https://blog.lindexi.com/post/dotnet-%E4%BD%BF%E7%94%A8-NamedPipeClientStream-%E8%BF%9E%E6%8E%A5%E4%B8%80%E4%B8%AA%E4%B8%8D%E5%AD%98%E5%9C%A8%E7%AE%A1%E9%81%93%E6%9C%8D%E5%8A%A1%E5%90%8D%E5%B0%86%E4%B8%8D%E6%96%AD%E7%A9%BA%E8%B7%91-CPU-%E8%B5%84%E6%BA%90.html + // 尝试在 15 秒内连接主进程 + const int timeout_connect = 15000; + await pipeClient.ConnectAsync(timeout_connect); } catch (TimeoutException) { @@ -27,7 +30,7 @@ public abstract class IPCServiceImpl : IPCService, IDisposable while (!disposedValue) { - var packet = ReadBytes(pipeClient); + var packet = Read(pipeClient); if (packet != default) { var exitCode = await HandleCommand(packet); @@ -46,14 +49,45 @@ public abstract class IPCServiceImpl : IPCService, IDisposable Write(pipeClient, packet); } + /// + /// 处理数据包 + /// + /// + /// protected virtual ValueTask HandleCommand(TPacket packet) { return default; } - protected abstract TPacket? ReadBytes(Stream stream); + /// + /// 从流中读取一个数据包 + /// + /// + /// + protected virtual TPacket? Read(Stream stream) + { + Span inBuffer = stackalloc byte[sizeof(int)]; + stream.Read(inBuffer); + var len = BitConverter.ToInt32(inBuffer); + if (len <= 0) return default; + inBuffer = stackalloc byte[len]; + stream.Read(inBuffer); + var obj = MemoryPackSerializer.Deserialize(inBuffer); + return obj; + } - protected abstract void Write(Stream stream, TPacket packet); + /// + /// 将一个数据包写入流中 + /// + /// + /// + protected virtual void Write(Stream stream, TPacket packet) + { + byte[] outBuffer = MemoryPackSerializer.Serialize(packet); + stream.Write(BitConverter.GetBytes(outBuffer.Length)); + stream.Write(outBuffer); + stream.Flush(); + } void Dispose(bool disposing) { diff --git a/src/BD.WTTS.Client.IPC/Services/IPCService.cs b/src/BD.WTTS.Client.IPC/Services/IPCService.cs index e0caec43e..0fd64cee7 100644 --- a/src/BD.WTTS.Client.IPC/Services/IPCService.cs +++ b/src/BD.WTTS.Client.IPC/Services/IPCService.cs @@ -1,6 +1,6 @@ namespace BD.WTTS.Services; -public interface IPCService where TPacket : class +public interface IPCService : IDisposable where TPacket : class { /// /// 启动 IPC 服务 diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Enums/ReverseProxyCommand.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Enums/ReverseProxyCommand.cs index 4c04d84d5..58ae2cb37 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Enums/ReverseProxyCommand.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Enums/ReverseProxyCommand.cs @@ -24,4 +24,19 @@ public enum ReverseProxyCommand : byte /// 获取当前流量统计 /// GetFlowStatistics, + + /// + /// 调用 UI 进程通知显示 DNS 错误 + /// + NotifyDNSError, + + /// + /// 热重载配置文件 + /// + HotReloadConfig, + + /// + /// 启动反向代理控制台结果 + /// + StartResult, } diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Models/IReverseProxyPacket.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Models/IReverseProxyPacket.cs index 328b83f02..41bb96a2e 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Models/IReverseProxyPacket.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Models/IReverseProxyPacket.cs @@ -8,36 +8,8 @@ namespace BD.WTTS.Models; [MemoryPackUnion(1, typeof(FlowStatistics))] public partial interface IReverseProxyPacket { - /// - /// 从流中读取一个 - /// - /// - /// - static IReverseProxyPacket? ReadBytes(Stream stream) - { - Span inBuffer = stackalloc byte[sizeof(int)]; - stream.Read(inBuffer); - var len = BitConverter.ToInt32(inBuffer); - if (len <= 0) return default; - inBuffer = stackalloc byte[len]; - stream.Read(inBuffer); - var obj = MemoryPackSerializer.Deserialize(inBuffer); - return obj; - } - /// - /// 将一个 写入流中 - /// - /// - /// - static void Write(Stream stream, IReverseProxyPacket packet) - { - byte[] outBuffer = MemoryPackSerializer.Serialize(packet); - stream.Write(BitConverter.GetBytes(outBuffer.Length)); - stream.Write(outBuffer); - stream.Flush(); - } } [MemoryPackable] -public sealed partial record ReverseProxyPacket(ReverseProxyCommand Command) : IReverseProxyPacket { } \ No newline at end of file +public sealed partial record ReverseProxyPacket(ReverseProxyCommand Command, string? Data) : IReverseProxyPacket { } \ No newline at end of file diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Program.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Program.cs index d7a60d623..b70874e1c 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Program.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Program.cs @@ -1,49 +1,24 @@ -if (!args.Any()) return (int)ExitCode.EmptyArrayArgs; +using Microsoft.Extensions.DependencyInjection; + +if (!args.Any()) + return (int)IPCExitCode.EmptyArrayArgs; var pipeName = args[0]; -if (string.IsNullOrWhiteSpace(pipeName)) return (int)ExitCode.EmptyPipeName; +if (string.IsNullOrWhiteSpace(pipeName)) + return (int)IPCExitCode.EmptyPipeName; -using var pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation); +Ioc.ConfigureServices(ConfigureServices); -try +static void ConfigureServices(IServiceCollection services) { - // 尝试在 45 秒内连接主进程 - pipeClient.Connect(TimeSpan.FromSeconds(45d)); -} -catch (TimeoutException) -{ - return (int)ExitCode.ConnectServerTimeout; -} - -while (true) -{ - var packet = IReverseProxyPacket.ReadBytes(pipeClient); - if (packet != default) + services.AddLogging(l => { - if (packet is ReverseProxyPacket packet1) - { - switch (packet1.Command) - { - case ReverseProxyCommand.Exit: - goto exit; - case ReverseProxyCommand.GetFlowStatistics: - FlowStatistics flowStatistics = null!; - IReverseProxyPacket.Write(pipeClient, flowStatistics); - break; - case ReverseProxyCommand.Start: - break; - case ReverseProxyCommand.Stop: - break; - } - } - } + l.AddConsole(); + }); + + services.AddReverseProxyService(); + services.AddSingleton(); } -exit: return (int)ExitCode.Ok; - -enum ExitCode -{ - Ok = 0, - EmptyArrayArgs = 4001, - EmptyPipeName, - ConnectServerTimeout, -} \ No newline at end of file +using var ipc = IPCService.Instance; +var exitCode = await ipc.RunAsync(pipeName); +return exitCode; \ No newline at end of file diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/DomainResolver.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/DomainResolver.cs index d372bca8c..ea7758f65 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/DomainResolver.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/DomainResolver.cs @@ -9,11 +9,13 @@ namespace BD.WTTS.Services.Implementation; sealed class DomainResolver : IDomainResolver { readonly IReverseProxyConfig reverseProxyConfig; + readonly IPCService ipc; bool isIpv6 = false; - public DomainResolver(IReverseProxyConfig reverseProxyConfig) + public DomainResolver(IPCService ipc, IReverseProxyConfig reverseProxyConfig) { + this.ipc = ipc; this.reverseProxyConfig = reverseProxyConfig; } @@ -34,7 +36,7 @@ sealed class DomainResolver : IDomainResolver } catch (Exception ex) { - IPCService.Instance.NotifyDNSError(ex); + ipc.Send(ReverseProxyCommand.NotifyDNSError, ex.Message); //INotificationService.Instance.Notify(AppResources.CommunityFix_DNSErrorNotify + Environment.NewLine + "Exception Message :" + ex.Message, NotificationType.Message); throw; } diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/IPCServiceImpl.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/IPCServiceImpl.cs index 4e4a8fdfb..089139320 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/IPCServiceImpl.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/IPCServiceImpl.cs @@ -2,21 +2,31 @@ namespace BD.WTTS.Services.Implementation; sealed class IPCServiceImpl : IPCServiceImpl, IPCService { - protected override ValueTask HandleCommand(IReverseProxyPacket packet) + public IPCServiceImpl() + { + // 保持无依赖注入的空构造函数 + } + + protected override async ValueTask HandleCommand(IReverseProxyPacket packet) { if (packet is ReverseProxyPacket packet1) { switch (packet1.Command) { case ReverseProxyCommand.Exit: - return new ValueTask((int)IPCExitCode.Ok); + return (int)IPCExitCode.Ok; case ReverseProxyCommand.GetFlowStatistics: FlowStatistics flowStatistics = null!; Send(flowStatistics); break; case ReverseProxyCommand.Start: + var startResult = await IReverseProxyService.Instance.StartProxyAsync(); + Send(ReverseProxyCommand.StartResult, startResult ? null : "Startup failed."); break; case ReverseProxyCommand.Stop: + await IReverseProxyService.Instance.StopProxyAsync(); + break; + case ReverseProxyCommand.HotReloadConfig: break; } } @@ -24,18 +34,9 @@ sealed class IPCServiceImpl : IPCServiceImpl, IPCService return default; } - public void NotifyDNSError(Exception ex) + public void Send(ReverseProxyCommand command, string? data = null) { - - } - - protected override IReverseProxyPacket? ReadBytes(Stream stream) - { - return IReverseProxyPacket.ReadBytes(stream); - } - - protected override void Write(Stream stream, IReverseProxyPacket packet) - { - IReverseProxyPacket.Write(stream, packet); + ReverseProxyPacket packet = new(command, data); + Send(packet); } } diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs index b853d67f1..6d9e380bb 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.Startup.cs @@ -28,6 +28,7 @@ partial class YarpReverseProxyServiceImpl services.AddPacketIntercept(); } #endif + services.AddSingleton(_ => ipc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs index 20c9b6639..f50bb10e7 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/YarpReverseProxyServiceImpl.cs @@ -11,11 +11,14 @@ sealed partial class YarpReverseProxyServiceImpl : ReverseProxyServiceImpl, IRev static readonly string RootPath = Path.Combine(IOPath.AppDataDirectory, "Yarp"); WebApplication? app; + readonly IPCService ipc; public YarpReverseProxyServiceImpl( + IPCService ipc, IDnsAnalysisService dnsAnalysis, ICertificateManager certificateManager) : base(dnsAnalysis) { + this.ipc = ipc; CertificateManager = certificateManager; } diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services/IPCService.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services/IPCService.cs index acaa896d3..aa3a826d5 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services/IPCService.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services/IPCService.cs @@ -4,5 +4,10 @@ public interface IPCService : IPCService { static IPCService Instance => Ioc.Get(); - void NotifyDNSError(Exception ex); + /// + /// 给主进程发送指令以及可选的附加消息 + /// + /// + /// + void Send(ReverseProxyCommand command, string? data = null); } diff --git a/src/BD.WTTS.Client/Models/Abstractions/IOperationResult.cs b/src/BD.WTTS.Client/Models/Abstractions/IOperationResult.cs new file mode 100644 index 000000000..f39e0a654 --- /dev/null +++ b/src/BD.WTTS.Client/Models/Abstractions/IOperationResult.cs @@ -0,0 +1,123 @@ +namespace BD.WTTS.Models.Abstractions; + +/// +/// 操作结果信息类,对操作结果进行封装 +/// +public interface IOperationResult +{ + /// + /// 获取或设置 操作结果类型 + /// + OperationResultType ResultType { get; set; } + + /// + /// 获取或设置 操作返回信息 + /// + string Message { get; set; } + + /// + /// 获取或设置 操作返回的日志消息,用于记录日志 + /// + string LogMessage { get; set; } +} + +/// +public interface IOperationResult : IOperationResult +{ + /// + /// 获取或设置 操作结果附加信息 + /// + T AppendData { get; set; } +} + +/// +public abstract class OperationResultBase : IOperationResult +{ + #region 构造函数 + + public OperationResultBase() + { + ResultType = OperationResultType.Error; + } + + /// + /// 初始化一个 操作结果信息类 的新实例 + /// + /// 操作结果类型 + public OperationResultBase(OperationResultType resultType) + { + ResultType = resultType; + } + + /// + /// 初始化一个 定义返回消息的操作结果信息类 的新实例 + /// + /// 操作结果类型 + /// 返回消息 + public OperationResultBase(OperationResultType resultType, string message) + : this(resultType) + { + Message = message; + } + + /// + /// 初始化一个 定义返回消息与附加数据的操作结果信息类 的新实例 + /// + /// 操作结果类型 + /// 返回消息 + /// 返回数据 + public OperationResultBase(OperationResultType resultType, string message, T? appendData) + : this(resultType, message) + { + _AppendData = appendData; + } + + /// + /// 初始化一个 定义返回消息与日志消息的操作结果信息类 的新实例 + /// + /// 操作结果类型 + /// 返回消息 + /// 日志记录消息 + public OperationResultBase(OperationResultType resultType, string message, string logMessage) + : this(resultType, message) + { + LogMessage = logMessage; + } + + /// + /// 初始化一个 定义返回消息、日志消息与附加数据的操作结果信息类 的新实例 + /// + /// 操作结果类型 + /// 返回消息 + /// 日志记录消息 + /// 返回数据 + public OperationResultBase(OperationResultType resultType, string message, string logMessage, T? appendData) + : this(resultType, message, logMessage) + { + _AppendData = appendData; + } + + #endregion + + #region 属性 + + public OperationResultType ResultType { get; set; } + + public string Message { get; set; } = string.Empty; + + public string LogMessage { get; set; } = string.Empty; + + protected T? _AppendData; + + public virtual T AppendData + { + get + { + _AppendData ??= Activator.CreateInstance(); + return _AppendData; + } + set => _AppendData = value; + } + + #endregion +} \ No newline at end of file diff --git a/src/BD.WTTS.Client/Models/OperationResult.cs b/src/BD.WTTS.Client/Models/OperationResult.cs index 578420b50..e7ad53c56 100644 --- a/src/BD.WTTS.Client/Models/OperationResult.cs +++ b/src/BD.WTTS.Client/Models/OperationResult.cs @@ -1,127 +1,5 @@ namespace BD.WTTS.Models; -/// -/// 操作结果信息类,对操作结果进行封装 -/// -public interface IOperationResult -{ - /// - /// 获取或设置 操作结果类型 - /// - OperationResultType ResultType { get; set; } - - /// - /// 获取或设置 操作返回信息 - /// - string Message { get; set; } - - /// - /// 获取或设置 操作返回的日志消息,用于记录日志 - /// - string LogMessage { get; set; } -} - -/// -public interface IOperationResult : IOperationResult -{ - /// - /// 获取或设置 操作结果附加信息 - /// - T AppendData { get; set; } -} - -/// -public abstract class OperationResultBase : IOperationResult -{ - #region 构造函数 - - public OperationResultBase() - { - ResultType = OperationResultType.Error; - } - - /// - /// 初始化一个 操作结果信息类 的新实例 - /// - /// 操作结果类型 - public OperationResultBase(OperationResultType resultType) - { - ResultType = resultType; - } - - /// - /// 初始化一个 定义返回消息的操作结果信息类 的新实例 - /// - /// 操作结果类型 - /// 返回消息 - public OperationResultBase(OperationResultType resultType, string message) - : this(resultType) - { - Message = message; - } - - /// - /// 初始化一个 定义返回消息与附加数据的操作结果信息类 的新实例 - /// - /// 操作结果类型 - /// 返回消息 - /// 返回数据 - public OperationResultBase(OperationResultType resultType, string message, T? appendData) - : this(resultType, message) - { - _AppendData = appendData; - } - - /// - /// 初始化一个 定义返回消息与日志消息的操作结果信息类 的新实例 - /// - /// 操作结果类型 - /// 返回消息 - /// 日志记录消息 - public OperationResultBase(OperationResultType resultType, string message, string logMessage) - : this(resultType, message) - { - LogMessage = logMessage; - } - - /// - /// 初始化一个 定义返回消息、日志消息与附加数据的操作结果信息类 的新实例 - /// - /// 操作结果类型 - /// 返回消息 - /// 日志记录消息 - /// 返回数据 - public OperationResultBase(OperationResultType resultType, string message, string logMessage, T? appendData) - : this(resultType, message, logMessage) - { - _AppendData = appendData; - } - - #endregion - - #region 属性 - - public OperationResultType ResultType { get; set; } - - public string Message { get; set; } = string.Empty; - - public string LogMessage { get; set; } = string.Empty; - - protected T? _AppendData; - - public virtual T AppendData - { - get - { - _AppendData ??= Activator.CreateInstance(); - return _AppendData; - } - set => _AppendData = value; - } - - #endregion -} - /// public class OperationResult : OperationResultBase { diff --git a/src/BD.WTTS.Client/Properties/AssemblyInfo.Xaml.cs b/src/BD.WTTS.Client/Properties/AssemblyInfo.Xaml.cs new file mode 100644 index 000000000..6c449e737 --- /dev/null +++ b/src/BD.WTTS.Client/Properties/AssemblyInfo.Xaml.cs @@ -0,0 +1,10 @@ +#if (WINDOWS || MACCATALYST || MACOS || LINUX) && !(IOS || ANDROID) +using XmlnsDefinition = Avalonia.Metadata.XmlnsDefinitionAttribute; + +// steampp +[assembly: XmlnsDefinition("https://steampp.net/ui", "BD.WTTS.Models")] +[assembly: XmlnsDefinition("https://steampp.net/ui", "BD.WTTS.Models.Abstractions")] +[assembly: XmlnsDefinition("https://steampp.net/ui", "BD.WTTS.UI.ViewModels")] +[assembly: XmlnsDefinition("https://steampp.net/ui", "BD.WTTS.UI.ViewModels.Abstractions")] + +#endif \ No newline at end of file