예제 #1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            await SetupStartupTask();

            SetupTethering();

            _timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(1)
            };

            _timer.Tick += (_1, _2) =>
            {
                UpdateTetheringStatus();
            };
            _timer.Start();

            if (ckAutoConn.IsChecked.Value)
            {
                if (tetheringManager.TetheringOperationalState == TetheringOperationalState.Off)
                {
                    var result = await tetheringManager.StartTetheringAsync();

                    if (result.Status == TetheringOperationStatus.Success)
                    {
                        if (ckCloseApp.IsChecked.Value)
                        {
                            Application.Current.Exit();
                        }
                    }
                }
            }
        }
예제 #2
0
 /// <summary>
 /// start/stop tethering
 /// </summary>
 /// <param name="enable"></param>
 private async void EnableTethering(bool enable)
 {
     try
     {
         NetworkOperatorTetheringOperationResult result;
         if (enable)
         {
             result = await tetheringManager.StartTetheringAsync();
         }
         else
         {
             result = await tetheringManager.StopTetheringAsync();
         }
         if (result.Status != TetheringOperationStatus.Success)
         {
             var errorString = "";
             if (result.AdditionalErrorMessage != "")
             {
                 errorString = result.AdditionalErrorMessage;
             }
             else
             {
                 errorString = GetTetheringErrorString(result.Status);
             }
             if (enable)
             {
                 rootPage.NotifyUser("StartTetheringAsync function failed: " + errorString, NotifyType.ErrorMessage);
             }
             else
             {
                 rootPage.NotifyUser("StopTetheringAsync function failed: " + errorString, NotifyType.ErrorMessage);
             }
         }
         else
         {
             rootPage.NotifyUser("Operation succeeded.", NotifyType.StatusMessage);
             UpdateUIWithTetheringState();
         }
     }
     catch (Exception ex)
     {
         rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
         return;
     }
 }
예제 #3
0
        private async Task <bool> StartNetworkOperatorTetheringManager(WlanSetting setting)
        {
            var Config = _tetheringManager.GetCurrentAccessPointConfiguration();

            _setting          = setting;
            Config.Ssid       = setting.Name;
            Config.Passphrase = setting.Password;

            await _tetheringManager.ConfigureAccessPointAsync(Config);

            var result = await _tetheringManager.StartTetheringAsync();

            if (result.Status == TetheringOperationStatus.Success)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
예제 #4
0
        public async Task RunAsync(CancellationToken cancellationToken)
        {
            await tetheringManager.StartTetheringAsync();

            var lastSeenClients = new HashSet <NetworkOperatorTetheringClient>(new ClientComparer());


            while (true)
            {
                // Continuously poll the connected clients
                var currentClients = tetheringManager.GetTetheringClients();

                // Compare with the saved clients to see which are new / which are gone
                var newClients  = currentClients.Except(lastSeenClients, new ClientComparer()).ToArray();
                var goneClients = lastSeenClients.Except(currentClients, new ClientComparer()).ToArray();

                foreach (var client in goneClients)
                {
                    ClientDisconnected?.Invoke(this, client);
                    lastSeenClients.Remove(client);
                }

                foreach (var client in newClients)
                {
                    ClientConnected?.Invoke(this, client);
                    lastSeenClients.Add(client);
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    await tetheringManager.StopTetheringAsync();

                    return;
                }

                await Task.Delay(10000);
            }
        }
예제 #5
0
 private static async Task TurnOnHotSpot(NetworkOperatorTetheringManager tetheringManager)
 {
     await tetheringManager.StartTetheringAsync();
 }
예제 #6
0
        public async Task <TetheringOperationStatus> StartTetheringAsync()
        {
            NetworkOperatorTetheringOperationResult result = await tetheringManager.StartTetheringAsync();

            return(result.Status);
        }