From 689dd676fc0efb31236d989334122590b7198d61 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 16 三月 2026 09:30:11 +0800
Subject: [PATCH] 1
---
Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs | 33 +++++++++++++++++++++++++++------
1 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs
index a006237..696008f 100644
--- a/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs
+++ b/Code/WCS/WIDESEAWCS_S7Simulator/WIDESEAWCS_S7Simulator.Server/Program.cs
@@ -3,6 +3,7 @@
using WIDESEAWCS_S7Simulator.Core.Persistence;
using WIDESEAWCS_S7Simulator.Core.Memory;
using WIDESEAWCS_S7Simulator.Core.Entities;
+using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
@@ -13,18 +14,23 @@
{
options.AddPolicy("AllowAll", policy =>
{
- policy.AllowAnyOrigin()
+ policy.WithOrigins("http://localhost:3000", "http://localhost:5173", "http://localhost:5174", "http://localhost:3001")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
-builder.Services.AddControllers()
- .AddJsonOptions(options =>
- {
- options.JsonSerializerOptions.PropertyNamingPolicy = System.Text.Json.JsonNamingPolicy.CamelCase;
- });
+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();
@@ -60,4 +66,19 @@
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