summaryrefslogtreecommitdiff
path: root/src/tools/heat/IIsFinalizeHarvesterMutator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/heat/IIsFinalizeHarvesterMutator.cs')
-rw-r--r--src/tools/heat/IIsFinalizeHarvesterMutator.cs160
1 files changed, 160 insertions, 0 deletions
diff --git a/src/tools/heat/IIsFinalizeHarvesterMutator.cs b/src/tools/heat/IIsFinalizeHarvesterMutator.cs
new file mode 100644
index 00000000..cfe90272
--- /dev/null
+++ b/src/tools/heat/IIsFinalizeHarvesterMutator.cs
@@ -0,0 +1,160 @@
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 System.Collections.Specialized;
8 using WixToolset.Harvesters.Data;
9 using WixToolset.Harvesters.Extensibility;
10 using Wix = WixToolset.Harvesters.Serialize;
11 using IIs = Serialize.IIs;
12
13 /// <summary>
14 /// The finalize harvester mutator for the WiX Toolset Internet Information Services Extension.
15 /// </summary>
16 public sealed class IIsFinalizeHarvesterMutator : BaseMutatorExtension
17 {
18 private Hashtable directoryPaths;
19 private Hashtable filePaths;
20 private ArrayList webFilters;
21 private ArrayList webSites;
22 private ArrayList webVirtualDirs;
23
24 /// <summary>
25 /// Instantiate a new IIsFinalizeHarvesterMutator.
26 /// </summary>
27 public IIsFinalizeHarvesterMutator()
28 {
29 this.directoryPaths = CollectionsUtil.CreateCaseInsensitiveHashtable();
30 this.filePaths = CollectionsUtil.CreateCaseInsensitiveHashtable();
31 this.webFilters = new ArrayList();
32 this.webSites = new ArrayList();
33 this.webVirtualDirs = new ArrayList();
34 }
35
36 /// <summary>
37 /// Gets the sequence of this mutator extension.
38 /// </summary>
39 /// <value>The sequence of this mutator extension.</value>
40 public override int Sequence
41 {
42 get { return 1900; }
43 }
44
45 /// <summary>
46 /// Mutate a WiX document.
47 /// </summary>
48 /// <param name="wix">The Wix document element.</param>
49 public override void Mutate(Wix.Wix wix)
50 {
51 this.directoryPaths.Clear();
52 this.filePaths.Clear();
53 this.webFilters.Clear();
54 this.webSites.Clear();
55 this.webVirtualDirs.Clear();
56
57 this.IndexElement(wix);
58
59 this.MutateWebFilters();
60 this.MutateWebSites();
61 this.MutateWebVirtualDirs();
62 }
63
64 /// <summary>
65 /// Index an element.
66 /// </summary>
67 /// <param name="element">The element to index.</param>
68 private void IndexElement(Wix.ISchemaElement element)
69 {
70 if (element is IIs.WebFilter)
71 {
72 this.webFilters.Add(element);
73 }
74 else if (element is IIs.WebSite)
75 {
76 this.webSites.Add(element);
77 }
78 else if (element is IIs.WebVirtualDir)
79 {
80 this.webVirtualDirs.Add(element);
81 }
82 else if (element is Wix.Directory)
83 {
84 Wix.Directory directory = (Wix.Directory)element;
85
86 if (null != directory.Id && null != directory.FileSource)
87 {
88 this.directoryPaths.Add(directory.FileSource, directory.Id);
89 }
90 }
91 else if (element is Wix.File)
92 {
93 Wix.File file = (Wix.File)element;
94
95 if (null != file.Id && null != file.Source)
96 {
97 this.filePaths[file.Source] = String.Concat("[#", file.Id, "]");
98 }
99 }
100
101 // index the child elements
102 if (element is Wix.IParentElement)
103 {
104 foreach (Wix.ISchemaElement childElement in ((Wix.IParentElement)element).Children)
105 {
106 this.IndexElement(childElement);
107 }
108 }
109 }
110
111 /// <summary>
112 /// Mutate the WebFilters.
113 /// </summary>
114 private void MutateWebFilters()
115 {
116 foreach (IIs.WebFilter webFilter in this.webFilters)
117 {
118 webFilter.Path = (string)this.filePaths[webFilter.Path];
119 }
120 }
121
122 /// <summary>
123 /// Mutate the WebSites.
124 /// </summary>
125 private void MutateWebSites()
126 {
127 foreach (IIs.WebSite webSite in this.webSites)
128 {
129 string path = (string)this.directoryPaths[webSite.Directory];
130 if (null == path)
131 {
132 this.Core.Messaging.Write(HarvesterWarnings.EncounteredNullDirectoryForWebSite(path));
133 }
134 else
135 {
136 webSite.Directory = path;
137 }
138 }
139 }
140
141 /// <summary>
142 /// Mutate the WebVirtualDirs.
143 /// </summary>
144 private void MutateWebVirtualDirs()
145 {
146 foreach (IIs.WebVirtualDir webVirtualDir in this.webVirtualDirs)
147 {
148 string path = (string)this.directoryPaths[webVirtualDir.Directory];
149 if (null == path)
150 {
151 this.Core.Messaging.Write(HarvesterWarnings.EncounteredNullDirectoryForWebSite(path));
152 }
153 else
154 {
155 webVirtualDir.Directory = path;
156 }
157 }
158 }
159 }
160}