Пример #1
0
        /// <summary>
        /// Checks If internet connection is available.
        /// If silent mode is off shows a message and navigates user to WiFi Settings.
        /// </summary>
        /// <param name="silenceMode"></param>
        /// <returns></returns>
        public async Task <bool> InternetAvailableAsync(bool silenceMode)
        {
            if (!_initialized || !NetworkStatus)
            {
                if (!_initializing)
                {
                    _initializing = true;
                    NetworkStatus = await GetInternetStatusAsync();

                    _initializing = false;
                    _initialized  = true;
                }
            }

            if (!silenceMode && !NetworkStatus)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    var result = MessageBox.Show(NetworkCheckerErrorMessages.NetworkErrorMessage,
                                                 NetworkCheckerErrorMessages.NetworkErrorTitle,
                                                 MessageBoxButton.OK);

                    if (result == MessageBoxResult.OK)
                    {
                        var task = new Microsoft.Phone.Tasks.ConnectionSettingsTask
                        {
                            ConnectionSettingsType = Microsoft.Phone.Tasks.ConnectionSettingsType.WiFi
                        };
                        task.Show();
                    }
                });
            }

            return(NetworkStatus);
        }
Пример #2
0
        /// <summary>
        /// Shows the Bluetooth device picker so that the user can pick one device.
        /// </summary>
        /// <returns>When the call to this method completes successfully, it returns a PeerInformation object that represents the device that the user picked.</returns>
        public async Task <PeerInformation> PickDeviceAsync()
        {
            // replace waithandle - fixes bug with multiple calls (Thanks Phil Allison)
            WaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.AutoReset);

            SelectedItem = null;

#if V81
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(Windows.Devices.Bluetooth.BluetoothDevice.GetDeviceSelector());

            foreach (DeviceInformation info in devices)
            {
                info.
            }
#else
            PeerFinder.AlternateIdentities["Bluetooth:Paired"] = string.Empty;

            // get all service types
            if (this.serviceFilter == Guid.Empty)
            {
                PeerFinder.AlternateIdentities["Bluetooth:SDP"] = string.Empty;
            }
            else
            {
                PeerFinder.AlternateIdentities["Bluetooth:SDP"] = this.serviceFilter.ToString("D");
                PeerFinder.AlternateIdentities.Remove("Bluetooth:Paired");
            }
#endif

            IReadOnlyCollection <PeerInformation> devices = null;

            while (devices == null)
            {
                try
                {
                    devices = await PeerFinder.FindAllPeersAsync();
                }
                catch (Exception ex)
                {
                    if ((uint)ex.HResult == 0x8007048F)
                    {
                        if (MessageBox.Show(Resources.Strings.OpenSettings, Resources.Strings.Bluetooth, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        {
                            Microsoft.Phone.Tasks.ConnectionSettingsTask cst = new Microsoft.Phone.Tasks.ConnectionSettingsTask();
                            cst.ConnectionSettingsType = Microsoft.Phone.Tasks.ConnectionSettingsType.Bluetooth;
                            cst.Show();
                        }
                        else
                        {
                            // don't prompt again - return with no device selected
                            return(null);
                        }
                    }
                }
            }

            Items = devices;

            Frame f = (Frame)Application.Current.RootVisual;

            f.Navigate(new Uri("/InTheHand.Devices.Bluetooth;component/BluetoothPickerPage.xaml", UriKind.Relative));

            var tcs = new TaskCompletionSource <bool>();
            var rwh = System.Threading.ThreadPool.RegisterWaitForSingleObject(WaitHandle, delegate { tcs.TrySetResult(true); }, null, -1, true);
            var t   = tcs.Task;
            await t.ContinueWith(_ => rwh.Unregister(WaitHandle));

            return(SelectedItem);
        }