|
using Extensibility;
using EnvDTE;
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace WebReports {
/// <summary>Summary description for ReportXSLT.</summary>
internal class ReportXSLT : Report {
/// <summary>Create a ReportXSLT object.</summary>
public ReportXSLT() {
} // ReportXSLT
/// <summary>Number of arguments this report needs to run.</summary>
public override int Arguments {
get { return (2); }
}
/// <summary>Do the analysis by reading 2 files, compare them and render html to the output.</summary>
/// <param name="applicationObject">reference to the VS.NET</param>
/// <param name="output">ouput stream</param>
/// <param name="args">List of all arguments passed to this command.</param>
public override void Render(_DTE applicationObject, StringWriter output, params string[] args) {
StringBuilder html;
string xsltFileName = args[0];
string dataFileName = args[1];
XslTransform xTrans;
XPathDocument xDoc;
// swap filenames
if ((! xsltFileName.ToLower().EndsWith(".xslt")) && (! xsltFileName.ToLower().EndsWith(".xsl"))) {
dataFileName = args[0];
xsltFileName = args[1];
} // if
// load the data (and maybe throw an exception)
try {
xDoc = new XPathDocument(dataFileName);
} catch (XmlException ex) {
// set a usable HelpLink
ex.HelpLink = String.Format("dte:file?file={0}&line={1}&pos={2}",
System.Web.HttpUtility.UrlEncode(dataFileName),
ex.LineNumber, ex.LinePosition);
throw; //re-throw this message
} // try
// load the xslt-file (and maybe throw an exception)
try {
xTrans = new XslTransform();
xTrans.Load(xsltFileName);
} catch (XmlException ex) {
// set a usable HelpLink
ex.HelpLink = String.Format("dte:file?file={0}&line={1}&pos={2}",
System.Web.HttpUtility.UrlEncode(xsltFileName),
ex.LineNumber, ex.LinePosition);
throw; //re-throw this message
} // try
StringBuilder outBuffer = new StringBuilder();
StringWriter outWriter = new StringWriter(outBuffer);
// do the transformation (and maybe throw an exception)
xTrans.Transform(xDoc, null, outWriter, null);
if ((args.Length > 2) && (args[2].ToLower() == "html")) {
html = outBuffer;
} else {
html = new StringBuilder(ExtractHtmlResource("WebReports.WebReports.ReportXSLT.htm"));
// replace all placeholders
html.Replace("[TITLE]",
String.Format("{0} transformed by {1}", dataFileName, xsltFileName));
html.Replace("[XSTLFILE]", System.Web.HttpUtility.HtmlEncode(xsltFileName));
html.Replace("[XSTLFILEENC]", System.Web.HttpUtility.UrlEncode(xsltFileName));
html.Replace("[DATAFILE]", System.Web.HttpUtility.HtmlEncode(dataFileName));
html.Replace("[DATAFILEENC]", System.Web.HttpUtility.UrlEncode(dataFileName));
html.Replace("[RESULT]", System.Web.HttpUtility.HtmlEncode(outBuffer.ToString()));
} // if
output.Write(html.ToString());
} // Render
} // class
} // namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here