Esempio n. 1
0
        /// <summary>
        /// Called when custom pairing is initiated so that we can handle the custom ceremony
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void PairingRequestedHandler(
            DeviceInformationCustomPairing sender,
            DevicePairingRequestedEventArgs args)
        {
            // Save the args for use in ProvidePin case
            pairingRequestedHandlerArgs = args;

            // Save the deferral away and complete it where necessary.
            if (args.PairingKind != DevicePairingKinds.DisplayPin)
            {
                deferral = args.GetDeferral();
            }

            string confirmationMessage;

            switch (args.PairingKind)
            {
            case DevicePairingKinds.ConfirmOnly:
                // Windows itself will pop the confirmation dialog as part of "consent" if this is running on Desktop or Mobile
                // If this is an App for Athens where there is no Windows Consent UX, you may want to provide your own confirmation.
            {
                confirmationMessage = string.Format(bluetoothConfirmOnlyFormatString, args.DeviceInformation.Name, args.DeviceInformation.Id);
                DisplayMessagePanelAsync(confirmationMessage, MessageType.InformationalMessage);
                // Accept the pairing which also completes the deferral
                AcceptPairing();
            }
            break;

            case DevicePairingKinds.DisplayPin:
                // We just show the PIN on this side. The ceremony is actually completed when the user enters the PIN
                // on the target device
            {
                confirmationMessage = string.Format(bluetoothDisplayPinFormatString, args.Pin);
                DisplayMessagePanelAsync(confirmationMessage, MessageType.OKMessage);
            }
            break;

            case DevicePairingKinds.ProvidePin:
                // A PIN may be shown on the target device and the user needs to enter the matching PIN on
                // this Windows device.
                await MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    // PIN Entry
                    inProgressPairButton.Flyout = savedPairButtonFlyout;
                    inProgressPairButton.Flyout.ShowAt(inProgressPairButton);
                });

                break;

            case DevicePairingKinds.ConfirmPinMatch:
                // We show the PIN here and the user responds with whether the PIN matches what they see
                // on the target device. Response comes back and we set it on the PinComparePairingRequestedData
                // then complete the deferral.
            {
                confirmationMessage = string.Format(bluetoothConfirmPinMatchFormatString, args.Pin);
                DisplayMessagePanelAsync(confirmationMessage, MessageType.YesNoMessage);
            }
            break;
            }
        }
Esempio n. 2
0
 private void AcceptPairingWithPIN(string PIN)
 {
     if (pairingRequestedHandlerArgs != null)
     {
         pairingRequestedHandlerArgs.Accept(PIN);
         pairingRequestedHandlerArgs = null;
     }
     // Complete the deferral here
     CompleteDeferral();
 }
Esempio n. 3
0
 /// <summary>
 /// Accept the pairing and complete the deferral
 /// </summary>
 private void AcceptPairing()
 {
     if (pairingRequestedHandlerArgs != null)
     {
         pairingRequestedHandlerArgs.Accept();
         pairingRequestedHandlerArgs = null;
     }
     // Complete deferral
     CompleteDeferral();
 }
Esempio n. 4
0
 private void AcceptPairingWithPIN(string PIN)
 {
     if (pairingRequestedHandlerArgs != null)
     {
         pairingRequestedHandlerArgs.Accept(PIN);
         pairingRequestedHandlerArgs = null;
     }
     // Complete the deferral here
     CompleteDeferral();
 }
Esempio n. 5
0
        /// <summary>
        /// Called when custom pairing is initiated so that we can handle the custom ceremony
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void PairingRequestedHandler(
            DeviceInformationCustomPairing sender,
            DevicePairingRequestedEventArgs args)
        {
            // Save the args for use in ProvidePin case
            pairingRequestedHandlerArgs = args;

            // Save the deferral away and complete it where necessary.
            if (args.PairingKind != DevicePairingKinds.DisplayPin)
            {
                deferral = args.GetDeferral();
            }

            string confirmationMessage;

            switch (args.PairingKind)
            {
                case DevicePairingKinds.ConfirmOnly:
                    // Windows itself will pop the confirmation dialog as part of "consent" if this is running on Desktop or Mobile
                    // If this is an App for Athens where there is no Windows Consent UX, you may want to provide your own confirmation.
                    {
                        confirmationMessage = string.Format(bluetoothConfirmOnlyFormatString, args.DeviceInformation.Name, args.DeviceInformation.Id);
                        DisplayMessagePanel(confirmationMessage, MessageType.InformationalMessage);
                        // Accept the pairing which also completes the deferral
                        AcceptPairing();
                    }
                    break;

                case DevicePairingKinds.DisplayPin:
                    // We just show the PIN on this side. The ceremony is actually completed when the user enters the PIN
                    // on the target device
                    {
                        confirmationMessage = string.Format(bluetoothDisplayPinFormatString, args.Pin);
                        DisplayMessagePanel(confirmationMessage, MessageType.OKMessage);
                    }
                    break;

                case DevicePairingKinds.ProvidePin:
                    // A PIN may be shown on the target device and the user needs to enter the matching PIN on 
                    // this Windows device.
                    await MainPage.Current.UIThreadDispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        // PIN Entry
                        inProgressPairButton.Flyout = savedPairButtonFlyout;
                        inProgressPairButton.Flyout.ShowAt(inProgressPairButton);
                    });
                    break;

                case DevicePairingKinds.ConfirmPinMatch:
                    // We show the PIN here and the user responds with whether the PIN matches what they see
                    // on the target device. Response comes back and we set it on the PinComparePairingRequestedData
                    // then complete the deferral.
                    {
                        confirmationMessage = string.Format(bluetoothConfirmPinMatchFormatString, args.Pin);
                        DisplayMessagePanel(confirmationMessage, MessageType.YesNoMessage);
                    }
                    break;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Accept the pairing and complete the deferral
 /// </summary>
 private void AcceptPairing()
 {
     if (pairingRequestedHandlerArgs != null)
     {
         pairingRequestedHandlerArgs.Accept();
         pairingRequestedHandlerArgs = null;
     }
     // Complete deferral
     CompleteDeferral();
 }