1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . IO ;
4+
5+ namespace SignToolGUI . Class
6+ {
7+ public static class SigningReportExporter
8+ {
9+ public static void ExportToHtml (
10+ IList < Forms . MainForm . SigningReportEntry > entries ,
11+ string certType ,
12+ string certDetails ,
13+ string appVersion ,
14+ string outputPath )
15+ {
16+ var sb = new System . Text . StringBuilder ( ) ;
17+ sb . AppendLine ( "<!DOCTYPE html>" ) ;
18+ sb . AppendLine ( "<html><head><meta charset='utf-8'><title>Signing Report</title>" ) ;
19+ sb . AppendLine ( @"<style>
20+ body { font-family: Segoe UI, Arial, sans-serif; background: #f8f8f8; }
21+ h1 { color: #2d5c8a; }
22+ h2 { color: #444; font-size: 1.1em; margin-bottom: 0.5em; }
23+ ul.job-summary { list-style: none; padding: 0; margin: 0 0 1em 0; }
24+ ul.job-summary li { margin-bottom: 4px; }
25+ .cert-details {
26+ background: #f4f8fc;
27+ border: 1px solid #cce;
28+ padding: 16px 18px;
29+ margin-left: 0;
30+ margin-bottom: 1.5em;
31+ max-width: 480px;
32+ box-shadow: 0 2px 8px rgba(44, 76, 120, 0.08);
33+ border-radius: 10px;
34+ }
35+ .cert-details strong { font-size: 1.08em; color: #2d5c8a; }
36+ table { border-collapse: collapse; width: 100%; background: #fff; }
37+ th, td { border: 1px solid #ccc; padding: 8px; }
38+ th { background: #e3eaf2; }
39+ tr.success { background: #eafbe7; }
40+ tr.error { background: #ffeaea; }
41+ tr.pending { background: #fffbe7; }
42+ pre { font-family: Consolas, monospace; font-size: 12px; white-space: pre-wrap; margin: 0; }
43+ </style></head><body>" ) ;
44+ sb . AppendLine ( "<h1>Signing Report</h1>" ) ;
45+ sb . AppendLine ( "<h2>Job Summary</h2>" ) ;
46+ sb . AppendLine ( "<ul class='job-summary'>" ) ;
47+ sb . AppendLine ( $ "<li><strong>Date:</strong> { DateTime . Now : yyyy-MM-dd HH:mm:ss} </li>") ;
48+ sb . AppendLine ( $ "<li><strong>Certificate Type:</strong> { System . Net . WebUtility . HtmlEncode ( certType ) } </li>") ;
49+ sb . AppendLine ( $ "<li><strong>Files Signed:</strong> { entries . Count } </li>") ;
50+ sb . AppendLine ( $ "<li><strong>Generated by:</strong> { Environment . UserName } on { Environment . MachineName } </li>") ;
51+ sb . AppendLine ( $ "<li><strong>Application Version:</strong> { appVersion } </li>") ;
52+ //sb.AppendLine($"<li><strong>OS Version:</strong> {Environment.OSVersion.VersionString}</li>");
53+ //sb.AppendLine($"<li><strong>.NET Version:</strong> {Environment.Version}</li>");
54+ sb . AppendLine ( "</ul>" ) ;
55+
56+ sb . AppendLine ( "<div class='cert-details'><strong>Certificate Details</strong><br><pre>" +
57+ System . Net . WebUtility . HtmlEncode ( certDetails ) + "</pre></div>" ) ;
58+
59+ sb . AppendLine ( "<table>" ) ;
60+ sb . AppendLine ( "<tr><th>File Name</th><th>Status</th><th>Error</th><th>Timestamp</th></tr>" ) ;
61+ foreach ( var entry in entries )
62+ {
63+ var rowClass = entry . Status == "Success" ? "success" : entry . Status == "Error" ? "error" : "pending" ;
64+ sb . AppendLine ( $ "<tr class='{ rowClass } '>") ;
65+ sb . AppendLine ( $ "<td>{ System . Net . WebUtility . HtmlEncode ( entry . FileName ) } </td>") ;
66+ sb . AppendLine ( $ "<td>{ System . Net . WebUtility . HtmlEncode ( entry . Status ) } </td>") ;
67+ sb . AppendLine ( $ "<td>{ System . Net . WebUtility . HtmlEncode ( entry . Error ) } </td>") ;
68+ sb . AppendLine ( $ "<td>{ System . Net . WebUtility . HtmlEncode ( entry . Timestamp ) } </td>") ;
69+ sb . AppendLine ( "</tr>" ) ;
70+ }
71+ sb . AppendLine ( "</table>" ) ;
72+ sb . AppendLine ( "</body></html>" ) ;
73+ File . WriteAllText ( outputPath , sb . ToString ( ) ) ;
74+ }
75+
76+ public static void ExportToCsv (
77+ IList < Forms . MainForm . SigningReportEntry > entries ,
78+ string certType ,
79+ string certDetails ,
80+ string appVersion ,
81+ string outputPath )
82+ {
83+ var lines = new List < string >
84+ {
85+ $ "# Signing Report",
86+ $ "# Date: { DateTime . Now : yyyy-MM-dd HH:mm:ss} ",
87+ $ "# Certificate Type: { certType } ",
88+ $ "# Files Signed: { entries . Count } ",
89+ $ "# Generated by: { Environment . UserName } on { Environment . MachineName } ",
90+ $ "# Application Version: { appVersion } ",
91+ $ "# OS Version: { Environment . OSVersion . VersionString } ",
92+ $ "# .NET Version: { Environment . Version } ",
93+ $ "# Certificate Details: { certDetails . Replace ( Environment . NewLine , " | " ) } ",
94+ "" ,
95+ "File Name,Status,Error,Timestamp"
96+ } ;
97+
98+ foreach ( var entry in entries )
99+ {
100+ lines . Add ( $ "\" { entry . FileName } \" ,\" { entry . Status } \" ,\" { entry . Error } \" ,\" { entry . Timestamp } \" ") ;
101+ }
102+
103+ File . WriteAllLines ( outputPath , lines ) ;
104+ }
105+
106+ public static void ExportToTxt (
107+ IList < Forms . MainForm . SigningReportEntry > entries ,
108+ string certType ,
109+ string certDetails ,
110+ string appVersion ,
111+ string outputPath )
112+ {
113+ var sb = new System . Text . StringBuilder ( ) ;
114+ sb . AppendLine ( "=== Signing Report ===" ) ;
115+ sb . AppendLine ( $ "Date: { DateTime . Now : yyyy-MM-dd HH:mm:ss} ") ;
116+ sb . AppendLine ( $ "Certificate Type: { certType } ") ;
117+ sb . AppendLine ( $ "Files Signed: { entries . Count } ") ;
118+ sb . AppendLine ( $ "Generated by: { Environment . UserName } on { Environment . MachineName } ") ;
119+ sb . AppendLine ( $ "Application Version: { appVersion } ") ;
120+ sb . AppendLine ( $ "OS Version: { Environment . OSVersion . VersionString } ") ;
121+ sb . AppendLine ( $ ".NET Version: { Environment . Version } ") ;
122+ sb . AppendLine ( "Certificate Details:" ) ;
123+ sb . AppendLine ( certDetails ) ;
124+ sb . AppendLine ( new string ( '=' , 60 ) ) ;
125+
126+ foreach ( var entry in entries )
127+ {
128+ sb . AppendLine ( $ "File: { entry . FileName } ") ;
129+ sb . AppendLine ( $ "Status: { entry . Status } ") ;
130+ if ( ! string . IsNullOrEmpty ( entry . Error ) )
131+ sb . AppendLine ( $ "Error: { entry . Error } ") ;
132+ sb . AppendLine ( $ "Timestamp: { entry . Timestamp } ") ;
133+ sb . AppendLine ( new string ( '-' , 60 ) ) ;
134+ }
135+
136+ File . WriteAllText ( outputPath , sb . ToString ( ) ) ;
137+ }
138+ }
139+ }
0 commit comments