Exemple #1
0
        async void RegisterForInboundPairingRequests()
        {
            // Make the system discoverable for Bluetooth
            await MakeDiscoverable();

            // If the attempt to make the system discoverable failed then likely there is no Bluetooth device present
            // so leave the diagnositic message put out by the call to MakeDiscoverable()
            if (App.IsBluetoothDiscoverable)
            {
                string formatString;
                string confirmationMessage;

                // Get state of ceremony checkboxes
                DevicePairingKinds ceremoniesSelected = GetSelectedCeremonies();
                int iCurrentSelectedCeremonies        = (int)ceremoniesSelected;

                // Find out if we changed the ceremonies we orginally registered with - if we have registered before these will be saved
                var    localSettings            = Windows.Storage.ApplicationData.Current.LocalSettings;
                Object supportedPairingKinds    = localSettings.Values["supportedPairingKinds"];
                int    iSavedSelectedCeremonies = -1; // Deliberate impossible value
                if (supportedPairingKinds != null)
                {
                    iSavedSelectedCeremonies = (int)supportedPairingKinds;
                }

                ResourceLoader loader = ResourceLoader.GetForCurrentView();

                if (!DeviceInformationPairing.TryRegisterForAllInboundPairingRequests(ceremoniesSelected))
                {
                    confirmationMessage = loader.GetString("BluetoothInboundRegistrationFailed/Text");
                }
                else
                {
                    // Save off the ceremonies we registered with
                    localSettings.Values["supportedPairingKinds"] = iCurrentSelectedCeremonies;
                    formatString        = loader.GetString("BluetoothInboundRegistrationSucceeded/Text");
                    confirmationMessage = formatString + ceremoniesSelected.ToString();
                }

                // Clear the current collection
                BluetoothDevices.Clear();
                // Start the watcher
                StartWatcher();
                // Display a message
                confirmationMessage += loader.GetString("BluetoothOn/Text");
                DisplayMessagePanelAsync(confirmationMessage, MessageType.InformationalMessage);
            }
        }
        private async void RegisterForInboundPairingRequests()
        {
            // Make the system discoverable for Bluetooth
            await MakeDiscoverable();

            // If the attempt to make the system discoverable failed then likely there is no Bluetooth device present
            // so leave the diagnositic message put uot by the call to MakeDiscoverable()
            if (App.IsBluetoothDiscoverable)
            {
                string formatString;
                string confirmationMessage;

                // Get state of ceremony checkboxes
                DevicePairingKinds ceremoniesSelected = GetSelectedCeremonies();
                int iCurrentSelectedCeremonies        = (int)ceremoniesSelected;

                // Find out if we changed the ceremonies we orginally registered with - if we have registered before these will be saved
                var    localSettings            = Windows.Storage.ApplicationData.Current.LocalSettings;
                Object supportedPairingKinds    = localSettings.Values["supportedPairingKinds"];
                int    iSavedSelectedCeremonies = -1; // Deliberate impossible value
                if (supportedPairingKinds != null)
                {
                    iSavedSelectedCeremonies = (int)supportedPairingKinds;
                }

                if (!DeviceInformationPairing.TryRegisterForAllInboundPairingRequests(ceremoniesSelected))
                {
                    confirmationMessage = BluetoothDeviceInformationDisplay.GetResourceString("BluetoothInboundRegistrationFailed");
                }
                else
                {
                    // Save off the ceremonies we registered with
                    localSettings.Values["supportedPairingKinds"] = iCurrentSelectedCeremonies;
                    formatString        = BluetoothDeviceInformationDisplay.GetResourceString("BluetoothInboundRegistrationSucceededFormat");
                    confirmationMessage = string.Format(formatString, ceremoniesSelected.ToString());
                }

                DisplayMessagePanel(confirmationMessage, MessageType.InformationalMessage);

                // Enable the watcher switch
                BluetoothWatcherToggle.IsEnabled = true;
            }
            else
            {
                // Disable the watcher switch
                BluetoothWatcherToggle.IsEnabled = false;
            }
        }
        /// <summary>
        /// Register the device for inbound pairing requests
        /// </summary>
        private async void RegisterForInboundPairingRequests()
        {
            // Make the system discoverable for Bluetooth.
            await MakeDiscoverable();

            string confirmationMessage = string.Empty;

            // If the attempt to make the system discoverable failed then likely there is no Bluetooth device present,
            // so leave the diagnostic message put up by the call to MakeDiscoverable().
            if (_isBluetoothDiscoverable)
            {
                // Get state of ceremony checkboxes
                DevicePairingKinds ceremoniesSelected = GetSelectedCeremonies();
                int iCurrentSelectedCeremonies        = (int)ceremoniesSelected;
                int iSavedSelectedCeremonies          = -1; // Deliberate impossible value

                // Find out if we changed the ceremonies we originally registered with.
                // If we have registered before, these will be saved.
                object supportedPairingKinds = LocalSettings.Values["supportedPairingKinds"];

                if (supportedPairingKinds != null)
                {
                    iSavedSelectedCeremonies = (int)supportedPairingKinds;
                }

                if (!DeviceInformationPairing.TryRegisterForAllInboundPairingRequests(ceremoniesSelected))
                {
                    confirmationMessage = string.Format(BluetoothInboundRegistrationFailed, ceremoniesSelected.ToString());
                }
                else
                {
                    // Save off the ceremonies we registered with
                    LocalSettings.Values["supportedPairingKinds"] = iCurrentSelectedCeremonies;
                    confirmationMessage = string.Format(BluetoothInboundRegistrationSucceededFormat, ceremoniesSelected.ToString());
                }

                BluetoothWatcherEnabled = true;
            }
            else
            {
                BluetoothWatcherEnabled = false;
            }

            await DisplayMessagePanel(confirmationMessage, MessageType.InformationalMessage);
        }