public void EmptyParameters() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // load empty parameters { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlInputPaths = xmlPaths; t.XslInputPath = xslPath; t.Parameters = " "; Assert.True(t.Execute()); // "This test should've passed (empty parameters)." Console.WriteLine(engine.Log); } CleanUp(dir); }
public void CompiledDllWithType() { string dir; TaskItem xslCompiledPath; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out xslCompiledPath, out outputPaths, out _, out _, out engine); // Test Compiled DLLs // with type specified. { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; xslCompiledPath.ItemSpec += ";xslt"; t.XslCompiledDllPath = xslCompiledPath; Assert.Equal(xslCompiledPath.ItemSpec, t.XslCompiledDllPath.ItemSpec); Assert.True(t.Execute()); // "XsltComiledDll1 execution should've passed" Console.WriteLine(engine.Log); Assert.DoesNotContain("MSB", engine.Log); // "The log should not contain any errors. (XsltComiledDll1)" } CleanUp(dir); }
public void CompiledDllWithTwoTypes() { string dir; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out _, out outputPaths, out _, out _, out engine); // doubletype string doubleTypePath = Path.Combine(dir, "double.dll"); CompileDoubleType(doubleTypePath); { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslCompiledDllPath = new TaskItem(doubleTypePath); try { t.Execute(); Console.WriteLine(engine.Log); } catch (Exception e) { Assert.Contains("error?", e.Message); } System.Diagnostics.Debug.WriteLine(engine.Log); } CleanUp(dir); }
public void XsltParamatersCorrect() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // Test Correct Xslt Parameters { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslContent = _xslParameterDocument; t.Parameters = _xslParameters; t.Execute(); Console.WriteLine(engine.Log); using (StreamReader sr = new StreamReader(t.OutputPaths[0].ItemSpec)) { string fileContents = sr.ReadToEnd(); Assert.Contains("param 1: 1param 2: 2", fileContents); } } CleanUp(dir); }
public void MissingCompiledDllFile() { string dir; TaskItem xslCompiledPath; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out xslCompiledPath, out outputPaths, out _, out _, out engine); // missing xsltCompiledDll { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; xslCompiledPath.ItemSpec += "bad;xslt"; t.XslCompiledDllPath = xslCompiledPath; Assert.False(t.Execute()); // "XsltComiledDllBad execution should've failed" Console.WriteLine(engine.Log); Assert.Contains("MSB3704", engine.Log); } CleanUp(dir); }
public void MissingOutputFile() { Assert.Throws <System.ArgumentNullException>(() => { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // load missing xml { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.XmlInputPaths = xmlPaths; t.XslInputPath = xslPath; Assert.False(t.Execute()); // "This test should've failed (no output)." Console.WriteLine(engine.Log); } CleanUp(dir); } ); }
public void MissingXsltFile() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out _, out outputPaths, out _, out _, out engine); // load missing xsl { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlInputPaths = xmlPaths; xslPath.ItemSpec += "bad"; t.XslInputPath = xslPath; Assert.False(t.Execute()); // "This test should've failed (bad xslt)." Console.WriteLine(engine.Log); Assert.Contains("MSB3704", engine.Log); } CleanUp(dir); }
public void OutputFileCannotBeWritten() { string dir; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out _, out outputPaths, out _, out _, out engine); // load bad output { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslContent = _xslDocument; t.OutputPaths = new TaskItem[] { new TaskItem("k:\\folder\\file.xml") }; try { Assert.False(t.Execute()); // "This test should've failed (bad output)." Console.WriteLine(engine.Log); } catch (Exception e) { Assert.Contains("MSB3701", e.Message); } } CleanUp(dir); }
public void BadXsltFile() { string dir; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out _, out outputPaths, out _, out _, out engine); // load bad xslt { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslContent = _errorXslDocument; try { t.Execute(); Console.WriteLine(engine.Log); } catch (Exception e) { Assert.Contains("The '$' character", e.Message); } } CleanUp(dir); }
public void BadXmlAsParameter() { string dir; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out _, out outputPaths, out _, out _, out engine); // load bad xml on parameters { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslContent = _xslParameterDocument; t.Parameters = "<<>>"; try { Assert.False(t.Execute()); // "This test should've failed (bad params1)." Console.WriteLine(engine.Log); } catch (Exception e) { Assert.Contains("'<'", e.Message); } } CleanUp(dir); }
public void XsltDocumentThrowsError() { string dir; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out _, out outputPaths, out _, out _, out engine); // load error xslDocument { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslContent = _errorXslDocument2; try { Assert.False(t.Execute()); // "This test should've failed (xsl with error)." Console.WriteLine(engine.Log); } catch (Exception e) { Assert.Contains("error?", e.Message); } } CleanUp(dir); }
public void OutputTest() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // Test Out { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.XmlContent = _xmlDocument; t.XslContent = _xslDocument; t.OutputPaths = outputPaths; Assert.True(t.Execute()); // "Test out should have given true when executed" Assert.Equal(String.Empty, engine.Log); // "The log should be empty" Console.WriteLine(engine.Log); using (StreamReader sr = new StreamReader(t.OutputPaths[0].ItemSpec)) { string fileContents = sr.ReadToEnd(); MatchCollection mc = _surroundMatch.Matches(fileContents); Assert.Equal(8, mc.Count); // "The file test doesn't match" } } CleanUp(dir); }
public void ManyXslParameters() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // Test too many Xsl. { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslContent = _xslDocument; t.XslInputPath = xslPath; Assert.Equal(_xslDocument, t.XslContent); Assert.Equal(xslPath, t.XslInputPath); Assert.False(t.Execute()); // "The test should fail when there are too many files" Console.WriteLine(engine.Log); Assert.Contains("MSB3701", engine.Log); // "The output should contain MSB3701 error message at no params test" } CleanUp(dir); }
public void MissingXmlXslParameter() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // Test both missing. { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; Assert.False(t.Execute()); // "The test should fail when there is no params" Console.WriteLine(engine.Log); Assert.Contains("MSB3701", engine.Log); // "The output should contain MSB3701 error message" } CleanUp(dir); }
public void XslDocumentFunctionWorks() { string dir; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out _, out outputPaths, out _, out _, out engine); var otherXslPath = new TaskItem(Path.Combine(dir, Guid.NewGuid().ToString() + ".xslt")); using (StreamWriter sw = new StreamWriter(otherXslPath.ItemSpec, false)) { sw.Write(_xslDocument2); } // Initialize first xml file for the XslTransformation task to consume var myXmlPath1 = new TaskItem(Path.Combine(dir, "a.xml")); using (StreamWriter sw = new StreamWriter(myXmlPath1.ItemSpec, false)) { sw.Write("<document><myInclude path = \"b.xml\"/></document>"); } // Initialize second xml file for the first one to consume var myXmlPath2 = new TaskItem(Path.Combine(dir, "b.xml")); using (StreamWriter sw = new StreamWriter(myXmlPath2.ItemSpec, false)) { sw.Write("<stuff/>"); } // Validate that execution passes when UseTrustedSettings is true XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlInputPaths = new TaskItem[] { myXmlPath1 }; t.XslInputPath = otherXslPath; t.UseTrustedSettings = true; Assert.True(t.Execute()); // "Test should have passed and allowed the use of the document() function within the xslt file" // Validate that execution fails when UseTrustedSettings is false t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlInputPaths = new TaskItem[] { myXmlPath1 }; t.XslInputPath = otherXslPath; t.UseTrustedSettings = false; Assert.False(t.Execute()); // "Test should have failed and not allowed the use of the document() function within the xslt file" CleanUp(dir); }
public void MultipleXmlInputs_NotMatching() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out _, out outputPaths, out _, out _, out engine); // xmlPaths have one XmlPath, lets duplicate it **4 times ** TaskItem[] xmlMultiPaths = new TaskItem[] { xmlPaths[0], xmlPaths[0], xmlPaths[0], xmlPaths[0] }; // outputPaths have one output path, lets duplicate it **3 times ** TaskItem[] outputMultiPathsShort = new TaskItem[] { new TaskItem(outputPaths[0].ItemSpec + ".1.xml"), new TaskItem(outputPaths[0].ItemSpec + ".2.xml"), new TaskItem(outputPaths[0].ItemSpec + ".3.xml") }; TaskItem[] outputMultiPathsLong = new TaskItem[] { new TaskItem(outputPaths[0].ItemSpec + ".1.xml"), new TaskItem(outputPaths[0].ItemSpec + ".2.xml"), new TaskItem(outputPaths[0].ItemSpec + ".3.xml"), new TaskItem(outputPaths[0].ItemSpec + ".4.xml"), new TaskItem(outputPaths[0].ItemSpec + ".5.xml") }; // Short version. { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.XslInputPath = xslPath; t.XmlInputPaths = xmlMultiPaths; t.OutputPaths = outputMultiPathsShort; Assert.False(t.Execute(), "CompiledDllWithTwoTypes execution should've failed" + engine.Log); System.Diagnostics.Debug.WriteLine(engine.Log); } // Long version { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.XslInputPath = xslPath; t.XmlInputPaths = xmlMultiPaths; t.OutputPaths = outputMultiPathsLong; Assert.False(t.Execute(), "CompiledDllWithTwoTypes execution should've failed" + engine.Log); Console.WriteLine(engine.Log); System.Diagnostics.Debug.WriteLine(engine.Log); } CleanUp(dir); }
public void XsltParametersIncorrect() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // Test Xslt Parameters { string[] attrs = new string[] { "Name=\"param2\"", "Namespace=\"http://eksiduyuru.com\"", "Value=\"2\"" }; for (int i = 0; i < Math.Pow(2, attrs.Length); i++) { string res = ""; for (int k = 0; k < attrs.Length; k++) { if ((i & (int)Math.Pow(2, k)) != 0) { res += attrs[k] + " "; } } XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslContent = _xslParameterDocument; t.Parameters = "<Parameter " + res + "/>"; Assert.Equal("<Parameter " + res + "/>", t.Parameters); bool result = t.Execute(); Console.WriteLine(engine.Log); if (i == 5 || i == 7) { Assert.True(result); // "Only 5th and 7th values should pass." } else { Assert.False(result); // "Only 5th and 7th values should pass." } } } CleanUp(dir); }
public void MissingXmlParameter() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem xslCompiledPath; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out xslCompiledPath, out outputPaths, out xmlInputs, out xslInputs, out engine); // Test Xml missing. for (int xsi = 0; xsi < xslInputs.Count; xsi++) { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; XslTransformation.XsltInput.XslModes xslKey = xslInputs[xsi].Key; object xslValue = xslInputs[xsi].Value; switch (xslKey) { case XslTransformation.XsltInput.XslModes.Xslt: t.XslContent = (string)xslValue; break; case XslTransformation.XsltInput.XslModes.XsltFile: t.XslInputPath = (TaskItem)xslValue; break; case XslTransformation.XsltInput.XslModes.XsltCompiledDll: t.XslCompiledDllPath = (TaskItem)xslValue; break; default: Assert.True(false, "Test error"); break; } Assert.False(t.Execute()); // "The test should fail when there is missing Xml params" Console.WriteLine(engine.Log); Assert.Contains("MSB3701", engine.Log); // "The output should contain MSB3701 error message at missing Xml params test" engine.Log = ""; } CleanUp(dir); }
private XsltError Transform() { Stopwatch timer = Stopwatch.StartNew(); XslTimings timings; //// Contract.Assert((this.useSourceStdIn && string.IsNullOrEmpty(this.sourceFile)) || (!this.useSourceStdIn && !string.IsNullOrEmpty(this.sourceFile))); //// Contract.Assert((this.useStylesheetStdIn && string.IsNullOrEmpty(this.stylesheetFile)) || (!this.useStylesheetStdIn && !string.IsNullOrEmpty(this.stylesheetFile))); using (TextReader xml = GetInput(this.useSourceStdIn, this.sourceFile)) { using (TextReader xsl = GetInput(this.useStylesheetStdIn, this.stylesheetFile)) { try { using (Stream output = GetOutput(this.useOutputfile, this.outputfile)) { try { timings = XslTransformation.Transform(xsl, xml, output, this.xsltOptions); } catch (XsltException ex) { DisplayError(ex.Message, XsltError.CompileContext, this.stylesheetFile); return(XsltError.CompileContext); } catch (XmlException ex) { DisplayError(ex.Message, XsltError.CompileContext, this.stylesheetFile); return(XsltError.CompileContext); } } } catch (IOException ex) { DisplayError(ex.Message, XsltError.MSXSL_E_CREATE_FILE_CTXT, this.outputfile); return(XsltError.MSXSL_E_CREATE_FILE_CTXT); } } } timer.Stop(); timings.Total = timer.Elapsed; if (this.useTimings) { DisplayTimings(timings); } return(XsltError.None); }
public void MultipleXmlInputs_Matching() { string dir; TaskItem[] xmlPaths; TaskItem xslPath; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out xmlPaths, out xslPath, out _, out outputPaths, out _, out _, out engine); var otherXmlPath = new TaskItem(Path.Combine(dir, Guid.NewGuid().ToString())); using (StreamWriter sw = new StreamWriter(otherXmlPath.ItemSpec, false)) { sw.Write(_xmlDocument2); } // xmlPaths have one XmlPath, lets duplicate it TaskItem[] xmlMultiPaths = new TaskItem[] { xmlPaths[0], otherXmlPath, xmlPaths[0], xmlPaths[0] }; // outputPaths have one output path, lets duplicate it TaskItem[] outputMultiPaths = new TaskItem[] { new TaskItem(outputPaths[0].ItemSpec + ".1.xml"), new TaskItem(outputPaths[0].ItemSpec + ".2.xml"), new TaskItem(outputPaths[0].ItemSpec + ".3.xml"), new TaskItem(outputPaths[0].ItemSpec + ".4.xml") }; { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.XslInputPath = xslPath; t.XmlInputPaths = xmlMultiPaths; t.OutputPaths = outputMultiPaths; Assert.True(t.Execute(), "CompiledDllWithTwoTypes execution should've passed" + engine.Log); Console.WriteLine(engine.Log); foreach (TaskItem tsk in t.OutputPaths) { Assert.True(File.Exists(tsk.ItemSpec), tsk.ItemSpec + " should exist on output dir"); } // The first and second input XML files are not equivalent, so their output files // should be different Assert.NotEqual(new FileInfo(xmlMultiPaths[0].ItemSpec).Length, new FileInfo(xmlMultiPaths[1].ItemSpec).Length); Assert.NotEqual(new FileInfo(outputMultiPaths[0].ItemSpec).Length, new FileInfo(outputMultiPaths[1].ItemSpec).Length); System.Diagnostics.Debug.WriteLine(engine.Log); } CleanUp(dir); }
public void CompiledDllWithoutType() { string dir; TaskItem xslCompiledPath; TaskItem[] outputPaths; MockEngine engine; Prepare(out dir, out _, out _, out xslCompiledPath, out outputPaths, out _, out _, out engine); // without type specified. { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; t.XmlContent = _xmlDocument; t.XslCompiledDllPath = xslCompiledPath; Assert.True(t.Execute(), "XsltComiledDll2 execution should've passed" + engine.Log); Console.WriteLine(engine.Log); Assert.False(engine.MockLogger.ErrorCount > 0); // "The log should not contain any errors. (XsltComiledDll2)" } CleanUp(dir); }
/// <exclude /> public override IEnumerable<PackageFragmentValidationResult> Validate() { _xslTransformations = new List<XslTransformation>(); var validationResult = new List<PackageFragmentValidationResult>(); var filesElement = this.ConfigurationParent.GetSingleConfigurationElement("XslFiles", validationResult, false); if (filesElement == null) { return validationResult; } foreach (XElement fileElement in filesElement.GetConfigurationElements("XslFile", validationResult)) { XAttribute pathXMLAttribute = fileElement.Attribute(TargetXmlAttributeName); XAttribute inputXMLAttribute = fileElement.Attribute(InputXmlAttributeName); XAttribute outputXMLAttribute = fileElement.Attribute(OutputXmlAttributeName); XAttribute pathXSLAttribute = fileElement.Attribute(TargetXslAttributeName); XAttribute installXSLAttribute = fileElement.Attribute(InstallXslAttributeName); XAttribute uninstallXSLAttribute = fileElement.Attribute(UninstallXslAttributeName); XAttribute overrideReadOnlyAttribute = fileElement.Attribute(OverrideReadOnlyAttributeName); XAttribute skipIfNotExistAttribute = fileElement.Attribute(SkipIfNotExistAttributeName); bool skipIfNotExist = skipIfNotExistAttribute != null && skipIfNotExistAttribute.Value.ToLower() == "true"; if (pathXSLAttribute == null && installXSLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } if (outputXMLAttribute != null && uninstallXSLAttribute != null) { validationResult.AddFatal("Xsl installer does not suppurt simultaneous usage of attributes '{0}' and '{1}'" .FormatWith(OutputXmlAttributeName, UninstallXslAttributeName), fileElement); continue; } string xslFilePath = (pathXSLAttribute ?? installXSLAttribute).Value; XslTransformation xslFile; if (inputXMLAttribute != null) { if (outputXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("outputFilename"), fileElement); continue; } xslFile = new XslTransformation { XslPath = xslFilePath, InputXmlPath = inputXMLAttribute.Value, OutputXmlPath = outputXMLAttribute.Value }; } else { if (pathXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } string pathToXmlFile = pathXMLAttribute.Value; xslFile = new XslTransformation { XslPath = xslFilePath, // UninstallXslPath = uninstallXSLAttribute != null ? uninstallXSLAttribute.Value : null, InputXmlPath = pathToXmlFile, OutputXmlPath = pathToXmlFile }; } if (!C1File.Exists(PathUtil.Resolve(xslFile.InputXmlPath))) { if (skipIfNotExist) continue; validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileNotFound(xslFile.InputXmlPath), fileElement); continue; } string outputXmlFullPath = PathUtil.Resolve(xslFile.OutputXmlPath); if (C1File.Exists(outputXmlFullPath) && (C1File.GetAttributes(outputXmlFullPath) & FileAttributes.ReadOnly) > 0) { if (overrideReadOnlyAttribute == null || overrideReadOnlyAttribute.Value != "true") { validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnly(xslFile.OutputXmlPath), fileElement); continue; } FileUtils.RemoveReadOnly(outputXmlFullPath); Log.LogWarning(LogTitle, Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnlyOverride(xslFile.OutputXmlPath)); } if (!PathUtil.WritePermissionGranted(outputXmlFullPath)) { validationResult.AddFatal(Texts.NotEnoughNtfsPermissions(xslFile.OutputXmlPath), fileElement); continue; } _xslTransformations.Add(xslFile); } if (validationResult.Count > 0) { _xslTransformations = null; } return validationResult; }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { _xslTransformations = new List <XslTransformation>(); var validationResult = new List <PackageFragmentValidationResult>(); var filesElement = this.ConfigurationParent.GetSingleConfigurationElement("XslFiles", validationResult, false); if (filesElement == null) { return(validationResult); } foreach (XElement fileElement in filesElement.GetConfigurationElements("XslFile", validationResult)) { XAttribute pathXMLAttribute = fileElement.Attribute(TargetXmlAttributeName); XAttribute inputXMLAttribute = fileElement.Attribute(InputXmlAttributeName); XAttribute outputXMLAttribute = fileElement.Attribute(OutputXmlAttributeName); XAttribute pathXSLAttribute = fileElement.Attribute(TargetXslAttributeName); XAttribute installXSLAttribute = fileElement.Attribute(InstallXslAttributeName); XAttribute uninstallXSLAttribute = fileElement.Attribute(UninstallXslAttributeName); XAttribute overrideReadOnlyAttribute = fileElement.Attribute(OverrideReadOnlyAttributeName); XAttribute skipIfNotExistAttribute = fileElement.Attribute(SkipIfNotExistAttributeName); bool skipIfNotExist = skipIfNotExistAttribute != null && skipIfNotExistAttribute.Value.ToLower() == "true"; if (pathXSLAttribute == null && installXSLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } if (outputXMLAttribute != null && uninstallXSLAttribute != null) { validationResult.AddFatal("Xsl installer does not suppurt simultaneous usage of attributes '{0}' and '{1}'" .FormatWith(OutputXmlAttributeName, UninstallXslAttributeName), fileElement); continue; } string xslFilePath = (pathXSLAttribute ?? installXSLAttribute).Value; XslTransformation xslFile; if (inputXMLAttribute != null) { if (outputXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("outputFilename"), fileElement); continue; } xslFile = new XslTransformation { XslPath = xslFilePath, InputXmlPath = inputXMLAttribute.Value, OutputXmlPath = outputXMLAttribute.Value }; } else { if (pathXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } string pathToXmlFile = pathXMLAttribute.Value; xslFile = new XslTransformation { XslPath = xslFilePath, // UninstallXslPath = uninstallXSLAttribute != null ? uninstallXSLAttribute.Value : null, InputXmlPath = pathToXmlFile, OutputXmlPath = pathToXmlFile }; } if (!C1File.Exists(PathUtil.Resolve(xslFile.InputXmlPath))) { if (skipIfNotExist) { continue; } validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileNotFound(xslFile.InputXmlPath), fileElement); continue; } string outputXmlFullPath = PathUtil.Resolve(xslFile.OutputXmlPath); if (C1File.Exists(outputXmlFullPath) && (C1File.GetAttributes(outputXmlFullPath) & FileAttributes.ReadOnly) > 0) { if (overrideReadOnlyAttribute == null || overrideReadOnlyAttribute.Value != "true") { validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnly(xslFile.OutputXmlPath), fileElement); continue; } FileUtils.RemoveReadOnly(outputXmlFullPath); Log.LogWarning(LogTitle, Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnlyOverride(xslFile.OutputXmlPath)); } if (!PathUtil.WritePermissionGranted(outputXmlFullPath)) { validationResult.AddFatal(Texts.NotEnoughNtfsPermissions(xslFile.OutputXmlPath), fileElement); continue; } _xslTransformations.Add(xslFile); } if (validationResult.Count > 0) { _xslTransformations = null; } return(validationResult); }
public static XslTransformation CreateNewXslTransformation() { var content = System.Xml.Linq.XDocument.Load( AppDomain.CurrentDomain.BaseDirectory + "\\cim.xslt" ); var result = new XslTransformation { Id = Guid.NewGuid(), TransformationDescription = "CIM Gateway Commerce", TransformationName = "CIM Transformation", Xsl = content.ToString() }; return result; }
public void XmlXslParameters() { string dir; TaskItem[] outputPaths; List <KeyValuePair <XslTransformation.XmlInput.XmlModes, object> > xmlInputs; List <KeyValuePair <XslTransformation.XsltInput.XslModes, object> > xslInputs; MockEngine engine; Prepare(out dir, out _, out _, out _, out outputPaths, out xmlInputs, out xslInputs, out engine); // Test when Xml and Xsl parameters are correct for (int xmi = 0; xmi < xmlInputs.Count; xmi++) { for (int xsi = 0; xsi < xslInputs.Count; xsi++) { XslTransformation t = new XslTransformation(); t.BuildEngine = engine; t.OutputPaths = outputPaths; XslTransformation.XmlInput.XmlModes xmlKey = xmlInputs[xmi].Key; object xmlValue = xmlInputs[xmi].Value; XslTransformation.XsltInput.XslModes xslKey = xslInputs[xsi].Key; object xslValue = xslInputs[xsi].Value; switch (xmlKey) { case XslTransformation.XmlInput.XmlModes.Xml: t.XmlContent = (string)xmlValue; break; case XslTransformation.XmlInput.XmlModes.XmlFile: t.XmlInputPaths = (TaskItem[])xmlValue; break; default: Assert.True(false, "Test error"); break; } switch (xslKey) { case XslTransformation.XsltInput.XslModes.Xslt: t.XslContent = (string)xslValue; break; case XslTransformation.XsltInput.XslModes.XsltFile: t.XslInputPath = (TaskItem)xslValue; break; case XslTransformation.XsltInput.XslModes.XsltCompiledDll: t.XslCompiledDllPath = (TaskItem)xslValue; break; default: Assert.True(false, "Test error"); break; } Assert.True(t.Execute()); // "The test should have passed at the both params correct test" } } CleanUp(dir); }
private XsltError Process() { if (this.validate) { // TODO: This will fail if it's not a file e.g. stdin XmlValidation validator = new XmlValidation(); using (StreamReader xml = new StreamReader(this.sourceFile)) { if (!validator.IsValid(xml)) { DisplayError(string.Empty, XsltError.ParseError, validator.LastException.Message); return(XsltError.ParseError); } } } List <string> undefinedPrefixes = this.xsltOptions.GetUndefinedPrefixes(); if (undefinedPrefixes.Count > 0) { DisplayCommandError(XsltError.MSXSL_E_PREFIX_UNDEFINED, undefinedPrefixes[0]); return(XsltError.MSXSL_E_PREFIX_UNDEFINED); } List <Tuple <string, string> > invalids = this.xsltOptions.GetInvalidArguments(); if (invalids.Count > 0) { DisplayError(invalids[0].Item2, XsltError.MSXSL_E_PARAM_CTXT, invalids[0].Item1); return(XsltError.MSXSL_E_PARAM_CTXT); } if (string.IsNullOrEmpty(this.stylesheetFile) && this.useProcessingInstruction) { string xml = File.ReadAllText(this.sourceFile); this.stylesheetFile = XslTransformation.GetPi(xml); this.useStylesheetStdIn = false; if (string.IsNullOrEmpty(this.stylesheetFile)) { DisplayError(string.Empty, XsltError.InvalidPi); return(XsltError.InvalidPi); } } if (!string.IsNullOrEmpty(this.xsltOptions.StartMode) && this.xsltOptions.StartMode.Contains(":")) { DisplayError(string.Format(CultureInfo.CurrentCulture, XsltResources.NameNotContainChar, ":"), XsltError.ModeContext, this.xsltOptions.StartMode); return(XsltError.ModeContext); } // TODO: Support Uris? // TODO: Support UNC? // For input & output XsltError fileError = XsltError.None; if (!this.useSourceStdIn) { fileError = this.TestFileExists(this.sourceFile); if (fileError != XsltError.None) { return(fileError); } } if (!this.useStylesheetStdIn) { fileError = this.TestFileExists(this.stylesheetFile); if (fileError != XsltError.None) { return(fileError); } } return(this.Transform()); }