ConnectToNetwork() 공개 메소드

public ConnectToNetwork ( WiFiAvailableNetwork network, bool autoConnect ) : Task
network WiFiAvailableNetwork
autoConnect bool
리턴 Task
예제 #1
0
        private async Task ConnectToWifiAsync(WiFiAvailableNetwork network, PasswordCredential credential, CoreDispatcher dispatcher)
        {
            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SwitchToItemState(network, WifiConnectingState, false);
            });

            var didConnect = credential == null?
                             networkPresenter.ConnectToNetwork(network, ConnectAutomatically) :
                                 networkPresenter.ConnectToNetworkWithPassword(network, ConnectAutomatically, credential);

            DataTemplate nextState   = (await didConnect) ? WifiConnectedState : WifiInitialState;
            bool         isConnected = (nextState == WifiConnectedState);

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var list         = WifiListView.ItemsSource as ObservableCollection <WiFiAvailableNetwork>;
                var itemLocation = list.IndexOf(network);
                if (0 != itemLocation && isConnected)
                {
                    list.Move(itemLocation, 0);
                }
                var item = SwitchToItemState(network, nextState, true);
                if (item != null)
                {
                    item.IsSelected = true;
                }
            });

            if (isConnected)
            {
                NetworkConnected?.Invoke(this, new EventArgs());
            }
        }
예제 #2
0
        private async void ConnectToWifi(WiFiAvailableNetwork network, PasswordCredential credential, CoreDispatcher dispatcher)
        {
            var didConnect = credential == null?
                             networkPresenter.ConnectToNetwork(network, Automatic) :
                                 networkPresenter.ConnectToNetworkWithPassword(network, Automatic, credential);

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SwitchToItemState(network, WifiConnectingState);
            });

            if (await didConnect)
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    NavigationUtils.NavigateToScreen(typeof(MainPage));
                });
            }
            else
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var item        = SwitchToItemState(network, WifiInitialState);
                    item.IsSelected = false;
                });
            }
        }
예제 #3
0
        private async void ConnectToWifi(WiFiAvailableNetwork network, PasswordCredential credential, CoreDispatcher dispatcher)
        {
            var didConnect = credential == null?
                             networkPresenter.ConnectToNetwork(network, Automatic) :
                                 networkPresenter.ConnectToNetworkWithPassword(network, Automatic, credential);

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SwitchToItemState(network, WifiConnectingState, false);
            });

            DataTemplate nextState = (await didConnect) ? WifiConnectedState : WifiInitialState;

            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var item        = SwitchToItemState(network, nextState, false);
                item.IsSelected = false;
            });
        }