From 2ef99428f9be29ec299029782edb97baef88e126 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 18 三月 2026 14:19:20 +0800
Subject: [PATCH] feat: 完成WCS/WMS任务链路与设备调度改造
---
Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs | 70 ++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 1 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs
index 48863a6..7ca0d53 100644
--- a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs
+++ b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs
@@ -1,11 +1,62 @@
+using WIDESEAWCS_S7Simulator.Core.Interfaces;
+using WIDESEAWCS_S7Simulator.Core.Manager;
+using WIDESEAWCS_S7Simulator.Core.Persistence;
+using WIDESEAWCS_S7Simulator.Core.Memory;
+using WIDESEAWCS_S7Simulator.Core.Entities;
+using System.Text.Json.Serialization;
+using WIDESEAWCS_S7Simulator.Application.Protocol;
+using WIDESEAWCS_S7Simulator.Server.Services;
+
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
-builder.Services.AddControllers();
+// 娣诲姞 CORS 鏀寔锛堝厑璁稿墠鍚庣鍒嗙锛�
+builder.Services.AddCors(options =>
+{
+ options.AddPolicy("AllowAll", policy =>
+ {
+ policy.WithOrigins("http://localhost:3000", "http://localhost:5173", "http://localhost:5174", "http://localhost:3001")
+ .AllowAnyMethod()
+ .AllowAnyHeader()
+ .AllowCredentials();
+ });
+});
+
+builder.Services.AddControllers(options =>
+{
+ // 绂佺敤闅愬紡 [Required] 楠岃瘉
+ options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true;
+})
+.AddJsonOptions(options =>
+{
+ options.JsonSerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
+ options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
+});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
+
+// Register core services
+builder.Services.AddSingleton<ISimulatorInstanceManager, SimulatorInstanceManager>();
+
+// Get content root path for data directory
+var contentRoot = builder.Environment.ContentRootPath;
+var dataPath = Path.Combine(contentRoot, "Data");
+
+builder.Services.AddSingleton<IPersistenceService>(sp => new FilePersistenceService(dataPath));
+builder.Services.AddSingleton<IProtocolTemplateService>(sp => new FileProtocolTemplateService(dataPath));
+builder.Services.Configure<ProtocolMonitoringOptions>(builder.Configuration.GetSection("ProtocolMonitoring"));
+builder.Services.AddSingleton<MirrorAckProtocolHandler>();
+builder.Services.AddSingleton<IDeviceProtocolHandler, WcsLineProtocolHandler>();
+builder.Services.AddSingleton<IDeviceProtocolHandler, PlcLinkStackerProtocolHandler>();
+builder.Services.AddSingleton<IDeviceProtocolHandler, StackerInteractionProtocolHandler>();
+builder.Services.AddHostedService<ProtocolMonitoringHostedService>();
+builder.Services.AddSingleton<IMemoryStore>(sp =>
+{
+ var config = new MemoryRegionConfig();
+ return new MemoryStore(config);
+});
var app = builder.Build();
@@ -18,8 +69,25 @@
app.UseHttpsRedirection();
+app.UseCors("AllowAll"); // 鍚敤 CORS
+
app.UseAuthorization();
app.MapControllers();
+// 鍚姩鏃跺姞杞藉凡淇濆瓨鐨勫疄渚嬶紙涓嶈嚜鍔ㄥ惎鍔級
+var instanceManager = app.Services.GetRequiredService<ISimulatorInstanceManager>();
+_ = Task.Run(async () =>
+{
+ try
+ {
+ await instanceManager.LoadSavedInstancesAsync(autoStart: false);
+ Console.WriteLine($"Loaded {instanceManager.GetAllInstances().Count()} saved instances.");
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Error loading saved instances: {ex.Message}");
+ }
+});
+
app.Run();
--
Gitblit v1.9.3