diff options
Diffstat (limited to 'src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs')
-rw-r--r-- | src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs b/src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs new file mode 100644 index 00000000..855ce9a9 --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs | |||
@@ -0,0 +1,51 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Xml; | ||
8 | using System.Xml.XPath; | ||
9 | |||
10 | /// <summary> | ||
11 | /// Default implementation of <see cref="IOverridableVariables"/>. | ||
12 | /// </summary> | ||
13 | public class OverridableVariablesInfo : IOverridableVariables | ||
14 | { | ||
15 | /// <inheritdoc /> | ||
16 | public IDictionary<string, IOverridableVariableInfo> Variables { get; internal set; } | ||
17 | |||
18 | internal OverridableVariablesInfo() { } | ||
19 | |||
20 | /// <summary> | ||
21 | /// Parses the overridable variable info from the BA manifest. | ||
22 | /// </summary> | ||
23 | /// <param name="root">XML root</param> | ||
24 | /// <returns>The parsed information.</returns> | ||
25 | public static IOverridableVariables ParseFromXml(XPathNavigator root) | ||
26 | { | ||
27 | XmlNamespaceManager namespaceManager = new XmlNamespaceManager(root.NameTable); | ||
28 | namespaceManager.AddNamespace("p", BootstrapperApplicationData.XMLNamespace); | ||
29 | XPathNodeIterator nodes = root.Select("/p:BootstrapperApplicationData/p:WixStdbaOverridableVariable", namespaceManager); | ||
30 | |||
31 | var overridableVariables = new OverridableVariablesInfo(); | ||
32 | overridableVariables.Variables = new Dictionary<string, IOverridableVariableInfo>(); | ||
33 | |||
34 | foreach (XPathNavigator node in nodes) | ||
35 | { | ||
36 | var variable = new OverridableVariableInfo(); | ||
37 | |||
38 | string name = BootstrapperApplicationData.GetAttribute(node, "Name"); | ||
39 | if (name == null) | ||
40 | { | ||
41 | throw new Exception("Failed to get name for overridable variable."); | ||
42 | } | ||
43 | variable.Name = name; | ||
44 | |||
45 | overridableVariables.Variables.Add(variable.Name, variable); | ||
46 | } | ||
47 | |||
48 | return overridableVariables; | ||
49 | } | ||
50 | } | ||
51 | } | ||