Example #1
0
        private async Task <bool> TryAuthenticateAsync()
        {
            try
            {
                // Create portal object
                var portal = new DevicePortal(
                    new DefaultDevicePortalConnection(
                        "https://127.0.0.1",
                        UserNameBox.Text,
                        PasswordBox.Password));

                // Attempt to connect
                await portal.Connect();

                // Get IPD
                var ipd = await portal.GetInterPupilaryDistance();

                // Success!
                return(true);
            }
            catch (Exception ex)
            {
                // Problem
                await new MessageDialog(ex.Message, "Error").ShowAsync();
                return(false);
            }
        }
Example #2
0
        private async Task <bool> TryAuthenticateAsync()
        {
            try
            {
                // Create portal object
                portal = new DevicePortal(
                    new DefaultDevicePortalConnection(
                        "https://127.0.0.1",
                        UserNameBox.Text,
                        PasswordBox.Password));

                // Get cert (OK to use untrusted since it's loopback)
                await portal.GetRootDeviceCertificate(acceptUntrustedCerts : true);

                // Attempt to connect
                await portal.Connect();

                // Get IPD
                var ipd = await portal.GetInterPupilaryDistance();

                // Success!
                return(true);
            }
            catch (Exception)
            {
                // Problem
                await new MessageDialog("Authentication was not successful. Please make sure Device Portal is enabled and check your password.", "Error").ShowAsync();
                return(false);
            }
        }
Example #3
0
    private async Task <bool> AuthSilentAsync()
    {
        // Placeholder
        PasswordCredential cred = null;

        // Try to get user name and password
        try
        {
            cred = vault.FindAllByResource(PortalResourceName).FirstOrDefault();

            // Password does not come across with the method above. We must call another method.
            if (cred != null)
            {
                cred = vault.Retrieve(PortalResourceName, cred.UserName);
            }
        }
        catch { }

        // If no credentials were found, fail
        if (cred == null)
        {
            return(false);
        }

        // Credentials found. Try and log into portal
        try
        {
            // Create portal object
            portal = new DevicePortal(
                new DefaultDevicePortalConnection(
                    "https://127.0.0.1",
                    cred.UserName,
                    cred.Password));

            // Get cert (OK to use untrusted since it's loopback)
            await portal.GetRootDeviceCertificate(acceptUntrustedCerts : true);

            // Attempt to connect
            await portal.Connect();

            // Get IPD
            var ipd = await portal.GetInterPupilaryDistance();

            // Success!
            return(true);
        }
        catch (Exception ex)
        {
            // Problem
            ShowError(ex.Message);
            return(false);
        }
    }
Example #4
0
    private async void ReadValues()
    {
        try
        {
            // Get IPD
            float ipd = await portal.GetInterPupilaryDistance();

            // Show IPD
            ShowIpd(ipd);
        }
        catch (Exception ex)
        {
            // Show error on Unity thread
            ShowError(ex.Message);
        }
    }