diff options
| author | Rob Mensching <rob@firegiant.com> | 2021-04-22 17:38:36 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2021-04-29 16:49:19 -0700 |
| commit | 35606d2cd04a7b1bec1d669f9619501dff2bf9dc (patch) | |
| tree | 9dfdca153ab55e842f1e0ae6962fa1214c488c00 /src/heat/UtilTransformMutator.cs | |
| parent | 19f147cc9d56924b8f556bebfa9be5ab3dbeb186 (diff) | |
| download | wix-35606d2cd04a7b1bec1d669f9619501dff2bf9dc.tar.gz wix-35606d2cd04a7b1bec1d669f9619501dff2bf9dc.tar.bz2 wix-35606d2cd04a7b1bec1d669f9619501dff2bf9dc.zip | |
Simplify heat by creating a single executable
Diffstat (limited to 'src/heat/UtilTransformMutator.cs')
| -rw-r--r-- | src/heat/UtilTransformMutator.cs | 77 |
1 files changed, 77 insertions, 0 deletions
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 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolset.Harvesters | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.IO; | ||
| 7 | using System.Xml; | ||
| 8 | using System.Xml.Xsl; | ||
| 9 | using WixToolset.Harvesters.Data; | ||
| 10 | using WixToolset.Harvesters.Extensibility; | ||
| 11 | |||
| 12 | internal class UtilTransformMutator : BaseMutatorExtension | ||
| 13 | { | ||
| 14 | private string transform; | ||
| 15 | private int transformSequence; | ||
| 16 | |||
| 17 | /// <summary> | ||
| 18 | /// Instantiate a new UtilTransformMutator. | ||
| 19 | /// </summary> | ||
| 20 | /// <param name="transform">Path to the XSL transform file.</param> | ||
| 21 | /// <param name="transformSequence">Order in which the transform should be applied, | ||
| 22 | /// relative to other transforms.</param> | ||
| 23 | public UtilTransformMutator(string transform, int transformSequence) | ||
| 24 | { | ||
| 25 | this.transform = transform; | ||
| 26 | this.transformSequence = transformSequence; | ||
| 27 | } | ||
| 28 | |||
| 29 | /// <summary> | ||
| 30 | /// Gets the sequence of the extension. | ||
| 31 | /// </summary> | ||
| 32 | /// <value>The sequence of the extension.</value> | ||
| 33 | public override int Sequence | ||
| 34 | { | ||
| 35 | get { return 3000 + this.transformSequence; } | ||
| 36 | } | ||
| 37 | |||
| 38 | /// <summary> | ||
| 39 | /// Mutate a WiX document as a string. | ||
| 40 | /// </summary> | ||
| 41 | /// <param name="wixString">The Wix document element as a string.</param> | ||
| 42 | /// <returns>The mutated Wix document as a string.</returns> | ||
| 43 | public override string Mutate(string wixString) | ||
| 44 | { | ||
| 45 | try | ||
| 46 | { | ||
| 47 | XslCompiledTransform xslt = new XslCompiledTransform(); | ||
| 48 | xslt.Load(this.transform, XsltSettings.TrustedXslt, new XmlUrlResolver()); | ||
| 49 | |||
| 50 | using (XmlTextReader xmlReader = new XmlTextReader(new StringReader(wixString))) | ||
| 51 | { | ||
| 52 | using (StringWriter stringWriter = new StringWriter()) | ||
| 53 | { | ||
| 54 | XmlWriterSettings xmlSettings = new XmlWriterSettings(); | ||
| 55 | xmlSettings.Indent = true; | ||
| 56 | xmlSettings.IndentChars = " "; | ||
| 57 | xmlSettings.OmitXmlDeclaration = true; | ||
| 58 | |||
| 59 | using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, xmlSettings)) | ||
| 60 | { | ||
| 61 | xslt.Transform(xmlReader, xmlWriter); | ||
| 62 | } | ||
| 63 | |||
| 64 | wixString = stringWriter.ToString(); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | catch (Exception ex) | ||
| 69 | { | ||
| 70 | this.Core.Messaging.Write(HarvesterErrors.ErrorTransformingHarvestedWiX(this.transform, ex.Message)); | ||
| 71 | return null; | ||
| 72 | } | ||
| 73 | |||
| 74 | return wixString; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
