using System; using System.Collections.Generic; using System.IO; using ANXStatusComparer.Data; #region License // // This file is part of the ANX.Framework created by the "ANX.Framework developer group". // // This file is released under the Ms-PL license. // // // // Microsoft Public License (Ms-PL) // // This license governs use of the accompanying software. If you use the software, you accept this license. // If you do not accept the license, do not use the software. // // 1.Definitions // The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning // here as under U.S. copyright law. // A "contribution" is the original software, or any additions or changes to the software. // A "contributor" is any person that distributes its contribution under this license. // "Licensed patents" are a contributor's patent claims that read directly on its contribution. // // 2.Grant of Rights // (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations // in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to // reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution // or any derivative works that you create. // (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in // section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed // patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution // in the software or derivative works of the contribution in the software. // // 3.Conditions and Limitations // (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. // (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your // patent license from such contributor to the software ends automatically. // (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution // notices that are present in the software. // (D) If you distribute any portion of the software in source code form, you may do so only under this license by including // a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or // object code form, you may only do so under a license that complies with this license. // (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, // or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the // extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a // particular purpose and non-infringement. #endregion // 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.MissingStructs.Count, result.WrongStructs.Count, result.ImplementedStructs.Count, result.MissingInterfaces.Count, result.WrongInterfaces.Count, result.ImplementedInterfaces.Count, 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.Handle.Name); } 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.Handle.Name); } 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.Handle.Name); } 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 } }