/// <summary>
        /// Implementation of the connect to device command.
        /// </summary>
        /// <param name="connectOptions">Options used when connecting to the device.</param>
        /// <param name="name">Descriptive name to assign to the device.</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 = DeviceMonitor.DefaultConnectionAddress;
            }

            DeviceMonitor monitor = new DeviceMonitor(this.dispatcher);

            try
            {
                this.StatusMessage = string.Format(
                    "Connecting to the device at {0}",
                    connectOptions.Address);

                await monitor.ConnectAsync(connectOptions);

                await this.RegisterDeviceAsync(
                    monitor,
                    name);

                await this.RefreshCommonAppsAsync();

                this.StatusMessage = "";
            }
            catch
            {
                string addr = connectOptions.Address;
                if (connectOptions.Address == DeviceMonitor.DefaultConnectionAddress)
                {
                    addr = "the attached device";
                }

                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="connectOptions">Options used when connecting to the device.</param>
        /// <param name="name">Descriptive name to assign to the device.</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 = DeviceMonitor.DefaultConnectionAddress;
            }

            DeviceMonitor monitor = new DeviceMonitor(this.dispatcher);

            this.StatusMessage = string.Format(
                "Connecting to the device at {0}",
                connectOptions.Address);

            await monitor.ConnectAsync(connectOptions);

            this.StatusMessage = "";

            await this.RegisterDeviceAsync(
                monitor,
                name);
        }