12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using NTERA.Engine.Compiler;
- namespace NTERA.Compiler
- {
- public class HTMLWriter
- {
- protected virtual string ReportFooter { get; } = " </body>\r\n</html>";
- public long TotalFileSize { get; set; }
- public int TotalFileCount { get; set; }
- public int FunctionCount { get; set; }
- public IList<Tuple<ParserError, string>> Errors { get; set; }
- public IList<Tuple<ParserError, string>> Warnings { get; set; }
- public void WriteReportToFile(Stream outputStream)
- {
- string ReportHeader = $@"<!DOCTYPE html>
- <html lang=""en"" xmlns=""http://www.w3.org/1999/xhtml"">
- <head>
- <meta charset=""utf-8""/>
- <title>NTERA Compilation Report</title>
- <style>
- {GetCSSStyle()}
- </style>
- </head>
- <body>";
- using (StreamWriter writer = new StreamWriter(outputStream, Encoding.UTF8, 4096, true))
- {
- writer.WriteLine(ReportHeader);
- EmitSummary(writer);
- writer.Write(ReportFooter);
- }
- }
- protected virtual string GetCSSStyle()
- {
- return @" body { font-family: sans-serif; }
- table { height: 98px; width: 100% }
- .message { width: 33.33% }
- .symbol { width: 66.67% }";
- }
- protected virtual void EmitSummary(StreamWriter streamWriter)
- {
- string fileSizeStr = (TotalFileSize / 1048576D).ToString("0.0");
- streamWriter.WriteLine($@" <h3>NTERA Compilation report</h3>
- <hr />
- <p>NTERA v0.X</p>
- <p>Processed {fileSizeStr} MB in {TotalFileCount} files<br />
- Processed {FunctionCount} functions
- </p>
- <p>{Errors.Count} errors, {Warnings.Count} warnings</p>");
- streamWriter.WriteLine(@" <h4>Warnings</h4>
- <table>
- <tbody>");
- foreach (var warning in Warnings)
- {
- EmitError(streamWriter, warning.Item1, warning.Item2);
- }
- streamWriter.WriteLine(@" </tbody>
- </table>
- <br />");
-
- streamWriter.WriteLine(@" <h4>Errors</h4>
- <table>
- <tbody>");
- foreach (var error in Errors)
- {
- EmitError(streamWriter, error.Item1, error.Item2);
- }
- streamWriter.WriteLine(" </tbody>\r\n </table>");
- }
- protected virtual void EmitError(StreamWriter streamWriter, ParserError error, string message)
- {
- streamWriter.WriteLine($@"<tr>
- <td class=""message"">{message}</td>
- <td class=""symbol"">{error.SymbolMarker} : {error.ErrorMessage}</td>
- </tr>");
- }
- }
- }
|