/// <summary> /// Uninstalls all side-loaded apps on selected devices /// </summary> /// <returns></returns> internal async Task UninstallAllAppsAsync() { if (this.IsConnected && this.IsSelected) { try { AppPackages installedApps = await this.deviceMonitor.GetInstalledApplicationsAsync(); foreach (PackageInfo packageInfo in installedApps.Packages) { if (packageInfo.IsSideloaded()) { await this.deviceMonitor.UninstallApplicationAsync(packageInfo.FullName); } } this.StatusMessage = "Successfully uninstalled all apps."; this.deviceMonitorControl.NotifyAppUninstall(); } catch (Exception e) { this.StatusMessage = string.Format("Failed to uninstall all apps. {0} ", e.Message); } } }
/// <summary> /// Unintalls an application on this HoloLens. /// </summary> /// <returns>Task object used for tracking method completion.</returns> internal async Task UninstallAppAsync(string appName) { if (this.IsConnected && this.IsSelected) { try { AppPackages installedApps = await this.holoLensMonitor.GetInstalledApplicationsAsync(); string packageName = Utilities.GetPackageNameFromAppName( appName, installedApps); if (packageName == null) { throw new Exception( string.Format("App ({0}) could not be found", appName)); } await this.holoLensMonitor.UninstallApplicationAsync(packageName); this.StatusMessage = "Uninstall complete"; } catch (Exception e) { this.StatusMessage = string.Format( "Failed to uninstall {0} - {1}", appName, e.Message); } } }
/// <summary> /// Find the installed application name that is associated with the specified package name. /// </summary> /// <param name="packageName">Name of the application package.</param> /// <returns>The application display name, or null if not found.</returns> private async Task <string> FindAppNameFromPackageName(string packageName) { string appName = null; // Get the collection of installed applications. AppPackages apps = await this.GetInstalledApplicationsAsync(); // Remove the version/plaform from the package name and squash string squashedPackageName = SquashPackageName(packageName); foreach (PackageInfo package in apps.Packages) { // Squash the name so there are no underscores or spaces string squashedName = SquashName(package.FamilyName); // Try to match with the squashed package name if (squashedPackageName == squashedName) { appName = package.Name; break; } } // Return the un-squashed name return(appName); }
private void ResetInternals() { this.CurrentPackageFullName = null; this.currentFolderName = null; this.currentFolderContents = null; this.currentAppPackages = null; this.PackageSelector.Items.Clear(); this.FileList.Items.Clear(); }
/// <summary> /// Implementation of the refresh installed applications command. /// </summary> /// <returns>Task object used for tracking method completion.</returns> private async Task RefreshInstalledAppsAsync() { AppPackages installedApps = await this.deviceMonitor.GetInstalledApplicationsAsync(); List <string> appNames = Utilities.GetAppNamesFromPackageInfo( installedApps.Packages, true); this.UpdateInstalledApps(appNames); }
async private void FetchPackageNames() { this.PackageSelector.Items.Clear(); this.currentAppPackages = await this.portal.GetInstalledAppPackagesAsync(); for (int i = 0; i < this.currentAppPackages.Packages.Count; i++) { this.PackageSelector.Items.Add(this.currentAppPackages.Packages.ElementAt(i).Name); } }
/// <summary> /// Implementation of the refresh installed applications command. /// </summary> /// <returns>Task object used for tracking method completion.</returns> private async Task RefreshInstalledAppsAsync() { //this.StatusMessage = "Refreshing list of installed apps."; AppPackages installedApps = await this.holoLensMonitor.GetInstalledApplicationsAsync(); List <string> appNames = Utilities.GetAppNamesFromPackageInfo( installedApps.Packages, true); this.UpdateInstalledApps(appNames); }
/// <summary> /// Launches an applicaiton on this HoloLens. /// </summary> /// <param name="appName">The name of the application to launch.</param> /// <returns>The process identifier of the running application.</returns> internal async Task <int> LaunchAppAsync(string appName) { int processId = 0; if (this.IsConnected && this.IsSelected) { try { string appId = null; string packageName = null; AppPackages installedApps = await this.holoLensMonitor.GetInstalledApplicationsAsync(); foreach (PackageInfo packageInfo in installedApps.Packages) { if (appName == packageInfo.Name) { appId = packageInfo.AppId; packageName = packageInfo.FullName; break; } } if (!string.IsNullOrWhiteSpace(appId) && !string.IsNullOrWhiteSpace(packageName)) { processId = await this.holoLensMonitor.LaunchApplicationAsync( appId, packageName); } Task t = new Task( async() => { await WatchProcess(processId, appName, 2); }); t.Start(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to launch {0} - {1}", appName, e.Message); } } return(processId); }
/// <summary> /// Returns the application package name associated with the specified application name. /// </summary> /// <param name="appName">Name of the application for which the package name is to be returned.</param> /// <param name="appPackages">Collection of application packages to be searched.</param> /// <returns>The application package name.</returns> public static string GetPackageNameFromAppName( string appName, AppPackages appPackages) { string packageName = null; foreach (PackageInfo packageInfo in appPackages.Packages) { if (packageInfo.Name == appName) { packageName = packageInfo.FullName; break; } } return(packageName); }
/// <summary> /// Queries the device for the names of all installed applications. /// </summary> /// <returns>List of application names.</returns> internal async Task <List <string> > GetInstalledAppNamesAsync() { List <string> appNames = new List <string>(); if (this.IsConnected && this.IsSelected) { try { AppPackages installedApps = await this.deviceMonitor.GetInstalledApplicationsAsync(); appNames = Utilities.GetAppNamesFromPackageInfo( installedApps.Packages, true); } catch { } } return(appNames); }
/// <summary> /// Queries the HoloLens for the names of all installed applications. /// </summary> /// <returns>List of application names.</returns> internal async Task <List <string> > GetInstalledAppNamesAsync() { List <string> appNames = new List <string>(); // Whether or not a device is selected, we still need to know what apps it has installed if (this.IsConnected) { try { AppPackages installedApps = await this.holoLensMonitor.GetInstalledApplicationsAsync(); appNames = Utilities.GetAppNamesFromPackageInfo( installedApps.Packages, true); } catch { } } return(appNames); }
/// <summary> /// Installs an application /// </summary> /// <param name="appName">Friendly name (ex: Hello World) of the application. If this parameter is not provided, the name of the package is assumed to be the app name.</param> /// <param name="packageFileName">Full name of the application package file.</param> /// <param name="dependencyFileNames">List containing the full names of any required dependency files.</param> /// <param name="certificateFileName">Full name of the optional certificate file.</param> /// <param name="stateCheckIntervalMs">How frequently we should check the installation state.</param> /// <param name="timeoutInMinutes">Operation timeout.</param> /// <param name="uninstallPreviousVersion">Indicate whether or not the previous app version should be uninstalled prior to installing.</param> /// <remarks>InstallApplication sends ApplicationInstallStatus events to indicate the current progress in the installation process. /// Some applications may opt to not register for the AppInstallStatus event and await on InstallApplication.</remarks> /// <returns>Task for tracking completion of install initialization.</returns> public async Task InstallApplication( 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.GetInstalledAppPackages(); foreach (PackageInfo package in installedApps.Packages) { if (package.Name == appName) { await this.UninstallApplication(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); using (MemoryStream dataStream = new MemoryStream()) { byte[] data; // Copy the application package. installPhaseDescription = string.Format("Copying: {0}", packageFile.Name); this.SendAppInstallStatus( ApplicationInstallStatus.InProgress, ApplicationInstallPhase.CopyingFile, installPhaseDescription); data = Encoding.ASCII.GetBytes(string.Format("--{0}\r\n", boundaryString)); dataStream.Write(data, 0, data.Length); CopyFileToRequestStream(packageFile, dataStream); // Copy dependency files, if any. foreach (string dependencyFile in dependencyFileNames) { FileInfo fi = new FileInfo(dependencyFile); installPhaseDescription = string.Format("Copying: {0}", fi.Name); this.SendAppInstallStatus( ApplicationInstallStatus.InProgress, ApplicationInstallPhase.CopyingFile, installPhaseDescription); data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}\r\n", boundaryString)); dataStream.Write(data, 0, data.Length); CopyFileToRequestStream(fi, dataStream); } // Copy the certificate file, if provided. if (!string.IsNullOrEmpty(certificateFileName)) { FileInfo fi = new FileInfo(certificateFileName); installPhaseDescription = string.Format("Copying: {0}", fi.Name); this.SendAppInstallStatus( ApplicationInstallStatus.InProgress, ApplicationInstallPhase.CopyingFile, installPhaseDescription); data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}\r\n", boundaryString)); dataStream.Write(data, 0, data.Length); CopyFileToRequestStream(fi, dataStream); } // Close the installation request data. data = Encoding.ASCII.GetBytes(string.Format("\r\n--{0}--\r\n", boundaryString)); dataStream.Write(data, 0, data.Length); dataStream.Position = 0; string contentType = string.Format("multipart/form-data; boundary={0}", boundaryString); // Make the HTTP request. await this.Post(uri, dataStream, contentType); } // 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.GetInstallStatus(); }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)); } } }
/// <summary> /// Installs an application /// </summary> /// <param name="appName">Friendly name (ex: Hello World) of the application. If this parameter is not provided, the name of the package is assumed to be the app name.</param> /// <param name="packageFileName">Full name of the application package file.</param> /// <param name="dependencyFileNames">List containing the full names of any required dependency files.</param> /// <param name="certificateFileName">Full name of the optional certificate file.</param> /// <param name="stateCheckIntervalMs">How frequently we should check the installation state.</param> /// <param name="timeoutInMinutes">Operation timeout.</param> /// <param name="uninstallPreviousVersion">Indicate whether or not the previous app version should be uninstalled prior to installing.</param> /// <remarks>InstallApplication sends ApplicationInstallStatus events to indicate the current progress in the installation process. /// Some applications may opt to not register for the AppInstallStatus event and await on InstallApplication.</remarks> /// <returns>Task for tracking completion of install initialization.</returns> 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(); await content.Add(packageFile.FullName); await content.AddRange(dependencyFileNames); await 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)); } } }