Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Models/SimulateConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public partial class SimulateConfigModel : ObservableObject
[ObservableProperty] private string _appSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6";
[ObservableProperty] private string _productId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a";
[ObservableProperty] private string _outputDirectory = string.Empty;
[ObservableProperty] private bool _autoRun = true;
public int ServerPort { get; set; } = 5000;
}
4 changes: 4 additions & 0 deletions src/Services/LocalizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public string this[string key]
["Sim.SelectOutput"] = "选择模拟输出目录",
["Sim.ValidateDirs"] = "请填写所有必填项",
["Sim.DotnetCheck"] = "需要 .NET 10.0 SDK,请先安装",
["Sim.AutoRun"] = "自动启动服务器并运行客户端",
["Sim.ManualMode"] = "服务器/客户端已生成,可手动运行:\ndotnet script client.csx",
["Sim.Starting"] = "正在启动模拟...",
["Sim.Completed"] = "模拟完成 ({0:F1}s)",
["Sim.Failed"] = "模拟失败: {0}",
Expand Down Expand Up @@ -233,6 +235,8 @@ public string this[string key]
["Sim.SelectOutput"] = "Select simulation output directory",
["Sim.ValidateDirs"] = "Please fill in all required fields",
["Sim.DotnetCheck"] = ".NET 10.0 SDK is required. Please install it first.",
["Sim.AutoRun"] = "Auto-start server and run client",
["Sim.ManualMode"] = "Server/client generated. Run manually:\ndotnet script client.csx",
["Sim.Starting"] = "Starting simulation...",
["Sim.Completed"] = "Simulation completed ({0:F1}s)",
["Sim.Failed"] = "Simulation failed: {0}",
Expand Down
27 changes: 19 additions & 8 deletions src/Services/SimulationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,25 @@ public async Task<SimulationResult> RunAsync(
Log($"STEP 2: Preparing {config.OutputDirectory}", progress);
Directory.CreateDirectory(config.OutputDirectory);

// 3. Copy patch to server working dir
Log("STEP 3: Setting up local server", progress);
// 3. Generate scripts first (always, even in manual mode)
Log("STEP 3: Generating client.csx and upgrade.csx", progress);
await _generator.GenerateAsync(config, config.OutputDirectory);
Log($" client.csx → {config.OutputDirectory}", progress);
Log($" upgrade.csx → {config.OutputDirectory}", progress);

// Manual mode: skip server + client run
if (!config.AutoRun)
{
Log(" Auto-run disabled — scripts ready for manual execution", progress);
Log($" cd {config.OutputDirectory}", progress);
Log(" dotnet script client.csx", progress);
result.Success = true;
result.Notes.Add("Manual mode: scripts generated, not executed");
return result;
}

// 4. Set up server + copy patch
Log("STEP 4: Setting up local server", progress);
var serverPatchDir = Path.Combine(config.OutputDirectory, ".server");
Directory.CreateDirectory(serverPatchDir);
var patchName = Path.GetFileName(config.PatchFilePath);
Expand All @@ -56,12 +73,6 @@ public async Task<SimulationResult> RunAsync(
Log($" Server running on {_server.BaseUrl}", progress);
config.ServerPort = _server.Port;

// 4. Generate client/upgrade scripts
Log("STEP 4: Generating client.csx and upgrade.csx", progress);
await _generator.GenerateAsync(config, config.OutputDirectory);
Log($" client.csx → {config.OutputDirectory}", progress);
Log($" upgrade.csx → {config.OutputDirectory}", progress);

// 5. Run client
Log("STEP 5: Running client (dotnet script client.csx)", progress);
var clientResult = await RunDotNetScript(config.OutputDirectory, "client.csx", ct);
Expand Down
2 changes: 2 additions & 0 deletions src/Views/SimulateView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
</Border>

<!-- Run -->
<CheckBox Content="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.AutoRun]}"
IsChecked="{Binding Config.AutoRun}"/>
<Button Content="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Sim.Start]}"
Command="{Binding StartSimulationCommand}"
IsEnabled="{Binding !IsRunning}" Height="40" FontSize="14" HorizontalAlignment="Stretch"/>
Expand Down
Loading