diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-05-06 18:55:18 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-05-11 19:11:19 -0500 |
commit | 8c27fbe1bc8a6d83859aead2105d6d528c307726 (patch) | |
tree | 1e26f482e119fd9bcb348412766eaba31bf4fc84 /src/test/burn/WixToolset.WixBA/Model.cs | |
parent | 3c88529e8e29f9763a6830f8d3ac29cd56a4cb33 (diff) | |
download | wix-8c27fbe1bc8a6d83859aead2105d6d528c307726.tar.gz wix-8c27fbe1bc8a6d83859aead2105d6d528c307726.tar.bz2 wix-8c27fbe1bc8a6d83859aead2105d6d528c307726.zip |
Move WixToolset.WixBA into test/burn and use new PackageReferences.
Diffstat (limited to 'src/test/burn/WixToolset.WixBA/Model.cs')
-rw-r--r-- | src/test/burn/WixToolset.WixBA/Model.cs | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/src/test/burn/WixToolset.WixBA/Model.cs b/src/test/burn/WixToolset.WixBA/Model.cs new file mode 100644 index 00000000..a557fa4e --- /dev/null +++ b/src/test/burn/WixToolset.WixBA/Model.cs | |||
@@ -0,0 +1,132 @@ | |||
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.WixBA | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Net; | ||
8 | using WixToolset.Mba.Core; | ||
9 | |||
10 | /// <summary> | ||
11 | /// The model. | ||
12 | /// </summary> | ||
13 | public class Model | ||
14 | { | ||
15 | private const string BurnBundleInstallDirectoryVariable = "InstallFolder"; | ||
16 | private const string BurnBundleLayoutDirectoryVariable = "WixBundleLayoutDirectory"; | ||
17 | private const string BurnBundleVersionVariable = "WixBundleVersion"; | ||
18 | |||
19 | /// <summary> | ||
20 | /// Creates a new model for the BA. | ||
21 | /// </summary> | ||
22 | /// <param name="bootstrapper">The BA.</param> | ||
23 | public Model(WixBA bootstrapper) | ||
24 | { | ||
25 | this.BAManifest = bootstrapper.BAManifest; | ||
26 | this.Bootstrapper = bootstrapper; | ||
27 | this.Command = bootstrapper.Command; | ||
28 | this.Engine = bootstrapper.Engine; | ||
29 | this.Telemetry = new List<KeyValuePair<string, string>>(); | ||
30 | this.Version = this.Engine.GetVariableVersion(BurnBundleVersionVariable); | ||
31 | } | ||
32 | |||
33 | public IBootstrapperApplicationData BAManifest { get; } | ||
34 | |||
35 | /// <summary> | ||
36 | /// Gets the bootstrapper. | ||
37 | /// </summary> | ||
38 | public IDefaultBootstrapperApplication Bootstrapper { get; } | ||
39 | |||
40 | /// <summary> | ||
41 | /// Gets the bootstrapper command-line. | ||
42 | /// </summary> | ||
43 | public IBootstrapperCommand Command { get; } | ||
44 | |||
45 | /// <summary> | ||
46 | /// Gets the bootstrapper engine. | ||
47 | /// </summary> | ||
48 | public IEngine Engine { get; } | ||
49 | |||
50 | /// <summary> | ||
51 | /// Gets the key/value pairs used in telemetry. | ||
52 | /// </summary> | ||
53 | public List<KeyValuePair<string, string>> Telemetry { get; private set; } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Get or set the final result of the installation. | ||
57 | /// </summary> | ||
58 | public int Result { get; set; } | ||
59 | |||
60 | /// <summary> | ||
61 | /// Get the version of the install. | ||
62 | /// </summary> | ||
63 | public string Version { get; private set; } | ||
64 | |||
65 | /// <summary> | ||
66 | /// Get or set the path where the bundle is installed. | ||
67 | /// </summary> | ||
68 | public string InstallDirectory | ||
69 | { | ||
70 | get | ||
71 | { | ||
72 | if (!this.Engine.ContainsVariable(BurnBundleInstallDirectoryVariable)) | ||
73 | { | ||
74 | return null; | ||
75 | } | ||
76 | |||
77 | return this.Engine.GetVariableString(BurnBundleInstallDirectoryVariable); | ||
78 | } | ||
79 | |||
80 | set | ||
81 | { | ||
82 | this.Engine.SetVariableString(BurnBundleInstallDirectoryVariable, value, false); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Get or set the path for the layout to be created. | ||
88 | /// </summary> | ||
89 | public string LayoutDirectory | ||
90 | { | ||
91 | get | ||
92 | { | ||
93 | if (!this.Engine.ContainsVariable(BurnBundleLayoutDirectoryVariable)) | ||
94 | { | ||
95 | return null; | ||
96 | } | ||
97 | |||
98 | return this.Engine.GetVariableString(BurnBundleLayoutDirectoryVariable); | ||
99 | } | ||
100 | |||
101 | set | ||
102 | { | ||
103 | this.Engine.SetVariableString(BurnBundleLayoutDirectoryVariable, value, false); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public LaunchAction PlannedAction { get; set; } | ||
108 | |||
109 | /// <summary> | ||
110 | /// Creates a correctly configured HTTP web request. | ||
111 | /// </summary> | ||
112 | /// <param name="uri">URI to connect to.</param> | ||
113 | /// <returns>Correctly configured HTTP web request.</returns> | ||
114 | public HttpWebRequest CreateWebRequest(string uri) | ||
115 | { | ||
116 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
117 | request.UserAgent = String.Concat("WixInstall", this.Version.ToString()); | ||
118 | |||
119 | return request; | ||
120 | } | ||
121 | |||
122 | /// <summary> | ||
123 | /// Gets the display name for a package if possible. | ||
124 | /// </summary> | ||
125 | /// <param name="packageId">Identity of the package to find the display name.</param> | ||
126 | /// <returns>Display name of the package if found or the package id if not.</returns> | ||
127 | public string GetPackageName(string packageId) | ||
128 | { | ||
129 | return this.BAManifest.Bundle.Packages.TryGetValue(packageId, out var package) ? package.DisplayName : packageId; | ||
130 | } | ||
131 | } | ||
132 | } | ||