コード例 #1
0
        public async Task RefreshWiFiListViewItemsAsync(bool refreshIfNeeded)
        {
            if (await _networkPresenter.WiFiIsAvailable())
            {
                bool isRefreshNeeded = _networkPresenter.IsRefreshNeeded();
                EnableView(false, false);

                try
                {
                    var networks = await _networkPresenter.GetAvailableNetworks(refreshIfNeeded);

                    if (networks.Count > 0)
                    {
                        var connectedNetwork = _networkPresenter.GetCurrentOOBENetworkName();
                        if (connectedNetwork != null)
                        {
                            networks.Remove(connectedNetwork);
                            networks.Insert(0, connectedNetwork);
                        }

                        WiFiListView.ItemsSource = WiFiListViewItems = new ObservableCollection <WiFiListViewItemPresenter>(networks);

                        var item = SwitchToItemState(connectedNetwork, WiFiConnectedState, true);
                        if (item != null)
                        {
                            WiFiListView.SelectedItem = item;
                        }

                        NoWiFiFoundText.Visibility = Visibility.Collapsed;
                        WiFiListView.Visibility    = Visibility.Visible;

                        EnableView(true, true);

                        return;
                    }
                }
                catch (Exception e)
                {
                    App.LogService.Write(string.Format("Error scanning: 0x{0:X}: {1}", e.HResult, e.Message));
                    NoWiFiFoundText.Text       = e.Message;
                    NoWiFiFoundText.Visibility = Visibility.Visible;
                    EnableView(true, true);
                    return;
                }
            }

            NoWiFiFoundText.Visibility = Visibility.Visible;
            WiFiListView.Visibility    = Visibility.Collapsed;
        }