// 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.Collections; using System.Collections.Specialized; using WixToolset.Harvesters.Data; using WixToolset.Harvesters.Extensibility; using Wix = WixToolset.Harvesters.Serialize; using IIs = Serialize.IIs; /// /// The finalize harvester mutator for the WiX Toolset Internet Information Services Extension. /// public sealed class IIsFinalizeHarvesterMutator : BaseMutatorExtension { private Hashtable directoryPaths; private Hashtable filePaths; private ArrayList webFilters; private ArrayList webSites; private ArrayList webVirtualDirs; /// /// Instantiate a new IIsFinalizeHarvesterMutator. /// public IIsFinalizeHarvesterMutator() { this.directoryPaths = CollectionsUtil.CreateCaseInsensitiveHashtable(); this.filePaths = CollectionsUtil.CreateCaseInsensitiveHashtable(); this.webFilters = new ArrayList(); this.webSites = new ArrayList(); this.webVirtualDirs = new ArrayList(); } /// /// Gets the sequence of this mutator extension. /// /// The sequence of this mutator extension. public override int Sequence { get { return 1900; } } /// /// Mutate a WiX document. /// /// The Wix document element. public override void Mutate(Wix.Wix wix) { this.directoryPaths.Clear(); this.filePaths.Clear(); this.webFilters.Clear(); this.webSites.Clear(); this.webVirtualDirs.Clear(); this.IndexElement(wix); this.MutateWebFilters(); this.MutateWebSites(); this.MutateWebVirtualDirs(); } /// /// Index an element. /// /// The element to index. private void IndexElement(Wix.ISchemaElement element) { if (element is IIs.WebFilter) { this.webFilters.Add(element); } else if (element is IIs.WebSite) { this.webSites.Add(element); } else if (element is IIs.WebVirtualDir) { this.webVirtualDirs.Add(element); } else if (element is Wix.Directory) { Wix.Directory directory = (Wix.Directory)element; if (null != directory.Id && null != directory.FileSource) { this.directoryPaths.Add(directory.FileSource, directory.Id); } } else if (element is Wix.File) { Wix.File file = (Wix.File)element; if (null != file.Id && null != file.Source) { this.filePaths[file.Source] = String.Concat("[#", file.Id, "]"); } } // index the child elements if (element is Wix.IParentElement) { foreach (Wix.ISchemaElement childElement in ((Wix.IParentElement)element).Children) { this.IndexElement(childElement); } } } /// /// Mutate the WebFilters. /// private void MutateWebFilters() { foreach (IIs.WebFilter webFilter in this.webFilters) { webFilter.Path = (string)this.filePaths[webFilter.Path]; } } /// /// Mutate the WebSites. /// private void MutateWebSites() { foreach (IIs.WebSite webSite in this.webSites) { string path = (string)this.directoryPaths[webSite.Directory]; if (null == path) { this.Core.Messaging.Write(HarvesterWarnings.EncounteredNullDirectoryForWebSite(path)); } else { webSite.Directory = path; } } } /// /// Mutate the WebVirtualDirs. /// private void MutateWebVirtualDirs() { foreach (IIs.WebVirtualDir webVirtualDir in this.webVirtualDirs) { string path = (string)this.directoryPaths[webVirtualDir.Directory]; if (null == path) { this.Core.Messaging.Write(HarvesterWarnings.EncounteredNullDirectoryForWebSite(path)); } else { webVirtualDir.Directory = path; } } } } }