using AxiOmron.PcbCheck.Options; using AxiOmron.PcbCheck.Services.Interfaces; namespace AxiOmron.PcbCheck.DesignTime; /// /// 提供设计时配置服务,返回固定的示例配置数据。 /// public sealed class DesignTimeAppConfigService : IAppConfigService { private readonly AppConfig _config; /// /// 初始化设计时配置服务。 /// public DesignTimeAppConfigService() { _config = CreateSampleConfig(); } /// /// 读取设计时配置副本。 /// /// 示例根配置对象。 public AppConfig Load() { return CreateSampleConfig(); } /// /// 保存设计时配置,占位实现,仅更新内存中的副本。 /// /// 待保存的配置对象。 /// 时抛出。 public void Save(AppConfig config) { ArgumentNullException.ThrowIfNull(config); _config.Plc = config.Plc; _config.Scanner = config.Scanner; _config.Sftp = config.Sftp; _config.Andon = config.Andon; _config.Workflow = config.Workflow; } /// /// 获取设计时展示用的示例配置路径。 /// /// 固定的设计时配置路径文本。 public string GetConfigPath() { return @"D:\DesignTime\appConfig.Development.json"; } /// /// 创建设计器使用的示例配置对象。 /// /// 填充默认值后的配置对象。 private static AppConfig CreateSampleConfig() { return new AppConfig { Plc = new PlcOptions { Host = "192.168.10.25", Port = 502, UnitId = 1, PollIntervalMs = 200, ConnectTimeoutMs = 3000, HeartbeatIntervalMs = 500, ReleasePulseMs = 450, ReleaseAckTimeoutMs = 2500 }, Scanner = new ScannerOptions { PortName = "COM3", BaudRate = 9600, DataBits = 8, Parity = "None", StopBits = "One", ReadTimeoutMs = 2500, TriggerCommand = "SCAN\\r", ResponseTerminator = "\\r", MaxScanAttempts = 3 }, Sftp = new SftpOptions { Host = "10.10.20.35", Port = 22, Username = "pcb_user", Password = "******", PrivateKeyPath = @"C:\Keys\pcb-check.ppk", RootPath = "/data/pcb", FileNamePattern = "${barcode}.txt", RetryIntervalSeconds = 2, MaxRetryCount = 3, ConnectTimeoutMs = 3000 }, Andon = new AndonOptions { Enable = true, Url = "http://10.10.20.50/api/andon/alarm", Method = "POST", TimeoutMs = 3000, StationCode = "OMRON-L01", StationName = "欧姆龙 PCB 检测", EnableScanFailAlarm = true, EnableFileNotFoundAlarm = true }, Workflow = new WorkflowOptions { RequirePlcReady = true, RequireAutoMode = true, RequireStationEnable = true, RequireManualResetAfterFault = true, MaxUiLogEntries = 200, MaxBoardRecords = 100 } }; } }