// 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.UX
{
using System;
using System.Collections.Generic;
using System.Net;
using WixToolset.Bootstrapper;
///
/// 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 UX.
///
/// Bootstrapper hosting the UX.
public Model(BootstrapperApplication bootstrapper)
{
this.Bootstrapper = bootstrapper;
this.Telemetry = new List>();
this.Version = this.Engine.VersionVariables[BurnBundleVersionVariable];
}
///
/// Gets the bootstrapper.
///
public BootstrapperApplication Bootstrapper { get; private set; }
///
/// Gets the bootstrapper command-line.
///
public Command Command { get { return this.Bootstrapper.Command; } }
///
/// Gets the bootstrapper engine.
///
public Engine Engine { get { return this.Bootstrapper.Engine; } }
///
/// 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 Version Version { get; private set; }
///
/// Get or set the path where the bundle is installed.
///
public string InstallDirectory
{
get
{
if (!this.Engine.StringVariables.Contains(BurnBundleInstallDirectoryVariable))
{
return null;
}
return this.Engine.StringVariables[BurnBundleInstallDirectoryVariable];
}
set
{
this.Engine.StringVariables[BurnBundleInstallDirectoryVariable] = value;
}
}
///
/// Get or set the path for the layout to be created.
///
public string LayoutDirectory
{
get
{
if (!this.Engine.StringVariables.Contains(BurnBundleLayoutDirectoryVariable))
{
return null;
}
return this.Engine.StringVariables[BurnBundleLayoutDirectoryVariable];
}
set
{
this.Engine.StringVariables[BurnBundleLayoutDirectoryVariable] = value;
}
}
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)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
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)
{
PackageInfo package;
return this.Bootstrapper.BAManifest.Bundle.Packages.TryGetValue(packageId, out package) ? package.DisplayName : packageId;
}
}
}