コード例 #1
0
        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 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;
                }

                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());
                }

                // Clear the current collection
                bluetoothDeviceObservableCollection.Clear();
                // Start the watcher
                StartWatcher();
                // Display a message
                confirmationMessage += BluetoothDeviceInformationDisplay.GetResourceString("BluetoothOn");
                DisplayMessagePanelAsync(confirmationMessage, MessageType.InformationalMessage);
            }
        }
コード例 #2
0
        /// <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);
        }