コード例 #1
0
        public static async void HandlePairing(CoreDispatcher dispatcher, DevicePairingRequestedEventArgs args)
        {
            using (Deferral deferral = args.GetDeferral())
            {
                switch (args.PairingKind)
                {
                case DevicePairingKinds.DisplayPin:
                    await ShowPinToUserAsync(dispatcher, args.Pin);

                    args.Accept();
                    break;

                case DevicePairingKinds.ConfirmOnly:
                    args.Accept();
                    break;

                case DevicePairingKinds.ProvidePin:
                {
                    string pin = await GetPinFromUserAsync(dispatcher);

                    if (String.IsNullOrEmpty(pin))
                    {
                        args.Accept(pin);
                    }
                }
                break;
                }
            }
        }
コード例 #2
0
        private static void PairingRequestedHandler(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args, string pin)
        {
            switch (args.PairingKind)
            {
            case DevicePairingKinds.ConfirmOnly:
                Console.WriteLine("Pairing mode: ConfirmOnly");
                args.Accept();
                return;

            case DevicePairingKinds.ProvidePin:
                Console.WriteLine("Pairing mode: ProvidePin");
                Console.WriteLine($"Pin is requested by the device. Using '{pin}' as a pin code");
                args.Accept(pin);
                return;

            case DevicePairingKinds.ConfirmPinMatch:
                Console.WriteLine("Pairing mode: ConfirmPinMatch");
                Console.WriteLine($"The device's pin code: '{args.Pin}'");
                Console.WriteLine("Waiting for the target device to accept the pairing (you probably need to follow the instructions on the target device's screen)");
                args.Accept();
                return;
            }

            Console.WriteLine($"Unexpected pairing type: {args.PairingKind}");
            throw new Exception();
        }
コード例 #3
0
        private async void CustomPairInfo_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
        {
            Deferral PairDeferral = args.GetDeferral();

            try
            {
                PairConfirmaion = new TaskCompletionSource <bool>();

                switch (args.PairingKind)
                {
                case DevicePairingKinds.ConfirmPinMatch:
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            Tips.Text             = $"{Globalization.GetString("BluetoothUI_Tips_Text_5")}{Environment.NewLine}{args.Pin}";
                            Tips.Visibility       = Visibility.Visible;
                            PinConfirm.Visibility = Visibility.Visible;
                            PinRefuse.Visibility  = Visibility.Visible;
                        });

                    if (await PairConfirmaion.Task)
                    {
                        args.Accept(args.Pin);
                    }

                    break;
                }

                case DevicePairingKinds.ConfirmOnly:
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            Tips.Text             = Globalization.GetString("BluetoothUI_Tips_Text_6");
                            Tips.Visibility       = Visibility.Visible;
                            PinConfirm.Visibility = Visibility.Visible;
                            PinRefuse.Visibility  = Visibility.Visible;
                        });

                    if (await PairConfirmaion.Task)
                    {
                        args.Accept();
                    }

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                LogTracer.Log(ex, $"An exception was threw in {nameof(CustomPairInfo_PairingRequested)}, pair with bluetooth failed");
            }
            finally
            {
                PairDeferral.Complete();
            }
        }
コード例 #4
0
        /// <summary>
        /// Accept the current pairing using the PIN parameter and complete the deferral
        /// </summary>
        /// <param name="PIN"></param>
        private void AcceptPairingWithPIN(string PIN)
        {
            if (_pairingRequestedArgs != null)
            {
                _pairingRequestedArgs.Accept(PIN);
                _pairingRequestedArgs = null;
            }

            CompleteDeferral();
        }
コード例 #5
0
ファイル: MainPage.xaml.cs プロジェクト: SkoonStudios/IoTLabs
        private async void OnPairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
        {
            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 'Windows IoT Core' where there is no Windows Consent UX, you may want to provide your own confirmation.
                args.Accept();
                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. We automatically except here since we can't really "cancel" the operation
                // from this side.
                args.Accept();

                // No need for a deferral since we don't need any decision from the user
                Debug.WriteLine("Please enter this PIN on the device you are pairing with: {0}", args.Pin);
                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. Get a deferral so we can perform the async request to the user.
                var collectPinDeferral = args.GetDeferral();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // NOT IMPLEMENTED - Make ASYNC
                    // GET PIN FROM USER

                    collectPinDeferral.Complete();
                });

                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.
                var displayMessageDeferral = args.GetDeferral();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // NOT IMPLEMENTED - Make ASYNC
                    // CONFIRM PIN MATCH

                    displayMessageDeferral.Complete();
                });

                break;
            }
        }
