diff options
Diffstat (limited to 'src/api/burn/WixToolset.BootstrapperApplicationApi/BundleInfo.cs')
-rw-r--r-- | src/api/burn/WixToolset.BootstrapperApplicationApi/BundleInfo.cs | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/api/burn/WixToolset.BootstrapperApplicationApi/BundleInfo.cs b/src/api/burn/WixToolset.BootstrapperApplicationApi/BundleInfo.cs new file mode 100644 index 00000000..14cac881 --- /dev/null +++ b/src/api/burn/WixToolset.BootstrapperApplicationApi/BundleInfo.cs | |||
@@ -0,0 +1,99 @@ | |||
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.BootstrapperApplicationApi | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using System.Xml; | ||
9 | using System.Xml.XPath; | ||
10 | |||
11 | /// <summary> | ||
12 | /// Default implementation of <see cref="IBundleInfo"/>. | ||
13 | /// </summary> | ||
14 | public class BundleInfo : IBundleInfo | ||
15 | { | ||
16 | /// <inheritdoc/> | ||
17 | public bool PerMachine { get; internal set; } | ||
18 | |||
19 | /// <inheritdoc/> | ||
20 | public string Name { get; internal set; } | ||
21 | |||
22 | /// <inheritdoc/> | ||
23 | public string LogVariable { get; internal set; } | ||
24 | |||
25 | /// <inheritdoc/> | ||
26 | public IOverridableVariables OverridableVariables { get; internal set; } | ||
27 | |||
28 | /// <inheritdoc/> | ||
29 | public IDictionary<string, IPackageInfo> Packages { get; internal set; } | ||
30 | |||
31 | internal BundleInfo() | ||
32 | { | ||
33 | this.Packages = new Dictionary<string, IPackageInfo>(); | ||
34 | } | ||
35 | |||
36 | /// <inheritdoc/> | ||
37 | public IPackageInfo AddRelatedBundleAsPackage(string productCode, RelationType relationType, bool perMachine, string version) | ||
38 | { | ||
39 | var package = PackageInfo.GetRelatedBundleAsPackage(productCode, relationType, perMachine, version); | ||
40 | this.Packages.Add(package.Id, package); | ||
41 | return package; | ||
42 | } | ||
43 | |||
44 | /// <inheritdoc/> | ||
45 | public IPackageInfo AddUpdateBundleAsPackage(string packageId) | ||
46 | { | ||
47 | var package = PackageInfo.GetUpdateBundleAsPackage(packageId); | ||
48 | this.Packages.Add(package.Id, package); | ||
49 | return package; | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Parses BA manifest from the given stream. | ||
54 | /// </summary> | ||
55 | /// <param name="stream"></param> | ||
56 | /// <returns></returns> | ||
57 | public static IBundleInfo ParseBundleFromStream(Stream stream) | ||
58 | { | ||
59 | XPathDocument manifest = new XPathDocument(stream); | ||
60 | XPathNavigator root = manifest.CreateNavigator(); | ||
61 | return ParseBundleFromXml(root); | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// Parses BA manifest from the given <see cref="XPathNavigator"/>. | ||
66 | /// </summary> | ||
67 | /// <param name="root">The root of the BA manifest.</param> | ||
68 | /// <returns></returns> | ||
69 | public static IBundleInfo ParseBundleFromXml(XPathNavigator root) | ||
70 | { | ||
71 | BundleInfo bundle = new BundleInfo(); | ||
72 | |||
73 | XmlNamespaceManager namespaceManager = new XmlNamespaceManager(root.NameTable); | ||
74 | namespaceManager.AddNamespace("p", BootstrapperApplicationData.XMLNamespace); | ||
75 | XPathNavigator bundleNode = root.SelectSingleNode("/p:BootstrapperApplicationData/p:WixBundleProperties", namespaceManager); | ||
76 | |||
77 | if (bundleNode == null) | ||
78 | { | ||
79 | throw new Exception("Failed to select bundle information."); | ||
80 | } | ||
81 | |||
82 | bool? perMachine = BootstrapperApplicationData.GetYesNoAttribute(bundleNode, "PerMachine"); | ||
83 | if (perMachine.HasValue) | ||
84 | { | ||
85 | bundle.PerMachine = perMachine.Value; | ||
86 | } | ||
87 | |||
88 | bundle.Name = BootstrapperApplicationData.GetAttribute(bundleNode, "DisplayName"); | ||
89 | |||
90 | bundle.LogVariable = BootstrapperApplicationData.GetAttribute(bundleNode, "LogPathVariable"); | ||
91 | |||
92 | bundle.OverridableVariables = OverridableVariablesInfo.ParseFromXml(root); | ||
93 | |||
94 | bundle.Packages = PackageInfo.ParsePackagesFromXml(root); | ||
95 | |||
96 | return bundle; | ||
97 | } | ||
98 | } | ||
99 | } | ||