private void WriteReport(IEnumerable <InstallItem> reportLines, string path) { var first = reportLines.First(); var dataFile = "<Result><Item></Item></Result>"; using (var writer = new StreamWriter(GetNewStream(path))) { var aml = new StringBuilder(); using (var amlWriter = new System.IO.StringWriter(aml)) { using (var xml = new ConfigurableXmlWriter(amlWriter)) { xml.ElementProcessor = (prefix, localName, ns, w) => { if (localName == "xsl_stylesheet") { return(ProcessState.DontRender); } return(ProcessState.RenderAll); }; xml.WriteStartElement("AML"); foreach (var line in reportLines) { line.Script.WriteTo(xml); } xml.WriteEndElement(); } } writer.WriteLine(_reportStart); writer.WriteLine(aml); writer.WriteLine(_reportEnd); var xsltElem = first.Script.SelectSingleNode(".//xsl_stylesheet") as XmlElement; if (xsltElem != null) { var xslt = xsltElem.InnerText; var dataStart = xslt.IndexOf(_reportDataStart); var dataEnd = xslt.IndexOf(_reportDataEnd); if (dataStart >= 0 && dataEnd >= 0) { dataFile = xslt.Substring(dataStart + _reportDataStart.Length, dataEnd - dataStart - _reportDataStart.Length).Trim(); xslt = xslt.Substring(0, dataStart).Trim() + Environment.NewLine + xslt.Substring(dataEnd + _reportDataEnd.Length).Trim(); } else { dataFile = xsltElem.Parent().Element("report_query", "<Result><Item></Item></Result>"); } writer.WriteLine(xslt); } } using (var writer = new StreamWriter(GetNewStream(path + ".xml"))) { writer.Write(dataFile); } }
private void WriteReport(IEnumerable<InstallItem> reportLines, string path) { var first = reportLines.First(); var dataFile = "<Result><Item></Item></Result>"; using (var writer = new StreamWriter(GetNewStream(path))) { var aml = new StringBuilder(); using (var amlWriter = new System.IO.StringWriter(aml)) { using (var xml = new ConfigurableXmlWriter(amlWriter)) { xml.ElementProcessor = (prefix, localName, ns, w) => { if (localName == "xsl_stylesheet") return ProcessState.DontRender; return ProcessState.RenderAll; }; xml.WriteStartElement("AML"); foreach (var line in reportLines) { line.Script.WriteTo(xml); } xml.WriteEndElement(); } } writer.WriteLine(_reportStart); writer.WriteLine(aml); writer.WriteLine(_reportEnd); var xsltElem = first.Script.SelectSingleNode(".//xsl_stylesheet") as XmlElement; if (xsltElem != null) { var xslt = xsltElem.InnerText; var dataStart = xslt.IndexOf(_reportDataStart); var dataEnd = xslt.IndexOf(_reportDataEnd); if (dataStart >= 0 && dataEnd >= 0) { dataFile = xslt.Substring(dataStart + _reportDataStart.Length, dataEnd - dataStart - _reportDataStart.Length).Trim(); xslt = xslt.Substring(0, dataStart).Trim() + Environment.NewLine + xslt.Substring(dataEnd + _reportDataEnd.Length).Trim(); } else { dataFile = xsltElem.Parent().Element("report_query", "<Result><Item></Item></Result>"); } writer.WriteLine(xslt); } } using (var writer = new StreamWriter(GetNewStream(path + ".xml"))) { writer.Write(dataFile); } }