diff --git a/XP.Scan/Models/ReconstructionMode.cs b/XP.Scan/Models/ReconstructionMode.cs new file mode 100644 index 0000000..459d760 --- /dev/null +++ b/XP.Scan/Models/ReconstructionMode.cs @@ -0,0 +1,14 @@ +namespace XP.Scan.Models +{ + /// + /// CT 重建模式 | CT Reconstruction Mode + /// + public enum ReconstructionMode + { + /// 平面CT重建 | Planar CT reconstruction + Planar = 2001, + + /// 立式CT重建 | Vertical CT reconstruction + Vertical = 2002 + } +} diff --git a/XP.Scan/Services/IReconstructionNotifyService.cs b/XP.Scan/Services/IReconstructionNotifyService.cs new file mode 100644 index 0000000..3daeaed --- /dev/null +++ b/XP.Scan/Services/IReconstructionNotifyService.cs @@ -0,0 +1,15 @@ +namespace XP.Scan.Services +{ + /// + /// 重建通知服务接口 | Reconstruction notification service interface + /// 负责通过 Socket 通知本地重建软件启动重建任务 + /// + public interface IReconstructionNotifyService + { + /// + /// 发送重建通知消息 + /// + /// 扫描配置文件路径 + void SendReconstructionNotify(string configPath); + } +} diff --git a/XP.Scan/Services/ReconstructionNotifyService.cs b/XP.Scan/Services/ReconstructionNotifyService.cs new file mode 100644 index 0000000..87b4720 --- /dev/null +++ b/XP.Scan/Services/ReconstructionNotifyService.cs @@ -0,0 +1,72 @@ +using System; +using System.Net; +using System.Net.Sockets; +using System.Text; +using XP.Common.Logging.Interfaces; +using XP.Scan.Models; + +namespace XP.Scan.Services +{ + /// + /// 重建通知服务 | Reconstruction notification service + /// 通过 TCP Socket 向本地重建软件发送配置路径 + 重建模式码 + /// + public class ReconstructionNotifyService : IReconstructionNotifyService + { + private readonly ILoggerService _logger; + private readonly string _host; + private readonly int _port; + private readonly ReconstructionMode _mode; + + /// + /// 构造函数 + /// + /// 日志服务 + /// 重建软件 IP 地址(本机默认 127.0.0.1) + /// 重建软件监听端口 + /// CT 重建模式(Planar=2001, Vertical=2002) + public ReconstructionNotifyService( + ILoggerService loggerService, + string host = "127.0.0.1", + int port = 11000, + ReconstructionMode mode = ReconstructionMode.Planar) + { + _logger = loggerService.ForModule(); + _host = host; + _port = port; + _mode = mode; + } + + /// + /// 发送重建通知消息 + /// 消息格式: configPath + 模式码(2001=平面CT, 2002=立式CT) + /// + /// 扫描配置文件路径 + public void SendReconstructionNotify(string configPath) + { + try + { + using var sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + var ipAddress = IPAddress.Parse(_host); + var remoteEP = new IPEndPoint(ipAddress, _port); + + sender.Connect(remoteEP); + + // 拼接消息: 配置路径 + 重建模式码 + string message = configPath + ((int)_mode).ToString(); + byte[] msg = Encoding.UTF8.GetBytes(message); + sender.Send(msg); + + _logger.Info($"重建通知已发送 | Reconstruction notify sent: {message}"); + } + catch (SocketException ex) + { + _logger.Error($"重建通知发送失败(Socket) | Reconstruction notify failed: {ex.Message}"); + } + catch (Exception ex) + { + _logger.Error($"重建通知发送异常 | Reconstruction notify error: {ex.Message}"); + } + } + } +} diff --git a/XplorePlane/App.config b/XplorePlane/App.config index 9825512..e6d2dab 100644 --- a/XplorePlane/App.config +++ b/XplorePlane/App.config @@ -175,6 +175,14 @@ + + + + + + + +