コード例 #6
0
        private void OnPairRequestedAsyncCallback(
            DeviceInformationCustomPairing sender,
            DevicePairingRequestedEventArgs args)
        {
            this.log.Info("OnPairRequested", () => string.Format("Paring kind {0}", args.PairingKind.ToString()));

            BT_PairInfoRequest pairInfo = new BT_PairInfoRequest();

            pairInfo.DeviceName = args.DeviceInformation.Name;

            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 'Windows IoT Core' or a Desktop and Console application
                // where there is no Windows Consent UX, you may want to provide your own confirmation.
                args.Accept();
                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. Get a deferral so we can perform the async request to the user.
                using (Windows.Foundation.Deferral collectPinDeferral = args.GetDeferral()) {
                    pairInfo.PinRequested = true;
                    if (this.BT_PairInfoRequested != null)
                    {
                        this.BT_PairInfoRequested(this, pairInfo);
                    }
                    else
                    {
                        this.log.Error(9999, "No subscriber to pin request");
                    }

                    this.log.Info("OnPairRequested",
                                  () => string.Format("Pin '{0}' Response:{1}",
                                                      pairInfo.Pin, pairInfo.Response));

                    if (pairInfo.Response)
                    {
                        // TODO Check for the result to see if you go ahead
                    }

                    if (!string.IsNullOrEmpty(pairInfo.Pin))
                    {
                        args.Accept(pairInfo.Pin);
                    }
                    // TODO - needs to be disposed
                    collectPinDeferral.Complete();
                };
                break;
            }
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: thenson81/DotNetSamples
 private void Custom_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     if (args.PairingKind == DevicePairingKinds.ProvidePin)
     {
         // add reference: Microsoft.VisualBasic.dll
         string result = Microsoft.VisualBasic.Interaction.InputBox("Pin?", "Pairing...", "");
         if (string.IsNullOrEmpty(result) == false)
         {
             args.Accept(result);
         }
     }
     else
     {
         args.Accept();
     }
 }
コード例 #8
0
 private void CustomOnPairingRequested(
     DeviceInformationCustomPairing sender,
     DevicePairingRequestedEventArgs args)
 {
     Console.WriteLine("Done Pairing");
     args.Accept("0");
 }
コード例 #9
0
ファイル: DevicesManager.cs プロジェクト: lawesly/ble-remote
        private void PairingRequestedHandler(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs arguments)
        {
            switch (arguments.PairingKind)
            {
            case DevicePairingKinds.ConfirmOnly:
                arguments.Accept();
                break;

            case DevicePairingKinds.ProvidePin:
                var    collectPinDeferral = arguments.GetDeferral();
                string pin = "000000";
                arguments.Accept(pin);
                collectPinDeferral.Complete();
                break;
            }
        }
コード例 #10
0
ファイル: Connector.cs プロジェクト: Budochka/Robot
 private void handlerPairingReq(DeviceInformationCustomPairing CP, DevicePairingRequestedEventArgs DPR)
 {
     //so we get here for custom pairing request.
     //this is the magic place where your pin goes.
     //my device actually does not require a pin but
     //windows requires at least a "0".  So this solved
     //it.  This does not pull up the Windows UI either.
     DPR.Accept("0");
 }
コード例 #11
0
ファイル: EnvSensor.cs プロジェクト: mabooring/WPF-
 /// <summary>
 /// ペアリング要求時のハンドラ
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private static void PairingRequestedHandler(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     switch (args.PairingKind)
     {
     case DevicePairingKinds.ConfirmOnly:
         args.Accept();
         break;
     }
 }
コード例 #12
0
 private void OnCustomPairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     while (pin == null)
     {
         Thread.Sleep(500);
     }
     args.Accept(pin);
     pin = null;
 }
コード例 #13
0
        private async void CustomPairInfo_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
        {
            Deferral PairDeferral = args.GetDeferral();

            switch (args.PairingKind)
            {
            case DevicePairingKinds.ConfirmPinMatch:
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Tips.Text             = $"{Globalization.GetString("BluetoothUI_Tips_Text_5")}{Environment.NewLine}{args.Pin}";
                        Tips.Visibility       = Visibility.Visible;
                        PinConfirm.Visibility = Visibility.Visible;
                        PinRefuse.Visibility  = Visibility.Visible;
                    });

                break;
            }

            case DevicePairingKinds.ConfirmOnly:
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Tips.Text             = Globalization.GetString("BluetoothUI_Tips_Text_6");
                        Tips.Visibility       = Visibility.Visible;
                        PinConfirm.Visibility = Visibility.Visible;
                        PinRefuse.Visibility  = Visibility.Visible;
                    });

                break;
            }
            }
            await Task.Run(() =>
            {
                PinLock.WaitOne();

                if (IsPinConfirm)
                {
                    args.Accept();
                }
            }).ConfigureAwait(false);

            PairDeferral.Complete();
        }
