Example #1
0
        private async void TgSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            tgSwitch.IsEnabled = false;

            if (tgSwitch.IsOn &&
                (tetheringManager.TetheringOperationalState == TetheringOperationalState.Off))
            {
                bool fNewConfig = false;

                ConfGui_Enable(false);

                NetworkOperatorTetheringAccessPointConfiguration apConfig =
                    tetheringManager.GetCurrentAccessPointConfiguration();

                if (txtSSID.Text != apConfig.Ssid)
                {
                    apConfig.Ssid = txtSSID.Text;
                    fNewConfig    = true;
                }

                if (txtPass.Password != apConfig.Passphrase)
                {
                    apConfig.Passphrase = txtPass.Password;
                    fNewConfig          = true;
                }

                if (fNewConfig)
                {
                    await tetheringManager.ConfigureAccessPointAsync(apConfig);
                }

                var result = await tetheringManager.StartTetheringAsync();

                if (result.Status != TetheringOperationStatus.Success)
                {
//                    txtStatus.Text = "Can't start!";
                }
            }
            else if (!tgSwitch.IsOn &&
                     (tetheringManager.TetheringOperationalState == TetheringOperationalState.On))
            {
                var result = await tetheringManager.StopTetheringAsync();

                if (result.Status == TetheringOperationStatus.Success)
                {
                    SetupTethering();
                }
                else
                {
//                    txtStatus.Text = "Can't stop!";
                }
            }
        }
Example #2
0
        public async void Stop()
        {
            try
            {
                if (_tetheringManager != null)
                {
                    await _tetheringManager.StopTetheringAsync();
                }

                //_publisher.Stop();
                //_publisher.StatusChanged -= OnStatusChanged;
            }
            catch (Exception ex)
            {
            }
        }
Example #3
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;
     }
 }
Example #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);
            }
        }