summaryrefslogtreecommitdiff
path: root/src/tools/heat/Mutator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/heat/Mutator.cs')
-rw-r--r--src/tools/heat/Mutator.cs93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/tools/heat/Mutator.cs b/src/tools/heat/Mutator.cs
new file mode 100644
index 00000000..8c63882d
--- /dev/null
+++ b/src/tools/heat/Mutator.cs
@@ -0,0 +1,93 @@
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
3namespace WixToolset.Harvesters
4{
5 using System;
6 using System.Collections;
7 using WixToolset.Harvesters.Extensibility;
8 using Wix = WixToolset.Harvesters.Serialize;
9
10 /// <summary>
11 /// The WiX Toolset mutator.
12 /// </summary>
13 internal class Mutator : IMutator
14 {
15 private SortedList extensions;
16 private string extensionArgument;
17
18 /// <summary>
19 /// Instantiate a new mutator.
20 /// </summary>
21 public Mutator()
22 {
23 this.extensions = new SortedList();
24 }
25
26 public IHarvesterCore Core { get; set; }
27
28 public string ExtensionArgument
29 {
30 get { return this.extensionArgument; }
31 set { this.extensionArgument = value; }
32 }
33
34 public void AddExtension(IMutatorExtension mutatorExtension)
35 {
36 this.extensions.Add(mutatorExtension.Sequence, mutatorExtension);
37 }
38
39 public bool Mutate(Wix.Wix wix)
40 {
41 bool encounteredError = false;
42
43 try
44 {
45 foreach (IMutatorExtension mutatorExtension in this.extensions.Values)
46 {
47 if (null == mutatorExtension.Core)
48 {
49 mutatorExtension.Core = this.Core;
50 }
51
52 mutatorExtension.Mutate(wix);
53 }
54 }
55 finally
56 {
57 encounteredError = this.Core.Messaging.EncounteredError;
58 }
59
60 // return the Wix document element only if mutation completed successfully
61 return !encounteredError;
62 }
63
64 public string Mutate(string wixString)
65 {
66 bool encounteredError = false;
67
68 try
69 {
70 foreach (IMutatorExtension mutatorExtension in this.extensions.Values)
71 {
72 if (null == mutatorExtension.Core)
73 {
74 mutatorExtension.Core = this.Core;
75 }
76
77 wixString = mutatorExtension.Mutate(wixString);
78
79 if (String.IsNullOrEmpty(wixString) || this.Core.Messaging.EncounteredError)
80 {
81 break;
82 }
83 }
84 }
85 finally
86 {
87 encounteredError = this.Core.Messaging.EncounteredError;
88 }
89
90 return encounteredError ? null : wixString;
91 }
92 }
93}