From 559bb7b4be83575cc5fedee98484647243c96f89 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 08 四月 2026 15:57:44 +0800
Subject: [PATCH] feat: 空托盘出库完整流程 + 输送线调度优化 + S7Simulator 协议同步增强

---
 Code/测试工具/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git "a/Code/\346\265\213\350\257\225\345\267\245\345\205\267/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs" "b/Code/\346\265\213\350\257\225\345\267\245\345\205\267/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs"
index 18b602a..05314b1 100644
--- "a/Code/\346\265\213\350\257\225\345\267\245\345\205\267/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs"
+++ "b/Code/\346\265\213\350\257\225\345\267\245\345\205\267/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs"
@@ -5,6 +5,8 @@
 using WIDESEAWCS_S7Simulator.Core.Entities;
 using System.Text.Json.Serialization;
 using WIDESEAWCS_S7Simulator.Application.Protocol;
+using WIDESEAWCS_S7Simulator.Application;
+using Microsoft.Extensions.Options;
 using WIDESEAWCS_S7Simulator.Server.Services;
 
 var builder = WebApplication.CreateBuilder(args);
@@ -39,6 +41,11 @@
 
 // Register core services
 builder.Services.AddSingleton<ISimulatorInstanceManager, SimulatorInstanceManager>();
+
+// WCS 鏁版嵁搴撻厤缃�
+builder.Services.Configure<WcsDbOptions>(builder.Configuration.GetSection(WcsDbOptions.SectionName));
+builder.Services.AddSingleton<DatabaseDeviceService>();
+builder.Services.AddSingleton<InstanceSyncService>();
 
 // Get content root path for data directory
 var contentRoot = builder.Environment.ContentRootPath;
@@ -78,16 +85,26 @@
 
 // 鍚姩鏃跺姞杞藉凡淇濆瓨鐨勫疄渚嬶紙涓嶈嚜鍔ㄥ惎鍔級
 var instanceManager = app.Services.GetRequiredService<ISimulatorInstanceManager>();
+var syncService = app.Services.GetRequiredService<InstanceSyncService>();
 _ = Task.Run(async () =>
 {
     try
     {
+        // 鍏堝姞杞藉凡淇濆瓨鐨勫疄渚�
         await instanceManager.LoadSavedInstancesAsync(autoStart: false);
         Console.WriteLine($"Loaded {instanceManager.GetAllInstances().Count()} saved instances.");
+
+        // 濡傛灉鍚敤浜� WCS 鏁版嵁搴撳悓姝ワ紝鍒欐墽琛屽悓姝�
+        var wcsDbOptions = app.Services.GetRequiredService<IOptions<WcsDbOptions>>().Value;
+        if (wcsDbOptions.Enabled)
+        {
+            await syncService.SyncInstancesAsync();
+            Console.WriteLine($"WCS DB sync completed. Last sync: {syncService.LastSyncTime}");
+        }
     }
     catch (Exception ex)
     {
-        Console.WriteLine($"Error loading saved instances: {ex.Message}");
+        Console.WriteLine($"Error during startup: {ex.Message}");
     }
 });
 

--
Gitblit v1.9.3