Пример #1
0
        public static void Report(string assemblyPath, string outPath, Error[] errors, int numRules, TimeSpan totalTime)
        {
            TextWriter stream = outPath == "stdout" ? Console.Out : new StreamWriter(outPath);

            string assemblyFile = HtmlHelpers.Escape(Path.GetFileName(assemblyPath));

            DoWriteHeader(stream, assemblyFile);

            stream.WriteLine("<body>");
            stream.WriteLine("<h1 class = \"heading\">{0} Violations</h1>", assemblyFile);

            if (errors.Length == 0)
            {
                stream.WriteLine("<p>No errors.</p>");
            }
            else
            {
                int        counter    = 1;
                Violations violations = ReportHelpers.GetViolations(errors);
                DoWriteViolations(stream, Severity.Error, violations, ref counter);
                DoWriteViolations(stream, Severity.Warning, violations, ref counter);
                DoWriteViolations(stream, Severity.Nitpick, violations, ref counter);
                DoWriteSummary(stream, errors, numRules, totalTime);
            }
            stream.WriteLine("</body>");

            DoWriteTrailer(stream);

            stream.Flush();
        }
Пример #2
0
        private static void DoWriteHeader(TextWriter stream, string category)
        {
            HtmlHelpers.WriteHeader(stream);

            stream.WriteLine("<head>");
            stream.WriteLine("    <link rel=\"stylesheet\" type=\"text/css\" href=\"Violations.css\">");
            stream.WriteLine("    <title>{0} Violations</title>", HtmlHelpers.Escape(category));
            stream.WriteLine("</head>");
        }
Пример #3
0
        private static void DoWriteViolation(TextWriter stream, Violation violation)
        {
            stream.WriteLine("<a name = \"{0}\">", violation.TypeName);
            stream.WriteLine("<h2 class = \"category\">{0}</h2>", violation.TypeName);
            stream.WriteLine("</a>");
            HtmlHelpers.WriteText(stream, "CheckId", violation.CheckID);
            HtmlHelpers.WriteSeverity(stream, "Severity", violation.Severity.ToString());
            HtmlHelpers.WriteText(stream, "Breaking", violation.Breaking ? "Yes" : "No");
            HtmlHelpers.WriteText(stream, "Cause", violation.Cause);
            HtmlHelpers.WriteText(stream, "Description", violation.Description);
            HtmlHelpers.WriteText(stream, "Fix", violation.Fix);

            if (violation.Csharp.Length > 0)
            {
                string code = Reformat.Code(violation.Csharp);
                code = HtmlHelpers.Escape(code);
                code = HtmlHelpers.ProcessLinks(code);
                code = HtmlHelpers.ColorizeCode(code);
                stream.WriteLine("<pre class = \"code\">{0}</pre>", code);
            }
        }
Пример #4
0
        private static void DoWriteViolation(TextWriter stream, int counter, Violation violation, List <Location> locations)
        {
            string countStr = DoGetCounter(counter, locations.Count);

            stream.WriteLine("<h2 class = \"category\">{0} {1}</h2>", countStr, violation.TypeName);
            HtmlHelpers.WriteSeverity(stream, "Severity", violation.Severity.ToString());
            HtmlHelpers.WriteText(stream, "Breaking", violation.Breaking ? "Yes" : "No");
            HtmlHelpers.WriteText(stream, "CheckId", violation.CheckID);

            foreach (Location loc in locations)
            {
                stream.WriteLine("<table border = \"2\" rules = \"none\" class = \"location\">");

                stream.WriteLine("<tr>");
                stream.WriteLine("<td>File:</td>");
                stream.WriteLine("<td>");
                if (loc.Line >= 0)
                {
                    stream.WriteLine("{0}:{1}", HtmlHelpers.Escape(loc.File), loc.Line);
                }
                else if (loc.File != null && loc.File.Length > 0)
                {
                    stream.WriteLine(HtmlHelpers.Escape(loc.File));
                }
                else
                {
                    stream.WriteLine("&lt;unknown&gt;");
                }
                stream.WriteLine("</td>");
                stream.WriteLine("</tr>");

                stream.WriteLine("<tr>");
                stream.WriteLine("<td>Name:</td>");
                stream.WriteLine("<td>");
                stream.WriteLine(HtmlHelpers.Escape(loc.Name));
                stream.WriteLine("</td>");
                stream.WriteLine("</tr>");

                if (loc.Details != null && loc.Details.Length > 0)
                {
                    stream.WriteLine("<tr>");
                    stream.WriteLine("<td>Details:</td>");
                    stream.WriteLine("<td>");
                    stream.WriteLine(HtmlHelpers.Escape(loc.Details));
                    stream.WriteLine("</td>");
                    stream.WriteLine("</tr>");
                }

                stream.WriteLine("</table>");
            }

            HtmlHelpers.WriteText(stream, "Cause", BaseReport.Expand(violation.Cause));
            HtmlHelpers.WriteText(stream, "Description", BaseReport.Expand(violation.Description));
            HtmlHelpers.WriteText(stream, "Fix", violation.Fix);

            if (violation.Csharp.Length > 0)
            {
                string code = Reformat.Code(violation.Csharp);
                code = HtmlHelpers.Escape(code);
                code = HtmlHelpers.ProcessLinks(code);
                code = HtmlHelpers.ColorizeCode(code);
                stream.WriteLine("<pre class = \"code\">{0}</pre>", code);
            }

            stream.WriteLine("<hr class = \"separator\">");
        }