|
3 | 3 | using GeneralUpdate.Bowl; |
4 | 4 |
|
5 | 5 | /// <summary> |
6 | | -/// 【Skill 参考】Bowl 崩溃守护 |
| 6 | +/// Bowl crash daemon integration. |
7 | 7 | /// |
8 | | -/// v10.5.0-beta.4 中 Bowl 使用 BowlContext 配置,支持 LaunchAsync 方法。 |
| 8 | +/// Bowl monitors whether the main application starts normally after an upgrade. |
| 9 | +/// If a crash is detected, it captures a dump, exports diagnostics, |
| 10 | +/// and optionally restores the previous version from backup. |
9 | 11 | /// |
10 | 12 | /// NuGet: dotnet add package GeneralUpdate.Bowl --version 10.5.0-beta.4 |
| 13 | +/// Note: Reference only GeneralUpdate.Bowl (it transitively includes Core). |
| 14 | +/// Do NOT reference GeneralUpdate.Core separately when using Bowl. |
| 15 | +/// |
| 16 | +/// Platform prerequisites: |
| 17 | +/// - Windows: Sysinternals procdump.exe is auto-bundled via Bowl NuGet package |
| 18 | +/// - Linux: Requires procdump installed (sudo apt install procdump) |
11 | 19 | /// </summary> |
12 | 20 | public static class BowlIntegration |
13 | 21 | { |
14 | 22 | public static async Task RunBowlAsync() |
15 | 23 | { |
| 24 | + // Configure the surveillance context |
16 | 25 | var context = new BowlContext |
17 | 26 | { |
| 27 | + // Process to monitor (name or PID) |
18 | 28 | ProcessNameOrId = "MyApp.exe", |
19 | | - DumpFileName = "v1.0.0.0_fail.dmp", |
20 | | - FailFileName = "v1.0.0.0_fail.json", |
| 29 | + |
| 30 | + // Backup directory path (the version that was running before upgrade) |
21 | 31 | TargetPath = @"C:\Program Files\MyApp", |
22 | | - FailDirectory = @"C:\Program Files\MyApp\fail", |
23 | | - BackupDirectory = @"C:\Program Files\MyApp\backup", |
| 32 | + |
| 33 | + // Version string, used to name dump/crash files |
| 34 | + ExtendedField = "1.0.0.1", |
| 35 | + |
| 36 | + // Generated dump file path |
| 37 | + DumpFileName = "1.0.0.1_fail.dmp", |
| 38 | + |
| 39 | + // Generated crash report file path |
| 40 | + FailFileName = "1.0.0.1_fail.json", |
| 41 | + |
| 42 | + // Where dump/crash files will be written |
| 43 | + FailDirectory = @"C:\Program Files\MyApp\fail\1.0.0.1", |
| 44 | + |
| 45 | + // Backup location (the previous version's backup that can be restored) |
| 46 | + BackupDirectory = @"C:\Program Files\MyApp\1.0.0.0", |
| 47 | + |
| 48 | + // "Upgrade": integrated with update pipeline, auto-restores on crash |
| 49 | + // "Normal": standalone monitoring, no restore |
24 | 50 | WorkModel = "Upgrade", |
25 | | - TimeoutMs = 30_000, |
| 51 | + |
| 52 | + // Auto-restore the previous version on crash (only in "Upgrade" mode) |
26 | 53 | AutoRestore = true, |
| 54 | + |
| 55 | + // Dump type: Full (0), Mini (1), or Heap (2) |
| 56 | + DumpType = DumpType.Full, |
| 57 | + |
| 58 | + // Timeout for child process (procdump), default 30s |
| 59 | + TimeoutMs = 30_000, |
| 60 | + |
| 61 | + // Optional: crash callback for custom handling (logging, telemetry, etc.) |
| 62 | + // OnCrash = async (crashInfo, ct) => { ... }, |
27 | 63 | }; |
28 | 64 |
|
| 65 | + // Apply sensible defaults (Normalize fills in TimeoutMs, WorkModel, DumpType if zero) |
| 66 | + context = context.Normalize(); |
| 67 | + |
| 68 | + // Start surveillance. This blocks until the monitored process exits. |
29 | 69 | var bowl = new Bowl(); |
30 | | - var result = await bowl.LaunchAsync(context); |
| 70 | + BowlResult result = await bowl.LaunchAsync(context); |
31 | 71 |
|
32 | | - Console.WriteLine($"[Bowl] 监控完成: Success={result.Success}, DumpCaptured={result.DumpCaptured}"); |
| 72 | + Console.WriteLine($""" |
| 73 | + [Bowl] 监控完成 |
| 74 | + Success: {result.Success} |
| 75 | + ExitCode: {result.ExitCode} |
| 76 | + DumpCaptured: {result.DumpCaptured} |
| 77 | + DumpFilePath: {result.DumpFilePath} |
| 78 | + Restored: {result.Restored} |
| 79 | + """); |
33 | 80 | } |
34 | 81 | } |
0 commit comments