| | |
| | | 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); |
| | |
| | | |
| | | // 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; |
| | |
| | | |
| | | // å¯å¨æ¶å 载已ä¿åçå®ä¾ï¼ä¸èªå¨å¯å¨ï¼ |
| | | 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}"); |
| | | } |
| | | }); |
| | | |