// 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. namespace WixToolset.WixBA { using System; using System.Collections.Generic; using System.Net; using WixToolset.Mba.Core; /// /// The model. /// public class Model { private const string BurnBundleInstallDirectoryVariable = "InstallFolder"; private const string BurnBundleLayoutDirectoryVariable = "WixBundleLayoutDirectory"; private const string BurnBundleVersionVariable = "WixBundleVersion"; /// /// Creates a new model for the BA. /// /// The BA. public Model(WixBA bootstrapper) { this.BAManifest = bootstrapper.BAManifest; this.Bootstrapper = bootstrapper; this.Command = bootstrapper.Command; this.Engine = bootstrapper.Engine; this.Telemetry = new List>(); this.Version = this.Engine.GetVariableVersion(BurnBundleVersionVariable); } public IBootstrapperApplicationData BAManifest { get; } /// /// Gets the bootstrapper. /// public IDefaultBootstrapperApplication Bootstrapper { get; } /// /// Gets the bootstrapper command-line. /// public IBootstrapperCommand Command { get; } /// /// Gets the bootstrapper engine. /// public IEngine Engine { get; } /// /// Gets the key/value pairs used in telemetry. /// public List> Telemetry { get; private set; } /// /// Get or set the final result of the installation. /// public int Result { get; set; } /// /// Get the version of the install. /// public string Version { get; private set; } /// /// Get or set the path where the bundle is installed. /// public string InstallDirectory { get { if (!this.Engine.ContainsVariable(BurnBundleInstallDirectoryVariable)) { return null; } return this.Engine.GetVariableString(BurnBundleInstallDirectoryVariable); } set { this.Engine.SetVariableString(BurnBundleInstallDirectoryVariable, value, false); } } /// /// Get or set the path for the layout to be created. /// public string LayoutDirectory { get { if (!this.Engine.ContainsVariable(BurnBundleLayoutDirectoryVariable)) { return null; } return this.Engine.GetVariableString(BurnBundleLayoutDirectoryVariable); } set { this.Engine.SetVariableString(BurnBundleLayoutDirectoryVariable, value, false); } } public LaunchAction PlannedAction { get; set; } /// /// Creates a correctly configured HTTP web request. /// /// URI to connect to. /// Correctly configured HTTP web request. public HttpWebRequest CreateWebRequest(string uri) { #pragma warning disable SYSLIB0014 // Type or member is obsolete HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); #pragma warning restore SYSLIB0014 // Type or member is obsolete request.UserAgent = String.Concat("WixInstall", this.Version.ToString()); return request; } /// /// Gets the display name for a package if possible. /// /// Identity of the package to find the display name. /// Display name of the package if found or the package id if not. public string GetPackageName(string packageId) { return this.BAManifest.Bundle.Packages.TryGetValue(packageId, out var package) ? package.DisplayName : packageId; } } }