Skip to content

Commit 1a3c8a6

Browse files
authored
feat: add ReportGeneratorService and wire up in SimulateViewModel (#36)
- Generates simulation_report.md with config table, result, notes, full timeline - Wired into SimulateViewModel after successful simulation - Completes the Simulate Update feature (#31)
1 parent 9233719 commit 1a3c8a6

2 files changed

Lines changed: 67 additions & 2 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
using GeneralUpdate.Tools.Models;
6+
7+
namespace GeneralUpdate.Tools.Services;
8+
9+
/// <summary>
10+
/// Generates simulation_report.md after a simulation run.
11+
/// </summary>
12+
public class ReportGeneratorService
13+
{
14+
public async Task<string> GenerateAsync(
15+
SimulateConfigModel config,
16+
SimulationResult result,
17+
string outputDir)
18+
{
19+
var sb = new StringBuilder();
20+
21+
sb.AppendLine("# Update Simulation Report");
22+
sb.AppendLine();
23+
sb.AppendLine("## Configuration");
24+
sb.AppendLine();
25+
sb.AppendLine("| Field | Value |");
26+
sb.AppendLine("|-------|-------|");
27+
sb.AppendLine($"| Patch | {EscapeMd(config.PatchFilePath)} |");
28+
sb.AppendLine($"| App Directory | {EscapeMd(config.AppDirectory)} |");
29+
sb.AppendLine($"| Platform | {config.Platform} |");
30+
sb.AppendLine($"| AppType | {config.AppType} |");
31+
sb.AppendLine($"| Version | {config.CurrentVersion}{config.TargetVersion} |");
32+
sb.AppendLine($"| Server Port | {config.ServerPort} |");
33+
sb.AppendLine($"| Simulation Time | {DateTime.Now:yyyy-MM-dd HH:mm:ss} |");
34+
sb.AppendLine();
35+
36+
sb.AppendLine("## Result");
37+
sb.AppendLine();
38+
sb.AppendLine($"**{(result.Success ? "✅ PASS" : "❌ FAIL")}** — {result.Elapsed.TotalSeconds:F1}s");
39+
if (!string.IsNullOrEmpty(result.ErrorMessage))
40+
sb.AppendLine($"\nError: `{result.ErrorMessage}`");
41+
sb.AppendLine();
42+
43+
if (result.Notes.Count > 0)
44+
{
45+
sb.AppendLine("## Notes");
46+
sb.AppendLine();
47+
foreach (var note in result.Notes)
48+
sb.AppendLine($"- {note}");
49+
sb.AppendLine();
50+
}
51+
52+
sb.AppendLine("## Timeline");
53+
sb.AppendLine();
54+
sb.AppendLine("```");
55+
sb.Append(result.FullLog);
56+
sb.AppendLine("```");
57+
58+
var reportPath = Path.Combine(outputDir, "simulation_report.md");
59+
await File.WriteAllTextAsync(reportPath, sb.ToString(), Encoding.UTF8);
60+
return reportPath;
61+
}
62+
63+
private static string EscapeMd(string s) => s.Replace(@"\", @"\\").Replace("|", "\\|");
64+
}

src/ViewModels/SimulateViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public partial class SimulateViewModel : ViewModelBase
1313
{
1414
private readonly LocalizationService _loc = LocalizationService.Instance;
1515
private readonly SimulationService _sim = new();
16+
private readonly ReportGeneratorService _report = new();
1617

1718
public SimulateConfigModel Config { get; } = new();
1819

@@ -85,8 +86,8 @@ async Task StartSimulation()
8586
L($" Note: {note}");
8687

8788
// Generate report
88-
var reportPath = Path.Combine(Config.OutputDirectory, "simulation_report.md");
89-
// report generation will be in next PR
89+
var reportPath = await _report.GenerateAsync(Config, result, Config.OutputDirectory);
90+
L($"Report: {reportPath}");
9091
}
9192
else
9293
{

0 commit comments

Comments
 (0)