コード例 #1
0
        private void GetWIFIProfileComplete(string result)
        {
            Debug.Log(result);
            WifiInterfaces all = JsonUtil.Deserialize <WifiInterfaces>(result);

            List <string> profileName = new List <string>();

            for (int i = 0; i < all.Interfaces.Count; i++)
            {
                WifiInterface inter = all.Interfaces[i];
                string        uid   = inter.GUID;
                uid = uid.Trim();
                uid = uid.Substring(1, uid.Length - 2);

                Debug.Log("find uid=" + uid);
                Debug.Log("networkId=" + networkID);

                if (uid == networkID)
                {
                    for (int j = 0; j < inter.ProfilesList.Count; j++)
                    {
                        WifiProfile profile = inter.ProfilesList[j];
                        profileName.Add(profile.Name);
                    }
                    Debug.Log("Find!!! profile count=" + profileName.Count);
                }
            }

            panel.hololensStatusPanel.ShowWifiProfileResult(profileName);
        }
コード例 #2
0
        public void TestPerformance3()
        {
            PerformanceUtility pu = new PerformanceUtility();

            pu.StartTimer();
            WifiProfile items = WifiProfileManager.ActiveWifiProfile;
            long        time  = pu.GetEnlapsedTime();

            Debug.WriteLine("Executed WifiProfileManager.ActiveWifiProfile in " + time + " ms");
        }
コード例 #3
0
        /// <summary>
        /// Refreshes the wifi combo.
        /// </summary>
        protected void RefreshWifiCombo(NetworkProfile profile)
        {
            WindowsNetworkCard config = profile.NetworkCardInfo;

            if (config == null)
            {
                return;
            }

            // get the correct type from dataModel, cause _configuration.CardType is not affidable
            WindowsNetworkCard     wnc  = DataModel.FindNetworkCard(config.Id);
            WindowsNetworkCardType type = WindowsNetworkCardType.UNKNOWN;

            if (wnc != null)
            {
                type = wnc.CardType;
            }

            // for wifi card
            if (WindowsNetworkCardType.WIRELESS == type)
            {
                WifiProfile currentWifiProfile = WifiProfileManager.GetActiveWifiProfileForCard(config);

                List <WifiProfile> listWifiProfile = WifiProfileManager.GetWifiProfilesForCard(config);

                cbWifiProfile.Items.Clear();
                cbWifiProfile.Items.Add("");
                foreach (WifiProfile item in listWifiProfile)
                {
                    cbWifiProfile.Items.Add(item.SSID);
                }

                // if nic is disable, no wireless profile found. Add the selected profile
                if (listWifiProfile.Count == 0)
                {
                    cbWifiProfile.Items.Add(WifiProfileSSID);
                }

                cbWifi.Checked     = WifiProfileSelected;
                cbWifiProfile.Text = WifiProfileSSID;
            }
            else
            {
                cbWifi.Checked     = false;
                cbWifiProfile.Text = "";
            }
        }
