/// <summary>
        /// Implementation of the connect to device command.
        /// </summary>
        /// <param name="connectOptions">Options used when connecting to the HoloLens.</param>
        /// <param name="name">Descriptive name to assign to the HoloLens.</param>
        /// <param name="suppressDialog">True causes the connection dialog to not be shown./param>
        /// <returns>Task object used for tracking method completion.</returns>
        private async Task ConnectToDeviceAsync(
            ConnectOptions connectOptions,
            string name,
            bool suppressDialog = false)
        {
            this.StatusMessage = string.Empty;

            if (!suppressDialog)
            {
                ContentDialog       dialog = new ConnectToDeviceDialog(connectOptions);
                ContentDialogResult result = await dialog.ShowAsync().AsTask <ContentDialogResult>();

                // Primary button == "Ok"
                if (result != ContentDialogResult.Primary)
                {
                    // The user decided not to connect.
                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(connectOptions.Address))
            {
                connectOptions.Address = DefaultConnectionAddress;
            }

            HoloLensMonitor monitor = new HoloLensMonitor(this.dispatcher);

            try
            {
                await monitor.ConnectAsync(connectOptions);

                await this.RegisterHoloLensAsync(
                    monitor,
                    name);

                await this.RefreshCommonAppsAsync();

                this.StatusMessage = string.Format(
                    "Connected to the HoloLens at {0}",
                    monitor.Address);
            }
            catch
            {
                string addr = connectOptions.Address;
                if (connectOptions.Address == "localhost:10080")
                {
                    addr = "the attached HoloLens";
                }

                this.StatusMessage = string.Format(
                    "Failed to connect to {0}. Is it powered on? Paired with the Windows Device Portal?",
                    addr);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Implementation of the connect to device command.
        /// </summary>
        /// <param name="address">The address of the HoloLens.</param>
        /// <param name="name">Descriptive name to assign to the HoloLens.</param>
        /// <returns>Task object used for tracking method completion.</returns>
        private async Task ConnectToDeviceAsync(
            string address,
            string name)
        {
            HoloLensMonitor monitor = new HoloLensMonitor(this.dispatcher);

            try
            {
                await monitor.ConnectAsync(
                    address,
                    this.UserName,
                    this.Password);

                await this.RegisterHoloLensAsync(
                    monitor,
                    name);

                await this.RefreshCommonAppsAsync();

                this.StatusMessage = string.Format(
                    "Connected to the HoloLens at {0}",
                    monitor.Address);
            }
            catch
            {
                string addr = address;
                if (address == "localhost:10080")
                {
                    addr = "the attached HoloLens";
                }

                this.StatusMessage = string.Format(
                    "Failed to connect to {0}. Is it powered on? Paired with the Windows Device Portal?",
                    addr);
            }
        }