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