コード例 #4
0
        /// <summary>
        /// Select NIC selected from listview and fill other fields.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void SelectNetworkCard()
        {
            NetworkProfile profile = Profile;
            // cerchiamo viewId
            string work = lstNetworkCard.Text;

            if (work.Equals(UseCaseProfile.NEW_NIC_NAME))
            {
            }
            else
            {
                int i1 = work.IndexOf("[");

                if (i1 >= 0)
                {
                    int i2 = work.IndexOf("]", i1);

                    work = i2 > 0 ? work.Substring(i1, i2 + 1) : work;
                }
                if (work.Length > 0)
                {
                    List <WindowsNetworkCard> lista = DataModel.NetworkCardList;

                    // lo facciamo solo se la card è diversa
                    if (profile.NetworkCardInfo == null || !profile.NetworkCardInfo.ViewId.Equals(work))
                    {
                        foreach (WindowsNetworkCard item in lista)
                        {
                            if (item.ViewId.Equals(work))
                            {
                                SelectedNetworkCard = item;

                                if (item.CardType == WindowsNetworkCardType.WIRELESS)
                                {
                                    // if present get the active profile
                                    WifiProfile wifiProfile = WifiProfileManager.GetActiveWifiProfileForCard(item);
                                    if (wifiProfile != null)
                                    {
                                        Profile.AssociatedWifiSSID = wifiProfile.SSID;

                                        wifiProfileControl.WifiProfileSelected = true;
                                        wifiProfileControl.WifiProfileSSID     = wifiProfile.SSID;
                                        wifiProfileControl.DisplayConfiguration(Profile);
                                    }
                                }


                                ipControl.DisplayConfiguration(item);
                                dnsConfiguration.DisplayConfiguration(item);
                                macAddressControl.DisplayConfiguration(item);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    SelectedNetworkCard = null;
                }
            }
            DisplaySelectedNetworkCard(false, true);
        }
コード例 #5
0
        /// <summary>
        /// Autodetects the network profile. For the moment it works only for wifi connections!
        /// If no connections found, it return null.
        /// Use
        ///     WindowsNetworkCardManager.EnabledWindowsNetworkCardList
        ///     WifiProfileManager.ActiveWifiProfile;
        /// </summary>
        ///
        /// <param name="profiles">profiles.</param>
        /// <returns></returns>
        public static NetworkProfile AutodetectNetworkProfile(List <NetworkProfile> profiles)
        {
            NetworkProfileHelper.FireNotifyEvent("Start autodetect");
            if (profiles == null || profiles.Count == 0)
            {
                NetworkProfileHelper.FireNotifyEvent("There's no profiles");
                NetworkProfileHelper.FireNotifyEvent("End autodetect");
                return(null);
            }
            // initial setup for cards
            SetupNetworkCardForAutodetect(profiles);

            NetworkProfile selectedProfile = null;

            // one or more card (not only wifi)
            // wifi connected,
            WifiProfile currentWifiProfile = WifiProfileManager.ActiveWifiProfile;

            // enable card
            List <WindowsNetworkCard> enabledCardList = WindowsNetworkCardManager.EnabledWindowsNetworkCardList;

            if (enabledCardList.Count == 1 && enabledCardList[0].CardType == WindowsNetworkCardType.WIRELESS && currentWifiProfile.SSID != null)
            {
                WindowsNetworkCard card = enabledCardList[0];
                // only a wifi connection avaible
                foreach (NetworkProfile item in profiles)
                {
                    // select if card is right and (ssid is right or for that profile there's no ssid)
                    if (item.NetworkCardInfo.Id.Equals(card.Id) && (currentWifiProfile.SSID.Equals(item.AssociatedWifiSSID) || string.IsNullOrWhiteSpace(item.AssociatedWifiSSID)))
                    {
                        // ok, we found it!!!
                        selectedProfile = item;

                        if (!string.IsNullOrWhiteSpace(item.AssociatedWifiSSID))
                        {
                            NetworkProfileHelper.FireNotifyEvent("The card " + card.Name + " are connected with right SSID (" + currentWifiProfile.SSID + ")");
                        }
                        NetworkProfileHelper.FireNotifyEvent("Selected profile " + item.Name + " without do anything else!!");
                        break;
                    }
                }
            }
            else
            {
                // order list by maxSpeed
                //enabledCardList.Sort(CompareCardBySpeed);

                // if there's no enabled card, it's a problem!
                if (enabledCardList.Count == 0)
                {
                    NetworkProfileHelper.FireNotifyEvent("No card enabled, found"); return(null);
                }

                List <NetworkProfile> enabledProfileList = FindValidOrderedNetworkProfiles(profiles, enabledCardList, currentWifiProfile);

                // assert: enabledProfile contains the right profiles. Now we have to test it.
                // the first with ping ok it's ok!
                bool pingOk;
                foreach (NetworkProfile item in enabledProfileList)
                {
                    NetworkProfileHelper.FireNotifyEvent("Start analizing profile " + item.Name + " with card " + item.NetworkCardInfo.Name);
                    //WindowsNetworkCardHelper.SetDeviceStatus(item.NetworkCardInfo, false);
                    NetworkProfileHelper.RunDisableNetworkCardsSetup(item);
                    NetworkProfileHelper.RunNetworkCardSetup(item);

                    // wait for a while
                    //NetworkProfileHelper.FireNotifyEvent("Wait " + (WAIT_BEFORE_PING) + " ms.");
                    //System.Threading.Thread.Sleep(WAIT_BEFORE_PING);
                    WindowsNetworkCardEventHandler eventHandler = new WindowsNetworkCardEventHandler(item.NetworkCardInfo);

                    eventHandler.WaitUntilNetworkCardIsUp();
                    //WaitUntilNetworkCardIsUp(item.NetworkCardInfo);

                    NetworkProfileHelper.FireNotifyEvent("Wait " + (WAIT_BEFORE_PING) + " ms.");
                    System.Threading.Thread.Sleep(WAIT_BEFORE_PING);

                    WindowsNetworkCard card = WindowsNetworkCardManager.RefreshStatus(item.NetworkCardInfo.Id);

                    if (card.CardType == WindowsNetworkCardType.WIRELESS)
                    {
                        // get current wifi profile only for wifi card
                        currentWifiProfile = WifiProfileManager.GetActiveWifiProfileForCard(card);

                        if (currentWifiProfile != null && currentWifiProfile.SSID.Equals(item.AssociatedWifiSSID) && card.NetConnectionStatus == 2)
                        {
                            // ok, we found it!!!
                            selectedProfile = item;
                            NetworkProfileHelper.FireNotifyEvent("The card " + card.Name + " are connected with right SSID (" + currentWifiProfile.SSID + ")");
                            NetworkProfileHelper.FireNotifyEvent("Selected profile " + item.Name + " without do anything else!!");
                            break;
                        }
                    }
                    else
                    {
                        pingOk = false;

                        NetworkProfileHelper.FireNotifyEvent("The card " + card.Name + " are in status " + card.NetConnectionStatus);
                        // test both static config or dynamic config
                        pingOk = PingHelper.RunPing(card.GatewayAddress);
                        pingOk = pingOk || PingHelper.RunPing(card.CurrentGatewayAddress);

                        NetworkProfileHelper.FireNotifyEvent("For card " + card.Name + " and profile " + item.Name + ", ping to gateway are " + pingOk);

                        if (pingOk)
                        {
                            selectedProfile = item;
                            NetworkProfileHelper.FireNotifyEvent("Selected profile " + item.Name + "!!");
                            break;
                        }
                    }

                    NetworkProfileHelper.FireNotifyEvent("Stop analizing profile " + item.Name + ", go to next profile");
                }

                // restore initial enabled card
                if (selectedProfile == null)
                {
                    NetworkProfileHelper.FireNotifyEvent("No profile found, so restore status card");
                    foreach (WindowsNetworkCard item in enabledCardList)
                    {
                        NetworkProfileHelper.FireNotifyEvent("Enable card " + item.Name);
                        WindowsNetworkCardHelper.SetDeviceStatus(item, true);
                    }
                }
            }

            NetworkProfileHelper.FireNotifyEvent("End autodetect");
            return(selectedProfile);
        }
コード例 #6
0
        /// <summary>
        /// Finds the valid network profiles. Filter the profile with enabled card. If a profile has an SSI associated
        /// this SSID must be the current SSID.
        ///
        /// Profiles are ordered by network card speed.
        /// </summary>
        /// <param name="profiles">The profiles.</param>
        /// <param name="enabledCardList">The enabled card list.</param>
        /// <param name="currentWifiProfile">The current wifi profile.</param>
        /// <returns></returns>
        internal static List <NetworkProfile> FindValidOrderedNetworkProfiles(List <NetworkProfile> profiles, List <WindowsNetworkCard> enabledCardList, WifiProfile currentWifiProfile)
        {
            List <NetworkProfile> enabledProfileList = new List <NetworkProfile>();

            foreach (WindowsNetworkCard itemCard in enabledCardList)
            {
                foreach (NetworkProfile itemProfile in profiles)
                {
                    // check if card is right
                    if (itemCard.Id.Equals(itemProfile.NetworkCardInfo.Id))
                    {
                        // copy nic info
                        itemProfile.NetworkCardInfo.MaxSpeed    = itemCard.MaxSpeed;
                        itemProfile.NetworkCardInfo.CardType    = itemCard.CardType;
                        itemProfile.NetworkCardInfo.AdapterType = itemCard.AdapterType;

                        // check if is a wifi connection
                        if (currentWifiProfile != null)
                        {
                            // check if card has an associated ssid
                            if (itemProfile.AssociatedWifiSSID != null && itemProfile.AssociatedWifiSSID.Trim().Length > 0)
                            {
                                // check if profile ssid and current ssid are equal
                                if (currentWifiProfile.SSID.Equals(itemProfile.AssociatedWifiSSID))
                                {
                                    enabledProfileList.Add(itemProfile);
                                }
                                else
                                {
                                    // wrogin SSID, ignore it
                                }
                            }
                            else
                            {
                                // no SSID associated, every SSID is ok
                                enabledProfileList.Add(itemProfile);
                            }
                        }
                        else
                        {
                            // there's no current wifi network connected
                            // card is enabled, profile is associated this profile
                            enabledProfileList.Add(itemProfile);
                        }
                    }
                }
            }

            // sort enabled profile by card speed
            enabledProfileList.Sort(CompareProfileByCardSpeed);
            return(enabledProfileList);
        }