コード例 #14
0
        private async void CustomPairInfo_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
        {
            Deferral PairDeferral = args.GetDeferral();

            switch (args.PairingKind)
            {
            case DevicePairingKinds.ConfirmPinMatch:
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Tips.Text             = "请确认PIN码与配对设备一致\r" + args.Pin;
                        Tips.Visibility       = Visibility.Visible;
                        PinConfirm.Visibility = Visibility.Visible;
                        PinRefuse.Visibility  = Visibility.Visible;
                    });

                break;
            }

            case DevicePairingKinds.ConfirmOnly:
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Tips.Text             = "请确认是否与配对设备配对";
                        Tips.Visibility       = Visibility.Visible;
                        PinConfirm.Visibility = Visibility.Visible;
                        PinRefuse.Visibility  = Visibility.Visible;
                    });

                break;
            }
            }
            await Task.Run(() =>
            {
                PinLock.WaitOne();

                if (IsPinConfirm)
                {
                    args.Accept();
                }
            });

            PairDeferral.Complete();
        }
コード例 #15
0
ファイル: MainPage.xaml.cs プロジェクト: bfjelds/samples
        private async void PairingRequestedHandler(
            DeviceInformationCustomPairing sender,
            DevicePairingRequestedEventArgs args)
        {
            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 'Windows IoT Core' where there is no Windows Consent UX, you may want to provide your own confirmation.
                args.Accept();
                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. We automatically except here since we can't really "cancel" the operation
                // from this side.
                args.Accept();

                // No need for a deferral since we don't need any decision from the user
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    ShowPairingPanel(
                        "Please enter this PIN on the device you are pairing with: " + args.Pin,
                        args.PairingKind);
                });

                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. Get a deferral so we can perform the async request to the user.
                var collectPinDeferral = args.GetDeferral();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    string pin = await GetPinFromUserAsync();
                    if (!string.IsNullOrEmpty(pin))
                    {
                        args.Accept(pin);
                    }

                    collectPinDeferral.Complete();
                });

                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.
                var displayMessageDeferral = args.GetDeferral();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    bool accept = await GetUserConfirmationAsync(args.Pin);
                    if (accept)
                    {
                        args.Accept();
                    }

                    displayMessageDeferral.Complete();
                });

                break;
            }
        }
コード例 #16
0
 private static void Custom_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     sender.PairingRequested -= Custom_PairingRequested;
     args.Accept(pinMappings[args.DeviceInformation.Id]);
     pinMappings.Remove(args.DeviceInformation.Id);
 }
コード例 #17
0
ファイル: PairingHelper.cs プロジェクト: nikname/HeartRateLE
 private static void Custom_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     args.Accept();
     //throw new NotImplementedException();
 }
        private async void PairingRequestedHandler(
            DeviceInformationCustomPairing sender,
            DevicePairingRequestedEventArgs args)
        {
            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 'Windows IoT Core' where there is no Windows Consent UX, you may want to provide your own confirmation.
                    args.Accept();
                    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. We automatically except here since we can't really "cancel" the operation
                    // from this side.
                    args.Accept();

                    // No need for a deferral since we don't need any decision from the user
                    await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ShowPairingPanel(
                            "Please enter this PIN on the device you are pairing with: " + args.Pin,
                            args.PairingKind);

                    });
                    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. Get a deferral so we can perform the async request to the user.
                    var collectPinDeferral = args.GetDeferral();

                    await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                    {
                        string pin = await GetPinFromUserAsync();
                        if (!string.IsNullOrEmpty(pin))
                        {
                            args.Accept(pin);
                        }

                        collectPinDeferral.Complete();
                    });
                    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.
                    var displayMessageDeferral = args.GetDeferral();

                    await rootPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                    {
                        bool accept = await GetUserConfirmationAsync(args.Pin);
                        if (accept)
                        {
                            args.Accept();
                        }

                        displayMessageDeferral.Complete();
                    });
                    break;
            }
        }
コード例 #19
0
 private static void OnPairingRequested(DeviceInformationCustomPairing pairing, DevicePairingRequestedEventArgs args)
 {
     args.Accept("0");
 }
コード例 #20
0
 private void CustomOnPairingRequested(DeviceInformationCustomPairing sender,
                                       DevicePairingRequestedEventArgs args)
 {
     args.Accept(_pairingCode);
 }
コード例 #21
0
 private void CustomPairing_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     args.Accept("123456");
 }
コード例 #22
0
 private void PairingRequestedHandler(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     args.Accept();
 }
コード例 #23
0
 private void CustomPairing_PairingRequested(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
 {
     Logger.Log($"Accepting pairing request with PIN: {args.Pin}.");
     args.Accept();
 }