diff options
Diffstat (limited to 'src/WixToolset.WixBA/Model.cs')
-rw-r--r-- | src/WixToolset.WixBA/Model.cs | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/src/WixToolset.WixBA/Model.cs b/src/WixToolset.WixBA/Model.cs new file mode 100644 index 00000000..9f03e95b --- /dev/null +++ b/src/WixToolset.WixBA/Model.cs | |||
@@ -0,0 +1,129 @@ | |||
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.UX | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Net; | ||
8 | using WixToolset.Bootstrapper; | ||
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 UX. | ||
21 | /// </summary> | ||
22 | /// <param name="bootstrapper">Bootstrapper hosting the UX.</param> | ||
23 | public Model(BootstrapperApplication bootstrapper) | ||
24 | { | ||
25 | this.Bootstrapper = bootstrapper; | ||
26 | this.Telemetry = new List<KeyValuePair<string, string>>(); | ||
27 | this.Version = this.Engine.VersionVariables[BurnBundleVersionVariable]; | ||
28 | } | ||
29 | |||
30 | /// <summary> | ||
31 | /// Gets the bootstrapper. | ||
32 | /// </summary> | ||
33 | public BootstrapperApplication Bootstrapper { get; private set; } | ||
34 | |||
35 | /// <summary> | ||
36 | /// Gets the bootstrapper command-line. | ||
37 | /// </summary> | ||
38 | public Command Command { get { return this.Bootstrapper.Command; } } | ||
39 | |||
40 | /// <summary> | ||
41 | /// Gets the bootstrapper engine. | ||
42 | /// </summary> | ||
43 | public Engine Engine { get { return this.Bootstrapper.Engine; } } | ||
44 | |||
45 | /// <summary> | ||
46 | /// Gets the key/value pairs used in telemetry. | ||
47 | /// </summary> | ||
48 | public List<KeyValuePair<string, string>> Telemetry { get; private set; } | ||
49 | |||
50 | /// <summary> | ||
51 | /// Get or set the final result of the installation. | ||
52 | /// </summary> | ||
53 | public int Result { get; set; } | ||
54 | |||
55 | /// <summary> | ||
56 | /// Get the version of the install. | ||
57 | /// </summary> | ||
58 | public Version Version { get; private set; } | ||
59 | |||
60 | /// <summary> | ||
61 | /// Get or set the path where the bundle is installed. | ||
62 | /// </summary> | ||
63 | public string InstallDirectory | ||
64 | { | ||
65 | get | ||
66 | { | ||
67 | if (!this.Engine.StringVariables.Contains(BurnBundleInstallDirectoryVariable)) | ||
68 | { | ||
69 | return null; | ||
70 | } | ||
71 | |||
72 | return this.Engine.StringVariables[BurnBundleInstallDirectoryVariable]; | ||
73 | } | ||
74 | |||
75 | set | ||
76 | { | ||
77 | this.Engine.StringVariables[BurnBundleInstallDirectoryVariable] = value; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Get or set the path for the layout to be created. | ||
83 | /// </summary> | ||
84 | public string LayoutDirectory | ||
85 | { | ||
86 | get | ||
87 | { | ||
88 | if (!this.Engine.StringVariables.Contains(BurnBundleLayoutDirectoryVariable)) | ||
89 | { | ||
90 | return null; | ||
91 | } | ||
92 | |||
93 | return this.Engine.StringVariables[BurnBundleLayoutDirectoryVariable]; | ||
94 | } | ||
95 | |||
96 | set | ||
97 | { | ||
98 | this.Engine.StringVariables[BurnBundleLayoutDirectoryVariable] = value; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | public LaunchAction PlannedAction { get; set; } | ||
103 | |||
104 | /// <summary> | ||
105 | /// Creates a correctly configured HTTP web request. | ||
106 | /// </summary> | ||
107 | /// <param name="uri">URI to connect to.</param> | ||
108 | /// <returns>Correctly configured HTTP web request.</returns> | ||
109 | public HttpWebRequest CreateWebRequest(string uri) | ||
110 | { | ||
111 | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); | ||
112 | request.UserAgent = String.Concat("WixInstall", this.Version.ToString()); | ||
113 | |||
114 | return request; | ||
115 | } | ||
116 | |||
117 | /// <summary> | ||
118 | /// Gets the display name for a package if possible. | ||
119 | /// </summary> | ||
120 | /// <param name="packageId">Identity of the package to find the display name.</param> | ||
121 | /// <returns>Display name of the package if found or the package id if not.</returns> | ||
122 | public string GetPackageName(string packageId) | ||
123 | { | ||
124 | PackageInfo package; | ||
125 | |||
126 | return this.Bootstrapper.BAManifest.Bundle.Packages.TryGetValue(packageId, out package) ? package.DisplayName : packageId; | ||
127 | } | ||
128 | } | ||
129 | } | ||