public bool Apply(XmlDocument xmlTarget) { if (this.xmlTarget != null) return false; this.logger.HasLoggedErrors = false; this.xmlTarget = xmlTarget; this.xmlTransformable = xmlTarget as XmlTransformableDocument; try { if (this.hasTransformNamespace) { this.InitializeDocumentServices(xmlTarget); this.TransformLoop(this.xmlTransformation); } else this.logger.LogMessage(MessageType.Normal, "The expected namespace {0} was not found in the transform file", new object[1] { (object) XmlTransformation.TransformNamespace }); } catch (Exception ex) { this.HandleException(ex); } finally { this.ReleaseDocumentServices(); this.xmlTarget = (XmlDocument)null; this.xmlTransformable = (XmlTransformableDocument)null; } return !this.logger.HasLoggedErrors; }
private void SaveTransformedFile(XmlTransformableDocument document, string destinationFile) { try { document.Save(destinationFile); } catch (XmlException ex) { throw ex; } catch (Exception ex) { throw new Exception(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Could not write Destination file: {0}", new object[1] { (object)ex.Message }), ex); } }
private XmlTransformableDocument OpenSourceFile(string sourceFile) { try { XmlTransformableDocument transformableDocument = new XmlTransformableDocument(); transformableDocument.PreserveWhitespace = true; transformableDocument.Load(sourceFile); return transformableDocument; } catch (XmlException ex) { throw ex; } catch (Exception ex) { throw new Exception(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Could not open Source file: {0}", new object[1] { (object) ex.Message }), ex); } }
public static string Merge(string webConfigXml, string transformXml) { try { using (var document = new XmlTransformableDocument()) { document.PreserveWhitespace = true; document.LoadXml(webConfigXml); using (var transform = new XmlTransformation(transformXml, false, null)) { if (transform.Apply(document)) { var stringBuilder = new StringBuilder(); var xmlWriterSettings = new XmlWriterSettings { Indent = true, IndentChars = " " }; using (var xmlTextWriter = XmlWriter.Create(stringBuilder, xmlWriterSettings)) { document.WriteTo(xmlTextWriter); } var result = stringBuilder.ToString(); return(result); } Console.WriteLine("Transformation failed for unknown reason", Color.Red); return(null); } } } catch (XmlTransformationException xmlTransformationException) { Console.WriteLine(xmlTransformationException.Message, Color.Red); return(null); } catch (XmlException xmlException) { Console.WriteLine(xmlException.Message, Color.Red); return(null); } }
private XmlTransformableDocument OpenSourceFile(string sourceFile) { try { XmlTransformableDocument transformableDocument = new XmlTransformableDocument(); transformableDocument.PreserveWhitespace = true; transformableDocument.Load(sourceFile); return(transformableDocument); } catch (XmlException ex) { throw ex; } catch (Exception ex) { throw new Exception(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Could not open Source file: {0}", new object[1] { (object)ex.Message }), ex); } }
public bool Execute() { bool flag = true; IXmlTransformationLogger logger = (IXmlTransformationLogger) new Log4netTransformationLogger(); try { logger.StartSection(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Transforming Source File: {0}", new object[1] { (object)this.Source }), new object[0]); XmlTransformableDocument document = this.OpenSourceFile(this.Source); logger.LogMessage(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Applying Transform File: {0}", new object[1] { (object)this.Transform }), new object[0]); flag = this.OpenTransformFile(this.Transform, logger).Apply((XmlDocument)document); if (flag) { logger.LogMessage(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Output File: {0}", new object[1] { (object)this.Destination }), new object[0]); this.SaveTransformedFile(document, this.Destination); } } catch (XmlException ex) { Uri uri = new Uri(ex.SourceUri); logger.LogError(uri.LocalPath, ex.LineNumber, ex.LinePosition, ex.Message, new object[0]); flag = false; } catch (Exception ex) { logger.LogErrorFromException(ex); flag = false; } finally { logger.EndSection(string.Format((IFormatProvider)CultureInfo.CurrentCulture, flag ? "Transformation succeeded" : "Transformation failed", new object[0]), new object[0]); } return(flag); }
public bool Apply(XmlDocument xmlTarget) { if (this.xmlTarget != null) { return(false); } this.logger.HasLoggedErrors = false; this.xmlTarget = xmlTarget; this.xmlTransformable = xmlTarget as XmlTransformableDocument; try { if (this.hasTransformNamespace) { this.InitializeDocumentServices(xmlTarget); this.TransformLoop(this.xmlTransformation); } else { this.logger.LogMessage(MessageType.Normal, "The expected namespace {0} was not found in the transform file", new object[1] { (object)XmlTransformation.TransformNamespace }); } } catch (Exception ex) { this.HandleException(ex); } finally { this.ReleaseDocumentServices(); this.xmlTarget = (XmlDocument)null; this.xmlTransformable = (XmlTransformableDocument)null; } return(!this.logger.HasLoggedErrors); }
private void SaveTransformedFile(XmlTransformableDocument document, string destinationFile) { try { document.Save(destinationFile); } catch (XmlException ex) { throw ex; } catch (Exception ex) { throw new Exception(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Could not write Destination file: {0}", new object[1] { (object) ex.Message }), ex); } }