main
cs 134 lines 4.5 KB
Raw
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.BootstrapperApplicationApi;
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 #pragma warning disable SYSLIB0014 // Type or member is obsolete
117 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
118 #pragma warning restore SYSLIB0014 // Type or member is obsolete
119 request.UserAgent = String.Concat("WixInstall", this.Version.ToString());
120
121 return request;
122 }
123
124 /// <summary>
125 /// Gets the display name for a package if possible.
126 /// </summary>
127 /// <param name="packageId">Identity of the package to find the display name.</param>
128 /// <returns>Display name of the package if found or the package id if not.</returns>
129 public string GetPackageName(string packageId)
130 {
131 return this.BAManifest.Bundle.Packages.TryGetValue(packageId, out var package) ? package.DisplayName : packageId;
132 }
133 }
134 }