using System; using System.Collections.Generic; using System.IO; using ANXStatusComparer.Data; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. // For details see: http://anxframework.codeplex.com/license namespace ANXStatusComparer.Output { public static class HtmlOutput { #region Constants public const string HtmlFilepath = "Summary.html"; private const string EmptyCell = @" "; #endregion #region GenerateOutput /// /// Generate an html result summary. /// /// Result data to output. /// Filepath to the stylesheet. /// Finished result output. public static void GenerateOutput(ResultData result, string stylesheetFile) { string text = @" "; #region Summary text += String.Format(@"
Summary Missing Wrong Implemented
Namespace {0}   {1}
Class {2} {3} {4}
Struct {5} {6} {7}
Interface {8} {9} {10}
Enum {11} {12} {13}
", result.MissingNamespaces.Count, result.ImplementedNamespaces.Count, result.MissingClasses.Count, result.WrongClasses.Count, result.ImplementedClasses.Count + " (" + result.NumberOfFinishedClasses + " complete)", result.MissingStructs.Count, result.WrongStructs.Count, result.ImplementedStructs.Count + " (" + result.NumberOfFinishedStructs + " complete)", result.MissingInterfaces.Count, result.WrongInterfaces.Count, result.ImplementedInterfaces.Count + " (" + result.NumberOfFinishedInterfaces + " complete)", result.MissingEnums.Count, result.WrongEnums.Count, result.ImplementedEnums.Count); #endregion #region Implemented/Missing Namespaces text += @" "; foreach (string missingNamespace in result.MissingNamespaces) { text += String.Format(@" {0} ", EmptyCell, missingNamespace); } text += @"
Missing Namespaces
{1}
"; foreach (string implementedNamespace in result.ImplementedNamespaces) { text += String.Format(@" {0} ", EmptyCell, implementedNamespace); } text += "\n
Implemented Namespaces
{1}
"; #endregion text += CreateWrongOutput("Classes", result.WrongClasses); #region Implemented/Missing Classes text += @"
"; foreach (BaseObject classData in result.MissingClasses) { text += String.Format(@" {0} ", EmptyCell, classData.Handle.FullName); } text += @"
Missing Classes
{1}
"; foreach (BaseObject classData in result.ImplementedClasses) { text += String.Format(@" {0} ", EmptyCell, classData.ToString()); } text += "\n
Implemented Classes
{1}
"; #endregion text += CreateWrongOutput("Structs", result.WrongStructs); #region Implemented/Missing Structs text += @"
"; foreach (BaseObject structData in result.MissingStructs) { text += String.Format(@" {0} ", EmptyCell, structData.Handle.FullName); } text += @"
Missing Structs
{1}
"; foreach (BaseObject structData in result.ImplementedStructs) { text += String.Format(@" {0} ", EmptyCell, structData.ToString()); } text += "\n
Implemented Structs
{1}
"; #endregion text += CreateWrongOutput("Interfaces", result.WrongInterfaces); #region Implemented/Missing Interfaces text += @"
"; foreach (BaseObject interfaceData in result.MissingInterfaces) { text += String.Format(@" {0} ", EmptyCell, interfaceData.Handle.Name); } text += @"
Missing Interfaces
{1}
"; foreach (BaseObject interfaceData in result.ImplementedInterfaces) { text += String.Format(@" {0} ", EmptyCell, interfaceData.ToString()); } text += "\n
Implemented Interfaces
{1}
"; #endregion #region Wrong Enums text += @"
"; foreach (KeyValuePair wrongEnum in result.WrongEnums) { text += String.Format(@" {0} ", EmptyCell, wrongEnum.Key.Handle.Name); string col1 = ""; for (int index = 0; index < wrongEnum.Key.Names.Count; index++) { col1 += wrongEnum.Key.Names[index] + "=" + wrongEnum.Key.Values[index] + "
\n"; } string col2 = ""; for (int index = 0; index < wrongEnum.Value.Names.Count; index++) { col2 += wrongEnum.Value.Names[index] + "=" + wrongEnum.Value.Values[index] + "
\n"; } text += String.Format(@" {0} {0} ", EmptyCell, col1, col2); } text += "\n
Wrong Enums
{1} XNA ANX
{1} {2}
"; #endregion #region Implemented/Missing Enums text += @"
"; foreach (EnumData enumeration in result.MissingEnums) { text += String.Format(@" {0} ", EmptyCell, enumeration.Handle.Name); } text += @"
Missing Enums
{1}
"; foreach (EnumData enumeration in result.ImplementedEnums) { text += String.Format(@" {0} ", EmptyCell, enumeration.Handle.Name); } text += "\n
Implemented Enums
{1}
"; #endregion text += @" "; File.WriteAllText(HtmlFilepath, text.Replace("\t", " ")); } #endregion #region CreateWrongOutput private static string CreateWrongOutput(string type, List pairs) { string result = @"
"; foreach (ResultData.WrongObjectPair wrongPair in pairs) { #region Missing parents string missingParents = ""; if (wrongPair.MissingParents.Count > 0) { foreach (string parent in wrongPair.MissingParents) { missingParents += parent + ", "; } missingParents = String.Format(@" {0} {0} ", EmptyCell, missingParents); } #endregion #region Wrong access string wrongAccess = ""; if (wrongPair.WrongAccesses.Count > 0) { foreach (string access in wrongPair.WrongAccesses) { wrongAccess += access; } wrongAccess = String.Format(@" {0} {0} ", EmptyCell, wrongAccess); } #endregion result += String.Format(@" {0} {0} {0} {2} {3}", EmptyCell, wrongPair.XnaObject.Handle.FullName, missingParents, wrongAccess); string lastType = ""; string col1 = ""; string col2 = ""; foreach (BaseObjectElement element in wrongPair.XnaElements) { string elementTypeString = element is FieldElement ? "Field" : element is PropertyElement ? "Property" : element is MethodElement ? "Method" : element is ConstructorElement ? "Constructor" : "Event"; if (lastType != elementTypeString) { lastType = elementTypeString; col1 += elementTypeString; } col1 += "
\n"; col2 += element.GetDescription() + "
\n"; } string col3 = ""; foreach (BaseObjectElement element in wrongPair.AnxElements) { col3 += (element != null ? element.GetDescription() : "<Missing>") + "
\n"; } result += String.Format(@" {0} {0} ", EmptyCell, col1, col2, col3); } result += "\n
Wrong " + type + @"
Missing Parents: {1}
Wrong Access: {1}
{1}
Type XNA ANX
{1} {2} {3}
"; return result; } #endregion } }