Skip to content

Commit 61b75f8

Browse files
authored
feat: AutoRun toggle for manual script execution (#52)
- Add Config.AutoRun (default true) checkbox in SimulateView - When off: skip server start + client run, just generate .csx files - Log manual instructions: cd dir; dotnet script client.csx - i18n: Sim.AutoRun / Sim.ManualMode keys added for both locales
1 parent 4b2ffe5 commit 61b75f8

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/Models/SimulateConfigModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public partial class SimulateConfigModel : ObservableObject
1616
[ObservableProperty] private string _appSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6";
1717
[ObservableProperty] private string _productId = "2d974e2a-31e6-4887-9bb1-b4689e98c77a";
1818
[ObservableProperty] private string _outputDirectory = string.Empty;
19+
[ObservableProperty] private bool _autoRun = true;
1920
public int ServerPort { get; set; } = 5000;
2021
}

src/Services/LocalizationService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public string this[string key]
136136
["Sim.SelectOutput"] = "选择模拟输出目录",
137137
["Sim.ValidateDirs"] = "请填写所有必填项",
138138
["Sim.DotnetCheck"] = "需要 .NET 10.0 SDK,请先安装",
139+
["Sim.AutoRun"] = "自动启动服务器并运行客户端",
140+
["Sim.ManualMode"] = "服务器/客户端已生成,可手动运行:\ndotnet script client.csx",
139141
["Sim.Starting"] = "正在启动模拟...",
140142
["Sim.Completed"] = "模拟完成 ({0:F1}s)",
141143
["Sim.Failed"] = "模拟失败: {0}",
@@ -233,6 +235,8 @@ public string this[string key]
233235
["Sim.SelectOutput"] = "Select simulation output directory",
234236
["Sim.ValidateDirs"] = "Please fill in all required fields",
235237
["Sim.DotnetCheck"] = ".NET 10.0 SDK is required. Please install it first.",
238+
["Sim.AutoRun"] = "Auto-start server and run client",
239+
["Sim.ManualMode"] = "Server/client generated. Run manually:\ndotnet script client.csx",
236240
["Sim.Starting"] = "Starting simulation...",
237241
["Sim.Completed"] = "Simulation completed ({0:F1}s)",
238242
["Sim.Failed"] = "Simulation failed: {0}",

src/Services/SimulationService.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,25 @@ public async Task<SimulationResult> RunAsync(
4040
Log($"STEP 2: Preparing {config.OutputDirectory}", progress);
4141
Directory.CreateDirectory(config.OutputDirectory);
4242

43-
// 3. Copy patch to server working dir
44-
Log("STEP 3: Setting up local server", progress);
43+
// 3. Generate scripts first (always, even in manual mode)
44+
Log("STEP 3: Generating client.csx and upgrade.csx", progress);
45+
await _generator.GenerateAsync(config, config.OutputDirectory);
46+
Log($" client.csx → {config.OutputDirectory}", progress);
47+
Log($" upgrade.csx → {config.OutputDirectory}", progress);
48+
49+
// Manual mode: skip server + client run
50+
if (!config.AutoRun)
51+
{
52+
Log(" Auto-run disabled — scripts ready for manual execution", progress);
53+
Log($" cd {config.OutputDirectory}", progress);
54+
Log(" dotnet script client.csx", progress);
55+
result.Success = true;
56+
result.Notes.Add("Manual mode: scripts generated, not executed");
57+
return result;
58+
}
59+
60+
// 4. Set up server + copy patch
61+
Log("STEP 4: Setting up local server", progress);
4562
var serverPatchDir = Path.Combine(config.OutputDirectory, ".server");
4663
Directory.CreateDirectory(serverPatchDir);
4764
var patchName = Path.GetFileName(config.PatchFilePath);
@@ -56,12 +73,6 @@ public async Task<SimulationResult> RunAsync(
5673
Log($" Server running on {_server.BaseUrl}", progress);
5774
config.ServerPort = _server.Port;
5875

59-
// 4. Generate client/upgrade scripts
60-
Log("STEP 4: Generating client.csx and upgrade.csx", progress);
61-
await _generator.GenerateAsync(config, config.OutputDirectory);
62-
Log($" client.csx → {config.OutputDirectory}", progress);
63-
Log($" upgrade.csx → {config.OutputDirectory}", progress);
64-
6576
// 5. Run client
6677
Log("STEP 5: Running client (dotnet script client.csx)", progress);
6778
var clientResult = await RunDotNetScript(config.OutputDirectory, "client.csx", ct);

src/Views/SimulateView.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
</Border>
8383

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

0 commit comments

Comments
 (0)