private static void WriteTrCss(StringBuilder sb, TypeDefinition type) { sb.AppendFormat("tr.{0} td.colormargin {{ background-color: {1}; }}", type.Name, type.Color); sb.AppendLine(); sb.AppendFormat("tr.{0} td.codecolor {{ background-color: {1};}}", type.Name, type.Background); sb.AppendLine(); sb.AppendFormat("div.{0}.annotationdiv {{ background-color: {1};border-color: {2}; }}", type.Name, type.Background, type.Color); sb.AppendLine(); }
public void Write(string outputDir, IDictionary<File, string> files, TypeDefinition[] types) { var filename = "index.html"; using (var sw = new StreamWriter(Path.Combine(outputDir, filename))) { WriteHeader(sw, files, types); WriteFiles(sw, files, types); WriteFooter(sw); } }
public string Write(string outputDir, File file, TypeDefinition[] types) { var filename = GetFileName(file.Name) + ".html"; using (var sw = new StreamWriter(Path.Combine(outputDir, filename))) { WriteHeader(sw, file, types); WriteSource(sw, file, types); WriteFooter(sw); } return filename; }
private static Dictionary<string, int> CountForTypes(TypeDefinition[] types, KeyValuePair<File, string> file) { var counter = new Dictionary<string, int>(); foreach (var typeDefinition in types) { counter[typeDefinition.Name] = 0; } foreach (var annotation in file.Key.Annotations) { counter[annotation.Type]++; } return counter; }
private static void WriteFile(StreamWriter sw, TypeDefinition[] types, KeyValuePair<File, string> file) { var counter = CountForTypes(types, file); var total = file.Key.Annotations.Length; var row = string.Format("<tr><td><a href='{0}'>{1}</a></td>", file.Value, WebUtility.HtmlEncode(file.Key.Name)); sw.Write(row); foreach (var typeDefinition in types) { sw.Write("<td>{0}</td>", counter[typeDefinition.Name]); } if (types.Length != 1) { sw.Write("<td>{0}</td>", total); } sw.WriteLine("<tr/>"); }
private static void WriteStats(StreamWriter sw, IDictionary<File, string> files, TypeDefinition[] types, int total) { var stats = files.SelectMany(x => x.Key.Annotations).Select(x => x.Type) .GroupBy(x => x) .Select(x => new {Type = types.First(y => y.Name == x.Key).Display, Count = x.Count()}) .OrderBy(x => x.Type) .ToArray(); foreach (var stat in stats) { sw.WriteLine("<tr><th>{0}:</th><td>{1}</td></tr>", WebUtility.HtmlEncode(stat.Type), stat.Count); } if (stats.Length != 1) { sw.WriteLine("<tr><th>Total:</th><td>{0}</td></tr>", total); } }
private static void WriteTableHeader(StreamWriter sw, TypeDefinition[] types) { sw.WriteLine("<colgroup>"); sw.WriteLine("<col />"); foreach (var typeDefinition in types) { sw.WriteLine("<col width='110' />"); } if (types.Length != 1) { sw.WriteLine("<col width='110' />"); } sw.Write("<thead><tr><th>File Name</th>"); foreach (var typeDefinition in types) { sw.Write("<th>{0}</th>", WebUtility.HtmlEncode(typeDefinition.Display)); } if (types.Length != 1) { sw.WriteLine("<th>Total</th>"); } }
private void WriteHeader(StreamWriter sw, IDictionary<File, string> files, TypeDefinition[] types) { var total = files.Sum(x => x.Key.Annotations.Length); sw.WriteLine("<html>"); sw.WriteLine("<head>"); sw.WriteLine("<meta charset='utf-8' />"); sw.WriteLine("<title>Warning Report</title>"); sw.WriteLine("<link rel='stylesheet' type='text/css' href='report.css' />"); sw.WriteLine("</head><body><div class='container'>"); sw.WriteLine("<h1>Summary</h1>"); sw.WriteLine("<table class='overview'>"); sw.WriteLine("<colgroup>"); sw.WriteLine("<col width='160' />"); sw.WriteLine("<col />"); sw.WriteLine("</colgroup>"); sw.WriteLine("<tbody>"); sw.WriteLine("<tr><th>Generated on:</th><td>" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "</td></tr>"); WriteStats(sw, files, types, total); sw.WriteLine("</tbody>"); sw.WriteLine("</table>"); sw.WriteLine("<h1>Files</h1>"); }
private void WriteFiles(StreamWriter sw, IDictionary<File, string> files, TypeDefinition[] types) { sw.WriteLine("<table id='summaryTable' class='overview'>"); WriteTableHeader(sw, types); sw.WriteLine("<tbody>"); foreach (var file in files) { WriteFile(sw, types, file); } sw.WriteLine("</tbody></table>"); }
private void WriteSource(StreamWriter sw, File file, TypeDefinition[] types) { var sourceLines = new string[0]; try { sourceLines = System.IO.File.ReadAllLines(file.Name); } catch (Exception ex) { Log.ErrorFormat("File read error {0}: {1}", file.Name, ex.Message); sw.WriteLine("<div><div class='code'>File read error {0}</div></div>", WebUtility.HtmlEncode(ex.Message)); } List<LineAnnotation> endAnnotations; List<LineAnnotation> beginAnnotations; Line[] lines; CreateFileModel(file, sourceLines, out beginAnnotations, out endAnnotations, out lines); sw.WriteLine("<table class='lineAnalysis'>"); sw.WriteLine("<thead><tr><th></th><th>#</th><th>Line</th><th>Source</th></tr></thead>"); sw.WriteLine("<tbody>"); foreach (var annotation in beginAnnotations) { WriteAnnotationDiv(sw, annotation); } foreach (var line in lines) { WriteSourceLine(sw, line); } foreach (var annotation in endAnnotations) { WriteAnnotationDiv(sw, annotation); } sw.WriteLine("</tbody>"); sw.WriteLine("</table>"); }
private void WriteHeader(StreamWriter sw, File file, TypeDefinition[] types) { var encodedfilename = WebUtility.HtmlEncode(file.Name); var total = file.Annotations.Length; sw.WriteLine("<html>"); sw.WriteLine("<head>"); sw.WriteLine("<meta charset='utf-8' />"); sw.WriteLine("<title>{0} Report</title>", encodedfilename); sw.WriteLine("<link rel='stylesheet' type='text/css' href='report.css' />"); sw.WriteLine("</head><body><div class='container'>"); sw.WriteLine("<h1>Summary</h1>"); sw.WriteLine("<table class='overview'>"); sw.WriteLine("<colgroup>"); sw.WriteLine("<col width='160' />"); sw.WriteLine("<col />"); sw.WriteLine("</colgroup>"); sw.WriteLine("<tbody>"); sw.WriteLine("<tr><th>File:</th><td>" + encodedfilename + "</td></tr>"); var stats = file.Annotations.Select(x => x.Type) .GroupBy(x => x) .Select(x => new {Type = types.First(y => y.Name == x.Key).Display, Count = x.Count()}) .OrderBy(x => x.Type) .ToArray(); foreach (var stat in stats) { sw.WriteLine("<tr><th>{0}:</th><td>{1}</td></tr>", WebUtility.HtmlEncode(stat.Type), stat.Count); } if (stats.Length != 1) { sw.WriteLine("<tr><th>Total:</th><td>" + total + "</td></tr>"); } sw.WriteLine("</tbody>"); sw.WriteLine("</table>"); sw.WriteLine("<h1>Sourcode</h1>"); }