/// <summary> /// Connects to a HoloLens using the provided credentials. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public async Task ConnectAsync( string address, string userName, string password) { this.devicePortalConnection = new HoloLensDevicePortalConnection( address, userName, password); DevicePortal portal = new DevicePortal(this.devicePortalConnection); portal.ConnectionStatus += DevicePortal_ConnectionStatus; // If the address is localhost (127.0.0.1), we are physically connected // to the HoloLens. This allows us to implicitly trust the device // certificate. // // !! NOTE: UWP applications are not allowed to connect to localhost // unless explicitly configured. // * Development - Visual Studio performs this configuration automatically. // * Side-loading - Please see README.md for more details. // * Store submissions - Use only non-loopback connections. 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 : true, manualCertificate : certificate); }
/// <summary> /// Connects to a HoloLens using the provided credentials. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns></returns> public async Task ConnectAsync( string address, string userName, string password) { this.devicePortalConnection = new HoloLensDevicePortalConnection( address, userName, 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 : true, manualCertificate : certificate); }
/// <summary> /// TextChanged handler for the address text box. /// </summary> /// <param name="sender">The caller of this method.</param> /// <param name="e">The arguments associated with this event.</param> private async void btnTakePicture2_Click(object sender, RoutedEventArgs e) { portal = new DevicePortal( new DefaultDevicePortalConnection(HoloLensUrl, "Tolegen", "*****")); StringBuilder sb = new StringBuilder(); sb.Append(this.messageb.Text); sb.AppendLine("Connecting..."); this.messageb.Text = sb.ToString(); portal.ConnectionStatus += (portal, connectArgs) => { if (connectArgs.Status == DeviceConnectionStatus.Connected) { sb.Append("Connected to: "); sb.AppendLine(portal.Address); sb.Append("OS version: "); sb.AppendLine(portal.OperatingSystemVersion); sb.Append("Device family: "); sb.AppendLine(portal.DeviceFamily); sb.Append("Platform: "); sb.AppendLine(String.Format("{0} ({1})", portal.PlatformName, portal.Platform.ToString())); } else if (connectArgs.Status == DeviceConnectionStatus.Failed) { sb.AppendLine("Failed to connect to the device."); sb.AppendLine(connectArgs.Message); } }; try { // If the user wants to allow untrusted connections, make a call to GetRootDeviceCertificate // with acceptUntrustedCerts set to true. This will enable untrusted connections for the // remainder of this session. this.certificate = await portal.GetRootDeviceCertificateAsync(true); await portal.ConnectAsync(manualCertificate : this.certificate); } catch (Exception exception) { sb.AppendLine(exception.Message); } this.messageb.Text = sb.ToString(); }
public async Task ConnectAsync() { if (_devicePortal != null) { _devicePortal.ConnectionStatus -= DevicePortal_ConnectionStatus; } // 入力された情報をもとに接続 _devicePortal = new DevicePortal(new DefaultDevicePortalConnection(Address, UserName, Password)); _devicePortal.ConnectionStatus += DevicePortal_ConnectionStatus; try { // 証明書をデバイスポータルから取得して、それを使って接続を行う await _devicePortal.ConnectAsync(manualCertificate : await _devicePortal.GetRootDeviceCertificateAsync(true)); } catch (Exception ex) { Message = ex.Message; Debug.WriteLine(ex); } }
/// <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> /// Click handler for the connectToDevice button. /// </summary> /// <param name="sender">The caller of this method.</param> /// <param name="e">The arguments associated with this event.</param> private async void ConnectToDevice_Click(object sender, RoutedEventArgs e) { this.EnableConnectionControls(false); this.EnableDeviceControls(false); this.ClearOutput(); bool allowUntrusted = this.allowUntrustedCheckbox.IsChecked.Value; portal = new DevicePortal( new DefaultDevicePortalConnection( this.address.Text, this.username.Text, this.password.Password)); StringBuilder sb = new StringBuilder(); sb.Append(this.commandOutput.Text); sb.AppendLine("Connecting..."); this.commandOutput.Text = sb.ToString(); portal.ConnectionStatus += (portal, connectArgs) => { if (connectArgs.Status == DeviceConnectionStatus.Connected) { sb.Append("Connected to: "); sb.AppendLine(portal.Address); sb.Append("OS version: "); sb.AppendLine(portal.OperatingSystemVersion); sb.Append("Device family: "); sb.AppendLine(portal.DeviceFamily); sb.Append("Platform: "); sb.AppendLine(String.Format("{0} ({1})", portal.PlatformName, portal.Platform.ToString())); } else if (connectArgs.Status == DeviceConnectionStatus.Failed) { sb.AppendLine("Failed to connect to the device."); sb.AppendLine(connectArgs.Message); } }; try { // If the user wants to allow untrusted connections, make a call to GetRootDeviceCertificate // with acceptUntrustedCerts set to true. This will enable untrusted connections for the // remainder of this session. if (allowUntrusted) { this.certificate = await portal.GetRootDeviceCertificateAsync(true); } await portal.ConnectAsync(manualCertificate : this.certificate); } catch (Exception exception) { sb.AppendLine(exception.Message); } this.commandOutput.Text = sb.ToString(); EnableDeviceControls(true); EnableConnectionControls(true); }