Skip to content

Commit

Permalink
Changes to make the SpecFlow.exe tool work properly. The changes shou…
Browse files Browse the repository at this point in the history
…ld work in .NET also, but these will need to be tested to be sure. One of the major changes was to remove the reflection code that was tranforming the CompiledXslTransform and use one of the public facing methods instead. The other major change was in XmlResourceResolver.cs. Needed to add code to resolve assembly names correctly and also resolve resource URI's.
  • Loading branch information
dragan committed Jun 8, 2010
1 parent 29654db commit a2baaa0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Reporting/NUnitExecutionReport/NUnitExecutionReport.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
exclude-result-prefixes="msxsl">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>

<xsl:include href="..\Common\Common.xslt"/>
<xsl:include href="../Common/Common.xslt"/>

<xsl:template match="@* | node()">
<xsl:copy>
Expand Down
2 changes: 1 addition & 1 deletion Reporting/StepDefinitionReport/StepDefinitionReport.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
exclude-result-prefixes="msxsl">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>

<xsl:include href="..\Common\Common.xslt"/>
<xsl:include href="../Common/Common.xslt"/>

<xsl:param name="tool-text">
<Language code="en">
Expand Down
58 changes: 53 additions & 5 deletions Reporting/XmlResourceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,66 @@ public class XmlResourceResolver : XmlResolver
{
private ICredentials credentials;

public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
public override Uri ResolveUri(Uri baseUri, string relativeUri)
{
if (baseUri == null)
{
if (relativeUri == null)
throw new ArgumentNullException ("Either baseUri or relativeUri are required.");

if (relativeUri.StartsWith ("resource:"))
{
return new Uri(relativeUri);
}
else
{
return base.ResolveUri(baseUri, relativeUri);
}
}

return base.ResolveUri(baseUri, relativeUri);
}

public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
{
string resourceName = absoluteUri.AbsolutePath.TrimStart(Path.AltDirectorySeparatorChar).Replace(Path.AltDirectorySeparatorChar, Type.Delimiter);
string assemblyName = absoluteUri.Host;

Assembly assembly = Assembly.Load(assemblyName);
return new ResourceXmlReader(assembly, resourceName);
Assembly assembly = GetAssemblyFor(absoluteUri.Host);

if (ofObjectToReturn != null)
{
if (ofObjectToReturn == typeof(ResourceXmlReader) || ofObjectToReturn == typeof(XmlTextReader))
{
return new ResourceXmlReader(assembly, resourceName);
}
else if (ofObjectToReturn == typeof(Stream))
{
return assembly.GetManifestResourceStream(resourceName);
}
}

return assembly.GetManifestResourceStream(resourceName);
}

public override ICredentials Credentials
{
set { credentials = value; }
}

private static Assembly GetAssemblyFor(string host)
{
Assembly locatedAssembly = null;

foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
AssemblyName assemblyName = assembly.GetName();

if (!assemblyName.Name.Equals(host, StringComparison.CurrentCultureIgnoreCase))
continue;

locatedAssembly = assembly;
}

return locatedAssembly;
}
}
}
28 changes: 5 additions & 23 deletions Reporting/XsltHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,20 @@ public static void TransformHtml(XmlSerializer serializer, object report, Type r
var reportName = reportType.Name.Replace("Generator", "");
using (var xsltReader = new ResourceXmlReader(reportType, reportName + ".xslt"))
{
xslt.Load(xsltReader, xsltSettings, resourceResolver);
xslt.Load(xsltReader, xsltSettings, resourceResolver);
}

var xmlOutputReader = new XmlTextReader(new StringReader(xmlOutputWriter.ToString()));

XsltArgumentList argumentList = new XsltArgumentList();
argumentList.AddParam("feature-language", "", generatorConfiguration.FeatureLanguage.Name);
argumentList.AddParam("tool-language", "", generatorConfiguration.ToolLanguage.Name);
using (var outFileStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write))

using (var outFileStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write))
using (var xmlTextWriter = new XmlTextWriter(outFileStream, Encoding.UTF8))
{
xslt.Transform(xmlOutputReader, argumentList, outFileStream, resourceResolver);
xslt.Transform(xmlOutputReader, argumentList, xmlTextWriter, resourceResolver);
}
}

static public void Transform(this XslCompiledTransform xslt, XmlReader input, XsltArgumentList arguments, Stream results, XmlResolver documentResolver)
{
//xslt.command.Execute(input, new XmlUrlResolver(), arguments, results);

var command = xslt.GetType().GetField("command", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(xslt);

var executeMethod = command.GetType().GetMethod("Execute", new Type[] { typeof(XmlReader), typeof(XmlResolver), typeof(XsltArgumentList), typeof(Stream) });

try
{
executeMethod.Invoke(command, new object[] {input, documentResolver, arguments, results});
}
catch (TargetInvocationException invEx)
{
var ex = invEx.InnerException;
ex.PreserveStackTrace();
throw ex;
}
}
}
}

0 comments on commit a2baaa0

Please sign in to comment.