in WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Core/AppDeployment.cs [75:176]
public async Task InstallApplicationAsync(
string appName,
string packageFileName,
List<string> dependencyFileNames,
string certificateFileName = null,
short stateCheckIntervalMs = 500,
short timeoutInMinutes = 15,
bool uninstallPreviousVersion = true)
{
string installPhaseDescription = string.Empty;
try
{
FileInfo packageFile = new FileInfo(packageFileName);
// If appName was not provided, use the package file name
if (string.IsNullOrEmpty(appName))
{
appName = packageFile.Name;
}
// Uninstall the application's previous version, if one exists.
if (uninstallPreviousVersion)
{
installPhaseDescription = string.Format("Uninstalling any previous version of {0}", appName);
this.SendAppInstallStatus(
ApplicationInstallStatus.InProgress,
ApplicationInstallPhase.UninstallingPreviousVersion,
installPhaseDescription);
AppPackages installedApps = await this.GetInstalledAppPackagesAsync();
foreach (PackageInfo package in installedApps.Packages)
{
if (package.Name == appName)
{
await this.UninstallApplicationAsync(package.FullName);
break;
}
}
}
// Create the API endpoint and generate a unique boundary string.
Uri uri;
string boundaryString;
this.CreateAppInstallEndpointAndBoundaryString(
packageFile.Name,
out uri,
out boundaryString);
installPhaseDescription = string.Format("Copying: {0}", packageFile.Name);
this.SendAppInstallStatus(
ApplicationInstallStatus.InProgress,
ApplicationInstallPhase.CopyingFile,
installPhaseDescription);
var content = new HttpMultipartFileContent();
content.Add(packageFile.FullName);
content.AddRange(dependencyFileNames);
content.Add(certificateFileName);
await this.PostAsync(uri, content);
// Poll the status until complete.
ApplicationInstallStatus status = ApplicationInstallStatus.InProgress;
do
{
installPhaseDescription = string.Format("Installing {0}", appName);
this.SendAppInstallStatus(
ApplicationInstallStatus.InProgress,
ApplicationInstallPhase.Installing,
installPhaseDescription);
await Task.Delay(TimeSpan.FromMilliseconds(stateCheckIntervalMs));
status = await this.GetInstallStatusAsync().ConfigureAwait(false);
}
while (status == ApplicationInstallStatus.InProgress);
installPhaseDescription = string.Format("{0} installed successfully", appName);
this.SendAppInstallStatus(
ApplicationInstallStatus.Completed,
ApplicationInstallPhase.Idle,
installPhaseDescription);
}
catch (Exception e)
{
DevicePortalException dpe = e as DevicePortalException;
if (dpe != null)
{
this.SendAppInstallStatus(
ApplicationInstallStatus.Failed,
ApplicationInstallPhase.Idle,
string.Format("Failed to install {0}: {1}", appName, dpe.Reason));
}
else
{
this.SendAppInstallStatus(
ApplicationInstallStatus.Failed,
ApplicationInstallPhase.Idle,
string.Format("Failed to install {0}: {1}", appName, installPhaseDescription));
}
}
}