From 35606d2cd04a7b1bec1d669f9619501dff2bf9dc Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 22 Apr 2021 17:38:36 -0700 Subject: Simplify heat by creating a single executable --- src/heat/UtilTransformMutator.cs | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/heat/UtilTransformMutator.cs (limited to 'src/heat/UtilTransformMutator.cs') diff --git a/src/heat/UtilTransformMutator.cs b/src/heat/UtilTransformMutator.cs new file mode 100644 index 00000000..f4dda3c5 --- /dev/null +++ b/src/heat/UtilTransformMutator.cs @@ -0,0 +1,77 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Harvesters +{ + using System; + using System.IO; + using System.Xml; + using System.Xml.Xsl; + using WixToolset.Harvesters.Data; + using WixToolset.Harvesters.Extensibility; + + internal class UtilTransformMutator : BaseMutatorExtension + { + private string transform; + private int transformSequence; + + /// + /// Instantiate a new UtilTransformMutator. + /// + /// Path to the XSL transform file. + /// Order in which the transform should be applied, + /// relative to other transforms. + public UtilTransformMutator(string transform, int transformSequence) + { + this.transform = transform; + this.transformSequence = transformSequence; + } + + /// + /// Gets the sequence of the extension. + /// + /// The sequence of the extension. + public override int Sequence + { + get { return 3000 + this.transformSequence; } + } + + /// + /// Mutate a WiX document as a string. + /// + /// The Wix document element as a string. + /// The mutated Wix document as a string. + public override string Mutate(string wixString) + { + try + { + XslCompiledTransform xslt = new XslCompiledTransform(); + xslt.Load(this.transform, XsltSettings.TrustedXslt, new XmlUrlResolver()); + + using (XmlTextReader xmlReader = new XmlTextReader(new StringReader(wixString))) + { + using (StringWriter stringWriter = new StringWriter()) + { + XmlWriterSettings xmlSettings = new XmlWriterSettings(); + xmlSettings.Indent = true; + xmlSettings.IndentChars = " "; + xmlSettings.OmitXmlDeclaration = true; + + using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, xmlSettings)) + { + xslt.Transform(xmlReader, xmlWriter); + } + + wixString = stringWriter.ToString(); + } + } + } + catch (Exception ex) + { + this.Core.Messaging.Write(HarvesterErrors.ErrorTransformingHarvestedWiX(this.transform, ex.Message)); + return null; + } + + return wixString; + } + } +} -- cgit v1.2.3-55-g6feb