/// <summary> /// Initializes a new instance of the <see cref="ConnectToDeviceDialog" /> class. /// </summary> /// <param name="options">Options to be used when connectiong to a device.</param> public ConnectToDeviceDialog(ConnectOptions options) { this.connectOptions = options; this.DataContext = new ConnectToDeviceDialogViewModel(options); this.InitializeComponent(); }
/// <summary> /// Implementation of the reconnect to devices command. /// </summary> /// <returns>Task object used for tracking method completion.</returns> private async Task ReconnectToDevicesAsync() { // TODO: allow the user to cancel this if it is taking too long this.reconnected = true; this.suppressSave = true; // Defer updating common apps until all devices have reconnected this.suppressRefreshCommonApps = true; List <ConnectionInformation> connections = await this.LoadConnectionsAsync(); foreach (ConnectionInformation connectionInfo in connections) { ConnectOptions connectOptions = new ConnectOptions( connectionInfo.Address, this.UserName, this.Password, false); await this.ConnectToDeviceAsync( connectOptions, connectionInfo.Name, true); // Do not show the connect dialog on re-connect. } this.suppressRefreshCommonApps = false; this.suppressSave = false; // All known devices have been reconnected, refresh common apps now. await this.RefreshCommonAppsAsync(); this.UpdateCanReconnect(); }
/// <summary> /// Initializes a new instance of the <see cref="ConnectToDeviceDialogViewModel" /> class. /// </summary> public ConnectToDeviceDialogViewModel(ConnectOptions options) { this.Address = options.Address; this.ConnectingToDesktopPC = options.ConnectingToDesktopPC; this.Name = options.Name; this.DeployNameToDevice = options.DeployNameToDevice; // Set the opposite of what we want and call the toggle method. this.ShowCredentials = options.ExpandCredentials ? Visibility.Collapsed : Visibility.Visible; this.ShowHideCredentials(); this.UserName = options.UserName; this.Password = options.Password; // Set the opposite of what we want and call the toggle method. this.ShowNetworkSettings = options.ExpandNetworkSettings ? Visibility.Collapsed : Visibility.Visible; this.ShowHideNetworkSettings(); this.Ssid = options.Ssid; this.NetworkKey = options.NetworkKey; this.UseInstalledCertificate = options.UseInstalledCertificate; this.UpdateConnection = options.UpdateConnection; this.RegisterCommands(); }
/// <summary> /// Implementation of the reconnect to devices command. /// </summary> /// <returns>Task object used for tracking method completion.</returns> private async Task ReconnectToDevicesAsync() { // TODO: allow the user to cancel this if it is taking too long this.reconnected = true; this.suppressSave = true; List <ConnectionInformation> connections = await this.LoadConnectionsAsync(); foreach (ConnectionInformation connectionInfo in connections) { ConnectOptions connectOptions = new ConnectOptions( connectionInfo.Address, this.UserName, this.Password, false); await this.ConnectToDeviceAsync( connectOptions, connectionInfo.Name, true); // Do not show the connect dialog on re-connect. } this.suppressSave = false; this.UpdateCanReconnect(); }
/// <summary> /// Update's the user selected data. /// </summary> /// <param name="connectOptions">The options to be used when connecting to the device.</param> internal void UpdateUserData(ConnectOptions connectOptions) { connectOptions.Address = this.Address; connectOptions.Ssid = this.Ssid; connectOptions.NetworkKey = this.NetworkKey; connectOptions.UpdateConnection = this.UpdateConnection; }
/// <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); } }
/// <summary> /// Update's the user selected data. /// </summary> /// <param name="connectOptions">The options to be used when connecting to the device.</param> internal void UpdateUserData(ConnectOptions connectOptions) { connectOptions.Address = this.Address; connectOptions.ConnectingToDesktopPC = this.ConnectingToDesktopPC; connectOptions.Name = this.Name; connectOptions.DeployNameToDevice = this.DeployNameToDevice; connectOptions.UserName = this.UserName; connectOptions.Password = this.Password; connectOptions.Ssid = this.Ssid; connectOptions.NetworkKey = this.NetworkKey; connectOptions.UseInstalledCertificate = this.UseInstalledCertificate; connectOptions.UpdateConnection = this.UpdateConnection; }
/// <summary> /// Connects to a device. /// </summary> /// <param name="options">Options that specify how the connection is to be established.</param> /// <returns></returns> public async Task ConnectAsync( ConnectOptions options) { this.connectOptions = options; string address = this.connectOptions.Address.ToLower(); if (!address.StartsWith("http")) { string scheme = "https"; if (string.Equals(address, DefaultConnectionAddress) || string.Equals(address, DefaultConnectionAddressAsIp)) { scheme = "http"; } address = string.Format( "{0}://{1}", scheme, address); } if (this.connectOptions.ConnectingToDesktopPC) { string s = address.Substring(address.IndexOf("//")); if (!s.Contains(":")) { // Append the default Windows Device Portal port for Desktop PC connections. address += ":50443"; } } this.devicePortalConnection = new DefaultDevicePortalConnection( address, this.connectOptions.UserName, this.connectOptions.Password); this.devicePortal = new DevicePortal(this.devicePortalConnection); await this.CheckHeartbeatAsync(); }
/// <summary> /// Implementation of the reconnect to devices command. /// </summary> /// <returns>Task object used for tracking method completion.</returns> private async Task ReconnectToDevicesAsync( StorageFile sessionFile = null) { // TODO: allow the user to cancel this if it is taking too long this.reconnected = true; this.suppressSave = true; // Defer updating common apps until all devices have reconnected this.suppressRefreshCommonApps = true; List <ConnectionInformation> connections = await this.ReadSessionFileAync(sessionFile); foreach (ConnectionInformation connectionInfo in connections) { ConnectOptions connectOptions = new ConnectOptions( connectionInfo.Address, connectionInfo.Name, this.UserName, this.Password); connectOptions.UseInstalledCertificate = this.useInstalledCertificate; // Since we are suppressing the UI, we do not need to provide // values for ExpandCredentials or ExpandNetworkSettings. // We assume that since we are reconnecting, the device has previously // been connected to the correct network access point. // Therefore, we are omitting the Ssid and NetworkKey values. await this.ConnectToDeviceAsync( connectOptions, true); // Do not show the connect dialog on re-connect. } this.suppressRefreshCommonApps = false; this.suppressSave = false; // All known devices have been reconnected, refresh common apps now. await this.RefreshCommonAppsAsync(); this.UpdateCanReconnect(); }
/// <summary> /// Connects to a device. /// </summary> /// <param name="connectOptions">Options that specify how the connection is to be established.</param> /// <returns></returns> public async Task ConnectAsync( ConnectOptions connectOptions) { string address = connectOptions.Address.ToLower(); if (!address.StartsWith("http")) { string scheme = "https"; if ((address == DefaultConnectionAddress) || (address == DefaultConnectionAddressAsIp)) { scheme = "http"; } address = string.Format( "{0}://{1}", scheme, address); } this.devicePortalConnection = new DefaultDevicePortalConnection( address, connectOptions.UserName, connectOptions.Password); DevicePortal portal = new DevicePortal(this.devicePortalConnection); portal.ConnectionStatus += DevicePortal_ConnectionStatus; // We are physically connected to the device. // We can safely accept the device's root certificate. Certificate certificate = await portal.GetRootDeviceCertificateAsync(true); // Establish the connection to the device. await portal.ConnectAsync( connectOptions.Ssid, connectOptions.NetworkKey, updateConnection : connectOptions.UpdateConnection, manualCertificate : certificate); }
/// <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); }
/// <summary> /// Connects to a HoloLens. /// </summary> /// <param name="connectOptions">Options that specify how the connection is to be established.</param> /// <returns></returns> public async Task ConnectAsync( ConnectOptions connectOptions) { this.devicePortalConnection = new HoloLensDevicePortalConnection( connectOptions.Address, connectOptions.UserName, connectOptions.Password); DevicePortal portal = new DevicePortal(this.devicePortalConnection); portal.ConnectionStatus += DevicePortal_ConnectionStatus; // We are physically connected to the device. // We can safely accept the device's root certificate. Certificate certificate = await portal.GetRootDeviceCertificateAsync(true); // Establish the connection to the device. // TODO: Add support for optionally setting the SSID and key. await portal.ConnectAsync( null, null, updateConnection : connectOptions.UpdateConnection, manualCertificate : certificate); }
/// <summary> /// Registers commands supported by this object. /// </summary> private void RegisterCommands() { this.CloseAllAppsCommand = new Command( (parameter) => { this.CloseAllApps(); }); this.ConnectToDeviceCommand = new Command( async(parameter) => { ConnectOptions connectOptions = new ConnectOptions( string.Empty, this.UserName, this.Password, false); await this.ConnectToDeviceAsync( connectOptions, string.Empty); }); this.DeselectAllDevicesCommand = new Command( (parameter) => { this.DeselectAllDevices(); }); this.ForgetConnectionsCommand = new Command( async(parameter) => { await this.ForgetAllConnectionsAsync(); }); this.InstallAppCommand = new Command( async(parameter) => { await this.InstallAppAsync(); }); this.LaunchAppCommand = new Command( (parameter) => { this.LaunchApp(); }); this.RefreshCommonAppsCommand = new Command( async(parameter) => { await this.RefreshCommonAppsAsync(); }); this.RebootDevicesCommand = new Command( async(parameter) => { await this.RebootDevicesAsync(); }); this.ReconnectPreviousSessionCommand = new Command( (parameter) => { this.ReconnectPreviousSession(); }); this.SaveMixedRealityFilesCommand = new Command( async(parameter) => { await this.SaveMixedRealityFiles(); }); this.SelectAllDevicesCommand = new Command( (parameter) => { this.SelectAllDevices(); }); this.ShowSetCredentialsCommand = new Command( async(parameter) => { await this.ShowSetCredentials(); }); this.ShutdownDevicesCommand = new Command( async(parameter) => { await this.ShutdownDevicesAsync(); }); this.StartMixedRealityRecordingCommand = new Command( (parameter) => { this.StartMixedRealityRecording(); }); this.StopMixedRealityRecordingCommand = new Command( (parameter) => { this.StopMixedRealityRecording(); }); this.UninstallAppCommand = new Command( (parameter) => { this.UninstallApp(); }); this.UninstallAllAppsCommand = new Command( (parameter) => { this.UninstallAllApps(); }); this.UseAllDevicesFilterCommand = new Command( (parameter) => { this.SelectionFilter = DeviceFilters.All; }); this.UseDesktopFilterCommand = new Command( (parameter) => { this.SelectionFilter = DeviceFilters.Desktop; }); this.UseHoloLensFilterCommand = new Command( (parameter) => { this.SelectionFilter = DeviceFilters.HoloLens; }); this.WipeCameraRollCommand = new Command( (parameter) => { this.WipeCameraRoll(); }); }
/// <summary> /// Registers commands supported by this object. /// </summary> private void RegisterCommands() { this.CloseAllAppsCommand = new Command( (parameter) => { this.CloseAllApps(); }); this.ConnectToDeviceCommand = new Command( async(parameter) => { ConnectOptions connectOptions = new ConnectOptions( string.Empty, this.UserName, this.Password, true); await this.ConnectToDeviceAsync( connectOptions, string.Empty); }); this.DeselectAllDevicesCommand = new Command( (parameter) => { this.DeselectAllDevices(); }); this.ForgetConnectionsCommand = new Command( async(parameter) => { await this.ForgetAllConnectionsAsync(); }); this.InstallAppCommand = new Command( async(parameter) => { await this.InstallAppAsync(); }); this.LaunchAppCommand = new Command( (parameter) => { this.LaunchApp(); }); this.RefreshCommonAppsCommand = new Command( async(parameter) => { await this.RefreshCommonAppsAsync(); }); this.RebootDevicesCommand = new Command( async(parameter) => { await this.RebootDevicesAsync(); }); this.ReconnectToDevicesCommand = new Command( async(parameter) => { await this.ReconnectToDevicesAsync(); }); this.SaveMixedRealityFilesCommand = new Command( async(parameter) => { await this.SaveMixedRealityFiles(); }); this.SelectAllDevicesCommand = new Command( (parameter) => { this.SelectAllDevices(); }); this.ShowConnectContextMenuCommand = new Command( async(parameter) => { await this.ShowConnectContextMenuAsync(parameter); }); this.ShutdownDevicesCommand = new Command( async(parameter) => { await this.ShutdownDevicesAsync(); }); this.StartMixedRealityRecordingCommand = new Command( async(parameter) => { await this.StartMixedRealityRecording(); }); this.StopMixedRealityRecordingCommand = new Command( async(parameter) => { await this.StopMixedRealityRecording(); }); this.UninstallAppCommand = new Command( async(parameter) => { await this.UninstallApp(); }); }
/// <summary> /// Update's the user selected data. /// </summary> /// <param name="connectOptions">The options to be used when connecting to the HoloLens.</param> internal void UpdateUserData(ConnectOptions connectOptions) { connectOptions.Address = this.Address; connectOptions.UpdateConnection = this.UpdateConnection; }
/// <summary> /// Registers commands supported by this object. /// </summary> private void RegisterCommands() { this.ClearDeviceStatusCommand = new Command( async(parameter) => { await this.ClearDeviceStatus(); }); this.ClearStatusMessageCommand = new Command( (parameter) => { this.ClearStatusMessage(); }); this.CloseAllAppsCommand = new Command( (parameter) => { try { this.CloseAllApps(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to close all apps on one or more devices ({0})", e.Message); } }); this.ConnectToDeviceCommand = new Command( async(parameter) => { ConnectOptions connectOptions = new ConnectOptions( string.Empty, string.Empty, this.UserName, this.Password); // TODO: use the full featured constructor connectOptions.ExpandCredentials = this.expandCredentials; connectOptions.ExpandNetworkSettings = this.expandNetworkSettings; connectOptions.UseInstalledCertificate = this.useInstalledCertificate; connectOptions.Ssid = this.defaultSsid; connectOptions.NetworkKey = this.defaultNetworkKey; try { await this.ConnectToDeviceAsync( connectOptions); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to connect to the device ({0})", e.Message); } }); this.DeselectAllDevicesCommand = new Command( (parameter) => { this.DeselectAllDevices(); }); this.ForgetConnectionsCommand = new Command( async(parameter) => { try { await this.ForgetAllConnectionsAsync(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to unregister devices {0}", e.Message); } }); this.InstallAppCommand = new Command( async(parameter) => { try { await this.InstallAppAsync(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to install the app on one or more devices ({0})", e.Message); } }); this.LaunchAppCommand = new Command( (parameter) => { try { this.LaunchApp(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to launch the app on one or more devices ({0})", e.Message); } this.LaunchApp(); }); this.LoadSessionFileCommand = new Command( async(parameter) => { await this.LoadSessionFileAsync(); }); this.RebootDevicesCommand = new Command( async(parameter) => { try { await this.RebootDevicesAsync(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to reboot one or more devices ({0})", e.Message); } }); this.ReconnectPreviousSessionCommand = new Command( (parameter) => { try { this.ReconnectPreviousSession(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to reconnect previous device session ({0})", e.Message); } }); this.RefreshCommonAppsCommand = new Command( async(parameter) => { try { await this.RefreshCommonAppsAsync(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to refresh common applications ({0})", e.Message); } }); this.SaveMixedRealityFilesCommand = new Command( async(parameter) => { try { await this.SaveMixedRealityFiles(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to save Mixed Reality files from one or more devices ({0})", e.Message); } }); this.SaveSessionFileCommand = new Command( async(parameter) => { await this.SaveSessionFile(); }); this.SelectAllDevicesCommand = new Command( (parameter) => { this.SelectAllDevices(); }); this.ShowSetCredentialsCommand = new Command( async(parameter) => { await this.ShowSetCredentials(); }); this.ShowSettingsCommand = new Command( async(paraneter) => { await this.ShowSettings(); }); this.ShutdownDevicesCommand = new Command( async(parameter) => { try { await this.ShutdownDevicesAsync(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to shutdown one or more devices ({0})", e.Message); } }); this.StartMixedRealityRecordingCommand = new Command( (parameter) => { try { this.StartMixedRealityRecording(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to start Mixed Reality recording on one or more devices ({0})", e.Message); } }); this.StopMixedRealityRecordingCommand = new Command( (parameter) => { try { this.StopMixedRealityRecording(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to stop Mixed Reality recording on one or more devices ({0})", e.Message); } }); this.UninstallAppCommand = new Command( (parameter) => { try { this.UninstallApp(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to uninstall an app on one or more devices ({0})", e.Message); } }); this.UninstallAllAppsCommand = new Command( (parameter) => { try { this.UninstallAllApps(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to uninstall all apps on one or more devices ({0})", e.Message); } }); this.UseAllDevicesFilterCommand = new Command( (parameter) => { this.SelectionFilter = DeviceFilters.All; }); this.UseDesktopFilterCommand = new Command( (parameter) => { this.SelectionFilter = DeviceFilters.Desktop; }); this.UseHoloLensFilterCommand = new Command( (parameter) => { this.SelectionFilter = DeviceFilters.HoloLens; }); this.WipeCameraRollCommand = new Command( (parameter) => { try { this.WipeCameraRoll(); } catch (Exception e) { this.StatusMessage = string.Format( "Failed to clear the camera roll on one or more devices ({0})", e.Message); } }); }
/// <summary> /// Initializes a new instance of the <see cref="ConnectToDeviceDialogViewModel" /> class. /// </summary> public ConnectToDeviceDialogViewModel(ConnectOptions options) { this.Address = options.Address; this.UpdateConnection = options.UpdateConnection; }