Esempio n. 1
0
        /// <summary>
        /// Creates a new HotspotManager with the given connection profile and configuration.
        /// </summary>
        public static async Task <HotspotManager> CreateAsync(ConnectionProfile profile, NetworkOperatorTetheringAccessPointConfiguration configuration)
        {
            var hotspot = new HotspotManager
            {
                tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(profile)
            };
            await hotspot.tetheringManager.ConfigureAccessPointAsync(configuration);

            return(hotspot);
        }
        private async Task WifiToEthernetAsync()
        {
            // Find the Ethernet profile (IANA Type 6)
            var connectionProfiles    = NetworkInformation.GetConnectionProfiles();
            var wifiConnectionProfile = connectionProfiles.FirstOrDefault(x => x.NetworkAdapter.IanaInterfaceType == 71);

            // Find an 802.11 wireless network interface (IANA Type 71)
            var ethernetConnectionProfile = connectionProfiles.FirstOrDefault(x => x.NetworkAdapter.IanaInterfaceType == 6);
            var targetNetworkAdapter      = ethernetConnectionProfile.NetworkAdapter;

            if (wifiConnectionProfile != null && targetNetworkAdapter != null)
            {
                var tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(wifiConnectionProfile, targetNetworkAdapter);

                var result = await tetheringManager.StartTetheringAsync();

                ContentDialog dialog = new ContentDialog()
                {
                    Title      = "Connection Status",
                    FontFamily = new Windows.UI.Xaml.Media.FontFamily("Agency FB"),

                    MaxWidth          = this.ActualWidth,
                    PrimaryButtonText = "OK",
                };

                if (result.Status == TetheringOperationStatus.Success)
                {
                    dialog.Content = new TextBlock
                    {
                        Text     = "Connection successful, please connect tag manager",
                        FontSize = 18,
                    };
                }
                else
                {
                    dialog.Content = new TextBlock
                    {
                        Text     = "Connection Failed",
                        FontSize = 18,
                    };
                }

                //TODO: temporary
                //dialog.Content = new TextBlock
                //{
                //    Text = "No Tag Manager Detected, Proceed for now",
                //    FontSize = 18,
                //    FontFamily = new Windows.UI.Xaml.Media.FontFamily("Agency FB"),
                //};

                //await dialog.ShowAsync();

                rootPage.Frame.Navigate(typeof(AlertsPage));
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            while (true)
            {
                var profile          = NetworkInformation.GetInternetConnectionProfile();
                var tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(profile);
                if (tetheringManager.TetheringOperationalState == TetheringOperationalState.Off)
                {
                    TurnOnHotSpot(tetheringManager).Wait();
                }
                System.Threading.Thread.Sleep(5000);
            }

            return;
        }
Esempio n. 4
0
        private bool SetupTethering()
        {
            conProfile = NetworkInformation.GetInternetConnectionProfile();
            if (conProfile.ProfileName == "WFD_GROUP_OWNER_PROFILE")
            {
                txtWAN.Text = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView().GetString("Default");
            }
            else
            {
                txtWAN.Text = conProfile.ProfileName;
            }
            tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(conProfile);
            NetworkOperatorTetheringAccessPointConfiguration apConfig =
                tetheringManager.GetCurrentAccessPointConfiguration();

            txtSSID.Text     = apConfig.Ssid;
            txtPass.Password = apConfig.Passphrase;
            return(true);
        }
Esempio n. 5
0
 /// <summary>
 /// Load tethering manager if available.
 /// </summary>
 private bool MakeTetheringManagerAvailable()
 {
     if (tetheringManager == null)
     {
         // verify tethering capabilities
         var allAccounts = MobileBroadbandAccount.AvailableNetworkAccountIds;
         if (allAccounts.Count == 0)
         {
             rootPage.NotifyUser("There is no avaiable network account ID.", NotifyType.ErrorMessage);
             return(false);
         }
         string networkAccountId          = allAccounts[0];
         TetheringCapability capabilities = 0;
         try
         {
             capabilities = NetworkOperatorTetheringManager.GetTetheringCapability(networkAccountId);
             if (capabilities != TetheringCapability.Enabled)
             {
                 OnCapabilityError(capabilities);
             }
             else
             {
                 if (tetheringManager == null)
                 {
                     tetheringManager = NetworkOperatorTetheringManager.CreateFromNetworkAccountId(networkAccountId);
                     if (tetheringManager == null)
                     {
                         rootPage.NotifyUser("Failed to create NetworkOperatorTetheringManager object using : " + networkAccountId, NotifyType.ErrorMessage);
                         return(false);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
             return(false);
         }
     }
     return(true);
 }
Esempio n. 6
0
        private void Init()
        {
            var connectionProfiles = NetworkInformation.GetConnectionProfiles();
            ConnectionProfile ethernetConnectionProfile = null;

            foreach (var item in NetworkInformation.GetHostNames())
            {
                string name  = item.DisplayName;
                string name2 = item.CanonicalName;

                if (connectionProfiles.Where(x => x.NetworkAdapter?.NetworkAdapterId == item.IPInformation?.NetworkAdapter?.NetworkAdapterId).FirstOrDefault() != null)
                {
                    ethernetConnectionProfile = connectionProfiles.Where(x => x.NetworkAdapter?.NetworkAdapterId == item.IPInformation?.NetworkAdapter?.NetworkAdapterId).First();
                }
            }
            _tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(ethernetConnectionProfile);
            var config = _tetheringManager.GetCurrentAccessPointConfiguration();

            _setting.Name     = config.Ssid;
            _setting.Password = config.Passphrase;
        }
Esempio n. 7
0
        public MainPage()
        {
            this.InitializeComponent();


            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (InternetConnectionProfile != null)
            {
                tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(InternetConnectionProfile);
                switch (tetheringManager.TetheringOperationalState)
                {
                case TetheringOperationalState.On:
                    switchTethering.IsOn = true;
                    break;

                default:
                    switchTethering.IsOn = false;
                    break;
                }
            }
            CPing ping = new CPing();
        }
Esempio n. 8
0
 private static async Task TurnOnHotSpot(NetworkOperatorTetheringManager tetheringManager)
 {
     await tetheringManager.StartTetheringAsync();
 }
Esempio n. 9
0
        private MeasureBackgroundTask()
        {
            logModel.AppendLog(Log.CreateLog("Measure Service starting...", Log.LogType.System));

            userSettings = new UserSettings();

            var taskUser = Task.Run(async() => { userSettings = await userSettingsModel.GetUserSettingsAsync(); });

            taskUser.Wait();

            logModel.AppendLog(Log.CreateLog("UserSettings retreived", Log.LogType.System));

            //Disable Diagnostic Mode on restart
            if (userSettings.isDiagnosticModeEnable)
            {
                userSettings.isDiagnosticModeEnable = false;

                var taskUserSync = Task.Run(async() =>
                {
                    await userSettingsModel.SyncUserSettings(userSettings);
                });
                taskUserSync.Wait();
            }

            var taskTethering = Task.Run(async() =>
            {
                try
                {
                    var connectedProfile = NetworkInformation.GetInternetConnectionProfile();

                    if (connectedProfile != null)
                    {
                        logModel.AppendLog(Log.CreateLog(String.Format("Connected Profile found - {0}", connectedProfile.ProfileName), Log.LogType.System));
                    }

                    bool isWLANConnection = (connectedProfile == null) ? false : connectedProfile.IsWlanConnectionProfile;

                    if (isWLANConnection == false)
                    {
                        logModel.AppendLog(Log.CreateLog("Device offline", Log.LogType.System));

                        ConnectionProfileFilter filter = new ConnectionProfileFilter();
                        filter.IsWlanConnectionProfile = true;

                        var profile = await NetworkInformation.FindConnectionProfilesAsync(filter);

                        var defaultProfile = profile.FirstOrDefault();

                        if (defaultProfile != null)
                        {
                            logModel.AppendLog(Log.CreateLog(String.Format("Default Profile found - {0}", defaultProfile.ProfileName), Log.LogType.System));

                            var networkOperatorTetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(defaultProfile);

                            if (networkOperatorTetheringManager.TetheringOperationalState != TetheringOperationalState.On)
                            {
                                var config = new NetworkOperatorTetheringAccessPointConfiguration();

                                config.Ssid       = userSettings.SSID;
                                config.Passphrase = userSettings.ACCESS_POINT_PWD;

                                logModel.AppendLog(Log.CreateLog("Access Point creation init...", Log.LogType.System));
                                await networkOperatorTetheringManager.ConfigureAccessPointAsync(config);

                                var rslt = await networkOperatorTetheringManager.StartTetheringAsync();
                                await Task.Delay(5000);
                                logModel.AppendLog(Log.CreateLog("Access Point creation ending...", Log.LogType.System));

                                if (rslt.Status == TetheringOperationStatus.Success)
                                {
                                    logModel.AppendLog(Log.CreateLog("Access Point created", Log.LogType.System));
                                }
                                else
                                {
                                    logModel.AppendLog(Log.CreateLog(String.Format("Access Point creation failed - {0}", rslt.AdditionalErrorMessage), Log.LogType.Warning));
                                }
                            }
                            else
                            {
                                logModel.AppendLog(Log.CreateLog(String.Format("Access Point already on - {0}", networkOperatorTetheringManager.TetheringOperationalState.ToString()), Log.LogType.System));
                            }
                        }
                        else
                        {
                            logModel.AppendLog(Log.CreateLog("No default profile found", Log.LogType.System));
                        }
                    }
                    else
                    {
                        logModel.AppendLog(Log.CreateLog("No connection profile found", Log.LogType.System));
                    }
                }
                catch (Exception ex)
                {
                    logModel.AppendLog(Log.CreateErrorLog("Error on Access Point init", ex));
                }
            });

            taskTethering.Wait();

            bw.WorkerSupportsCancellation = true;
            bw.WorkerReportsProgress      = true;
            bw.DoWork             += Bw_DoWork;
            bw.RunWorkerCompleted += Bw_RunWorkerCompleted;
            bw.ProgressChanged    += Bw_ProgressChanged;
        }
Esempio n. 10
0
        public TetherMobileHotspot()
        {
            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            tetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(InternetConnectionProfile);
        }
Esempio n. 11
0
 /// <summary>
 /// Load tethering manager if available.
 /// </summary>
 private bool MakeTetheringManagerAvailable()
 {
     if (tetheringManager == null)
     {
         // verify tethering capabilities
         var allAccounts = MobileBroadbandAccount.AvailableNetworkAccountIds;
         if (allAccounts.Count == 0)
         {
             rootPage.NotifyUser("There is no avaiable network account ID.", NotifyType.ErrorMessage);
             return false;
         }
         string networkAccountId = allAccounts[0];
         TetheringCapability capabilities = 0;
         try
         {
             capabilities = NetworkOperatorTetheringManager.GetTetheringCapability(networkAccountId);
             if (capabilities != TetheringCapability.Enabled)
             {
                 OnCapabilityError(capabilities);
             }
             else
             {
                 if (tetheringManager == null)
                 {
                     tetheringManager = NetworkOperatorTetheringManager.CreateFromNetworkAccountId(networkAccountId);
                     if (tetheringManager == null)
                     {
                         rootPage.NotifyUser("Failed to create NetworkOperatorTetheringManager object using : " + networkAccountId, NotifyType.ErrorMessage);
                         return false;
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             rootPage.NotifyUser("Unexpected exception occured: " + ex.ToString(), NotifyType.ErrorMessage);
             return false;
         }
     }
     return true;
 }
Esempio n. 12
0
 private NetworkOperatorTetheringManager GetCurrentTetheringManage()
 {
     return(NetworkOperatorTetheringManager.CreateFromConnectionProfile(
                NetworkInformation.GetInternetConnectionProfile()
                ));
 }