| | |
| | | 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); |
| | | |
| | |
| | | { |
| | | 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() |
| | | 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(); |
| | |
| | | |
| | | 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(); |