private void ExecuteListInstalledAppsOperation(ParameterHelper parameters)
        {
            Task <AppPackages> packagesTask = _portal.GetInstalledAppPackagesAsync();

            packagesTask.Wait();

            var packages = packagesTask.Result;

            Console.Out.WriteLine(packages.ToString());
        }
        /// <summary>
        /// Click handler for the shutdownDevice button.
        /// </summary>
        /// <param name="sender">The caller of this method.</param>
        /// <param name="e">The arguments associated with this event.</param>
        private void ShutdownDevice_Click(object sender, RoutedEventArgs e)
        {
            bool reenableDeviceControls = false;

            this.ClearOutput();
            this.EnableConnectionControls(false);
            this.EnableDeviceControls(false);

            StringBuilder sb           = new StringBuilder();
            Task          shutdownTask = new Task(
                async() =>
            {
                sb.Append(this.MarshalGetCommandOutput());
                sb.AppendLine("Shutting down the device");
                this.MarshalUpdateCommandOutput(sb.ToString());

                try
                {
                    Task <AppPackages> packagesTask = portal.GetInstalledAppPackagesAsync();

                    packagesTask.Wait();
                    foreach (var p in packagesTask.Result.Packages)
                    {
                        sb.AppendLine(p.FullName);
                    }
                    this.MarshalUpdateCommandOutput(sb.ToString());

                    await this.portal.TerminateApplicationAsync("Microsoft.RemoteDesktop_10.2.1636.0_x64__8wekyb3d8bbwe");
                }
                catch (Exception ex)
                {
                    sb.AppendLine("Failed to shut down the device.");
                    sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message);
                    reenableDeviceControls = true;
                }

                this.MarshalUpdateCommandOutput(sb.ToString());
            });

            Task continuationTask = shutdownTask.ContinueWith(
                (t) =>
            {
                this.MarshalEnableDeviceControls(reenableDeviceControls);
                this.MarshalEnableConnectionControls(true);
            });

            shutdownTask.Start();
        }
Example #3
0
        public async Task UpdateApplicationsAsync()
        {
            if (_devicePortal == null || !IsConnected)
            {
                Message = "Update app list failed.";
                return;
            }

            Applications.Clear();
            // インストールされているアプリを取得
            var appPackages = await _devicePortal.GetInstalledAppPackagesAsync();

            var apps = appPackages.Packages.Select(x => new HoloLensApplication(x.AppId, x.Name, x.FullName));

            foreach (var app in apps)
            {
                Applications.Add(app);
            }
        }
        /// <summary>
        /// Main entry point for handling a Config operation
        /// </summary>
        /// <param name="portal">DevicePortal reference for communicating with the device.</param>
        /// <param name="parameters">Parsed command line parameters.</param>
        public static void HandleOperation(DevicePortal portal, ParameterHelper parameters)
        {
            if (parameters.HasFlag(ParameterHelper.HelpFlag))
            {
                Console.WriteLine(AppUsageMessage);
                return;
            }

            string operationType = parameters.GetParameterValue("subop");

            if (string.IsNullOrWhiteSpace(operationType))
            {
                Console.WriteLine("Missing subop parameter");
                Console.WriteLine();
                Console.WriteLine(AppUsageMessage);
                return;
            }

            operationType = operationType.ToLowerInvariant();

            try
            {
                if (operationType.Equals("list"))
                {
                    Task <AppPackages> packagesTask = portal.GetInstalledAppPackagesAsync();

                    packagesTask.Wait();
                    Console.WriteLine(packagesTask.Result);
                }
                else
                {
                    string packageFullName = parameters.GetParameterValue("pfn");

                    if (string.IsNullOrEmpty(packageFullName))
                    {
                        Console.WriteLine("The Package Full Name is required as the /pfn<packageFullName> parameter for this operation.");
                        Console.WriteLine();
                        Console.WriteLine(AppUsageMessage);
                        return;
                    }

                    if (operationType.Equals("suspend"))
                    {
                        Console.WriteLine("Suspend isn't currently supported, but will be in the future.");
                    }
                    else if (operationType.Equals("resume"))
                    {
                        Console.WriteLine("Resume isn't currently supported, but will be in the future.");
                    }
                    else if (operationType.Equals("launch"))
                    {
                        string aumid = parameters.GetParameterValue("aumid");
                        if (string.IsNullOrEmpty(aumid))
                        {
                            Console.WriteLine("The appId (AUMID) is required as the /aumid:<appId> parameter for the launch operation.");
                            Console.WriteLine();
                            Console.WriteLine(AppUsageMessage);
                            return;
                        }

                        Task launchTask = portal.LaunchApplicationAsync(aumid, packageFullName);
                        launchTask.Wait();

                        Console.WriteLine("Application launched.");
                    }
                    else if (operationType.Equals("terminate"))
                    {
                        Task terminateTask = portal.TerminateApplicationAsync(packageFullName);
                        terminateTask.Wait();

                        Console.WriteLine("Application terminated.");
                    }
                    else if (operationType.Equals("uninstall"))
                    {
                        Task uninstallTask = portal.UninstallApplicationAsync(packageFullName);
                        uninstallTask.Wait();

                        Console.WriteLine("Application uninstalled.");
                    }
                }
            }
            catch (AggregateException e)
            {
                if (e.InnerException is DevicePortalException)
                {
                    DevicePortalException innerException = e.InnerException as DevicePortalException;

                    Console.WriteLine(string.Format("Exception encountered: 0x{0:X} : {1}", innerException.HResult, innerException.Reason));
                }
                else if (e.InnerException is OperationCanceledException)
                {
                    Console.WriteLine("The operation was cancelled.");
                }
                else
                {
                    Console.WriteLine(string.Format("Unexpected exception encountered: {0}", e.Message));
                }

                return;
            }
        }