diff options
Diffstat (limited to '')
-rw-r--r-- | src/WixToolset.Mba.Core/BundleInfo.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/WixToolset.Mba.Core/BundleInfo.cs b/src/WixToolset.Mba.Core/BundleInfo.cs new file mode 100644 index 00000000..51c2d268 --- /dev/null +++ b/src/WixToolset.Mba.Core/BundleInfo.cs | |||
@@ -0,0 +1,67 @@ | |||
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.BootstrapperCore | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using System.Xml; | ||
9 | using System.Xml.XPath; | ||
10 | |||
11 | public class BundleInfo : IBundleInfo | ||
12 | { | ||
13 | public bool PerMachine { get; internal set; } | ||
14 | public string Name { get; internal set; } | ||
15 | public string LogVariable { get; internal set; } | ||
16 | public IDictionary<string, IPackageInfo> Packages { get; internal set; } | ||
17 | |||
18 | internal BundleInfo() | ||
19 | { | ||
20 | this.Packages = new Dictionary<string, IPackageInfo>(); | ||
21 | } | ||
22 | |||
23 | public void AddRelatedBundleAsPackage(DetectRelatedBundleEventArgs e) | ||
24 | { | ||
25 | var package = PackageInfo.GetRelatedBundleAsPackage(e.ProductCode, e.RelationType, e.PerMachine, e.Version); | ||
26 | this.Packages.Add(package.Id, package); | ||
27 | } | ||
28 | |||
29 | public static IBundleInfo ParseBundleFromStream(Stream stream) | ||
30 | { | ||
31 | XPathDocument manifest = new XPathDocument(stream); | ||
32 | XPathNavigator root = manifest.CreateNavigator(); | ||
33 | return ParseBundleFromXml(root); | ||
34 | } | ||
35 | |||
36 | public static IBundleInfo ParseBundleFromXml(XPathNavigator root) | ||
37 | { | ||
38 | BundleInfo bundle = new BundleInfo(); | ||
39 | |||
40 | XmlNamespaceManager namespaceManager = new XmlNamespaceManager(root.NameTable); | ||
41 | namespaceManager.AddNamespace("p", BootstrapperApplicationData.XMLNamespace); | ||
42 | XPathNavigator bundleNode = root.SelectSingleNode("/p:BootstrapperApplicationData/p:WixBundleProperties", namespaceManager); | ||
43 | |||
44 | if (bundleNode == null) | ||
45 | { | ||
46 | throw new Exception("Failed to select bundle information."); | ||
47 | } | ||
48 | |||
49 | bool? perMachine = BootstrapperApplicationData.GetYesNoAttribute(bundleNode, "PerMachine"); | ||
50 | if (perMachine.HasValue) | ||
51 | { | ||
52 | bundle.PerMachine = perMachine.Value; | ||
53 | } | ||
54 | |||
55 | bundle.Name = BootstrapperApplicationData.GetAttribute(bundleNode, "DisplayName"); | ||
56 | |||
57 | bundle.LogVariable = BootstrapperApplicationData.GetAttribute(bundleNode, "LogPathVariable"); | ||
58 | |||
59 | foreach (var package in PackageInfo.ParsePackagesFromXml(root)) | ||
60 | { | ||
61 | bundle.Packages.Add(package.Id, package); | ||
62 | } | ||
63 | |||
64 | return bundle; | ||
65 | } | ||
66 | } | ||
67 | } | ||