diff --git a/MasstransferCommon/MasstransferCommon.csproj b/MasstransferCommon/MasstransferCommon.csproj index 6d2c11b..a9ad36d 100644 --- a/MasstransferCommon/MasstransferCommon.csproj +++ b/MasstransferCommon/MasstransferCommon.csproj @@ -40,8 +40,4 @@ - - - - diff --git a/MasstransferCommon/Model/Constant/Constants.cs b/MasstransferCommon/Model/Constant/Constants.cs index 1b62255..14b036a 100644 --- a/MasstransferCommon/Model/Constant/Constants.cs +++ b/MasstransferCommon/Model/Constant/Constants.cs @@ -2,5 +2,5 @@ public class Constants { - public const string SN = "5506771257"; + public const string SN = "G5506771257"; } \ No newline at end of file diff --git a/MasstransferExporter/Program.cs b/MasstransferExporter/Program.cs index 718d141..2754122 100644 --- a/MasstransferExporter/Program.cs +++ b/MasstransferExporter/Program.cs @@ -1,6 +1,9 @@ -using MasstransferCommon.Model.Constant; +using MasstransferCommon.Events; +using MasstransferCommon.Model.Entity; +using MasstransferCommunicate.Mqtt.Client; using MasstransferCommunicate.Process.Client; using MasstransferInfrastructure.Database.Sqlite; +using MasstransferInfrastructure.Mqtt.Model; namespace MasstransferExporter; @@ -10,31 +13,25 @@ class Program public static async Task Main() { - // var mqttParams = Db.Query("select * from mqtt_params").FirstOrDefault(); - // - // // 启动mqtt连接 - // await MessageQueueHelper.InitConnect(new MqttConnectOptions() - // { - // ServerAddress = mqttParams.ServerAddress, - // Port = mqttParams.Port, - // UserName = mqttParams.UserName, - // Password = mqttParams.Password - // }); - // - // // 启动与主程序的通信 - // await ProcessCommunicator.Connect(); - // - // // 启动完成后,广播启动通知 - // EventBus.Publish(EventType.StartUp, true);rewrwe + var mqttParams = Db.Query("select * from mqtt_params").FirstOrDefault(); + // 启动mqtt连接 + await MessageQueueHelper.InitConnect(new MqttConnectOptions() + { + ServerAddress = mqttParams.ServerAddress, + Port = mqttParams.Port, + UserName = mqttParams.UserName, + Password = mqttParams.Password + }); + + // 启动与主程序的通信 ProcessHelper.Init(); - while (Console.ReadLine() is { } input) - { - ProcessHelper.Send(ProcessTopics.TestEvent, input); - } + // 启动完成后,广播启动通知 + EventBus.Publish(EventType.StartUp, true); - // Console.WriteLine("按任意键退出"); - // Console.ReadKey(); + + Console.WriteLine("按任意键退出"); + Console.ReadKey(); } } \ No newline at end of file diff --git a/MasstransferInfrastructure/MasstransferInfrastructure.csproj b/MasstransferInfrastructure/MasstransferInfrastructure.csproj index 52f38e2..83d60ab 100644 --- a/MasstransferInfrastructure/MasstransferInfrastructure.csproj +++ b/MasstransferInfrastructure/MasstransferInfrastructure.csproj @@ -10,7 +10,6 @@ - diff --git a/MasstransferInfrastructure/Process/Client/PipeClient.cs b/MasstransferInfrastructure/Process/Client/PipeClient.cs index bafaf25..d320e52 100644 --- a/MasstransferInfrastructure/Process/Client/PipeClient.cs +++ b/MasstransferInfrastructure/Process/Client/PipeClient.cs @@ -1,11 +1,14 @@ using System.IO.Pipes; +using MasstransferCommon.Utils; namespace MasstransferCommunicate.Process.Client; -internal class PipeClient(string pipeName) +internal class PipeClient { private NamedPipeClientStream? _pipeClient; + private const string KeyPath = @"Software\Masstransfer\Security"; + public event Action MessageReceived; /// @@ -25,7 +28,17 @@ internal class PipeClient(string pipeName) { try { - _pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous); + Console.WriteLine("正在查找服务端管道id"); + var pipeName = RegistryHelper.ReadValue(KeyPath, "PipeId"); + if (pipeName == null) + { + Console.WriteLine("无法找到服务端管道id,等待重试"); + Thread.Sleep(1000); + continue; + } + + _pipeClient = new NamedPipeClientStream(".", (string)pipeName, PipeDirection.InOut, + PipeOptions.Asynchronous); Console.WriteLine("正在连接服务器"); _pipeClient.Connect(5000); diff --git a/MasstransferInfrastructure/Process/Client/ProcessHelper.cs b/MasstransferInfrastructure/Process/Client/ProcessHelper.cs index c3eba24..dbd0cee 100644 --- a/MasstransferInfrastructure/Process/Client/ProcessHelper.cs +++ b/MasstransferInfrastructure/Process/Client/ProcessHelper.cs @@ -20,7 +20,7 @@ public class ProcessHelper public static void Init() { if (_pipe != null) return; - _pipe = new PipeClient("MasstransferPipe"); + _pipe = new PipeClient(); _pipe.Start(); }