Exemple #1
0
        /// <summary>
        /// Remove the selected profile.
        /// </summary>
        private async Task RemoveProfileAsync()
        {
            BusyStateManager.EnterBusy();
            BusyStateManager.SetMessage(SeverityType.Info, "Removing selected profile.");

            /* Temporary store selected interface and WiFi profile so they can be restored after deletion. */
            Guid selectedInterfaceId = SelectedInterface.Id;
            int  profilePosition     = SelectedWiFiProfile.Position;

            await _mainController.DeleteProfileAsync(SelectedWiFiProfile);

            await DownloadProfilesAsync();

            /* Restore selected interface and position of selected WiFi profile. */
            Profile selectedWifiProfile = WiFiProfiles.Where(x => x.Id == selectedInterfaceId &&
                                                             x.Position == profilePosition).FirstOrDefault();

            if (selectedWifiProfile == default(Profile))
            {
                selectedWifiProfile = WiFiProfiles.Where(x => x.Id ==
                                                         selectedInterfaceId).OrderByDescending(x => x.Position).FirstOrDefault();
            }

            Interface selectedInterface = Interfaces.Where(x => x.Id == selectedInterfaceId).FirstOrDefault();

            SelectedInterface = selectedInterface == default(Interface) ?
                                Interfaces.FirstOrDefault() : selectedInterface;
            if (selectedWifiProfile != default(Profile))
            {
                SelectedWiFiProfile = selectedWifiProfile;
            }

            BusyStateManager.SetMessage(SeverityType.None);
            BusyStateManager.ExitBusy();
        }
        public string GetContractType()
        {
            if (ContractTags != null)
            {
                if (ContractTags.Contains("fa2"))
                {
                    return("FA2");
                }

                if (ContractTags.Contains("fa1-2"))
                {
                    return("FA12");
                }
            }

            if (Interfaces == null)
            {
                return("FA2");
            }

            if (Interfaces.FirstOrDefault(i => i == "TZIP-12" || i == "TZIP-012" || i.StartsWith("TZIP-012")) != null)
            {
                return("FA2");
            }

            if (Interfaces.FirstOrDefault(i => i == "TZIP-7" || i == "TZIP-007" || i.StartsWith("TZIP-007")) != null)
            {
                return("FA12");
            }

            return("FA2");
        }
            private async Task GetAllInterfaces()
            {
                if (KernelVersion > WindowsKernelVersions.Windows2012And8)
                {
                    //ActiveMaximumTransmissionUnit
                    //MtuSize
                    //
                    //Speed
                }
                else
                {
                }

                const string query = @"SELECT 
                NetConnectionID,
                Description,
                Name,
                MACAddress,
                Speed
                FROM Win32_NetworkAdapter
                WHERE NetConnectionStatus = 2"; //connected adapters.

                //'AND PhysicalAdapter = True' causes exceptions with old windows versions.

                using (var q = Wmi.Query(Name, query))
                {
                    foreach (var data in await q.GetDynamicResult())
                    {
                        string name      = data.Name,
                                 caption = data.NetConnectionID;
                        if (caption == "Ethernet")
                        {
                            caption = name;
                        }

                        var i = Interfaces.FirstOrDefault(x => x.Name == name && x.Caption == caption);
                        if (i == null)
                        {
                            i = new Interface();
                            Interfaces.Add(i);
                        }

                        i.Alias           = "!alias";
                        i.Caption         = caption;
                        i.FullName        = data.Description;
                        i.IfName          = data.Name;
                        i.Id              = $"{Id}-Int-{Interfaces.Count + 1}";
                        i.NodeId          = Id;
                        i.Index           = 0;
                        i.IsTeam          = false; //TODO: Fix
                        i.LastSync        = DateTime.UtcNow;
                        i.Name            = name;
                        i.PhysicalAddress = data.MACAddress;
                        i.Speed           = data.Speed;
                        i.Status          = NodeStatus.Active;
                        i.TypeDescription = "";
                    }
                }
            }
Exemple #4
0
        /// <summary>
        /// Retrieves access points and interfaces from the device and updates the view.
        /// </summary>
        private async Task DownloadAccessPointsAsync()
        {
            BusyStateManager.EnterBusy();
            BusyStateManager.SetMessage(SeverityType.Info, "Retrieving access points and interfaces.");

            /* Temporary store selected interface and access point so they can be restored after download. */
            Guid?  interfaceId = SelectedInterface?.Id;
            string profileName = SelectedAccessPoint?.ProfileName;
            string ssid        = SelectedAccessPoint?.Ssid;

            /* Scan and download access points and interfaces. */
            await _mainController.ScanNetworkAsync(TimeSpan.FromSeconds(_configurationProvider.Timeout),
                                                   CancellationToken.None);

            IEnumerable <AccessPoint> accessPoints = await _mainController.GetWiFiAccessPointsAsync();

            IEnumerable <Interface> interfaces = await _mainController.GetWiFiInterfacesAsync();

            if (accessPoints == default(IEnumerable <AccessPoint>) || interfaces == default(IEnumerable <Interface>))
            {
                AccessPoints = new ObservableCollection <AccessPoint>(Enumerable.Empty <AccessPoint>());
                WiFiAccessPointViewSource.Source = AccessPoints;
                Interfaces = new ObservableCollection <Interface>(Enumerable.Empty <Interface>());
            }
            else
            {
                /* User specified threshold is used to filter access points that meet this threshold. */
                AccessPoints = new ObservableCollection <AccessPoint>(accessPoints
                                                                      .Where(x => x.LinkQuality > _configurationProvider.Threshold));
                WiFiAccessPointViewSource.Source = AccessPoints;
                Interfaces = new ObservableCollection <Interface>(interfaces);
            }

            /* Restore selected interface and access point. */
            Interface   selectedInterface   = Interfaces.Where(x => x.Id == interfaceId).FirstOrDefault();
            AccessPoint selectedAccessPoint = default(AccessPoint);

            if (!string.IsNullOrEmpty(profileName))
            {
                selectedAccessPoint = AccessPoints.Where(x => x.Id == interfaceId &&
                                                         x.ProfileName == profileName).FirstOrDefault();
            }
            else if (!string.IsNullOrEmpty(ssid))
            {
                selectedAccessPoint = AccessPoints.Where(x => x.Id == interfaceId &&
                                                         x.Ssid.Equals(ssid, StringComparison.Ordinal)).FirstOrDefault();
            }

            SelectedInterface = selectedInterface == default(Interface) ?
                                Interfaces.FirstOrDefault() : selectedInterface;

            if (selectedAccessPoint != default(AccessPoint))
            {
                SelectedAccessPoint = selectedAccessPoint;
            }

            BusyStateManager.SetMessage(SeverityType.None);
            BusyStateManager.ExitBusy();
        }
Exemple #5
0
        private void InitializeNetworkInteraces()
        {
            // TODO : implement start/stop/change active interface
            _loginServerIp = Dns.GetHostAddresses("game.survarium.com").FirstOrDefault();
            var nic = NetworkInterfaces.GetBestInterface(_loginServerIp).FirstOrDefault();

            Interfaces.Add(new NetworkInterfaceModel(nic));
            SelectedNetworkInterface = Interfaces.FirstOrDefault();
        }
Exemple #6
0
            private async Task PollNetworkUtilization()
            {
                const string query = @"
SELECT Name,
       BytesReceivedPersec,
       BytesSentPersec,
       PacketsReceivedPersec,
       PacketsSentPersec
  FROM Win32_PerfFormattedData_Tcpip_NetworkInterface";

                var queryTime    = DateTime.UtcNow.ToEpochTime();
                var combinedUtil = new Interface.InterfaceUtilization
                {
                    DateEpoch = queryTime,
                    InAvgBps  = 0,
                    OutAvgBps = 0
                };

                using (var q = Wmi.Query(Name, query))
                {
                    foreach (var data in await q.GetDynamicResult())
                    {
                        if (data == null)
                        {
                            continue;
                        }
                        var iface = Interfaces.FirstOrDefault(i => data.Name == GetCounterName(i.Name));
                        if (iface == null)
                        {
                            continue;
                        }

                        iface.InBps  = data.BytesReceivedPersec;
                        iface.OutBps = data.BytesSentPersec;
                        iface.InPps  = data.PacketsReceivedPersec;
                        iface.OutPps = data.PacketsSentPersec;

                        var util = new Interface.InterfaceUtilization
                        {
                            DateEpoch = queryTime,
                            InAvgBps  = iface.InBps,
                            OutAvgBps = iface.OutBps
                        };

                        var netData = NetHistory.GetOrAdd(iface.Name, k => new List <Interface.InterfaceUtilization>(1024));
                        UpdateHistoryStorage(netData, util);

                        if (PrimaryInterfaces.Contains(iface))
                        {
                            combinedUtil.InAvgBps  += util.InAvgBps;
                            combinedUtil.OutAvgBps += util.OutAvgBps;
                        }
                    }
                }
                UpdateHistoryStorage(CombinedNetHistory, combinedUtil);
            }
Exemple #7
0
            internal List <Interface.InterfaceUtilization> GetInterfaceUtilizationHistory(Interface iface)
            {
                List <Interface.InterfaceUtilization> result;

                if (iface != null &&
                    Interfaces.FirstOrDefault(x => x == iface) != null &&
                    NetHistory.ContainsKey(iface.Name))
                {
                    result = NetHistory[iface.Name];
                }
                else
                {
                    result = new List <Interface.InterfaceUtilization>(0);
                }
                return(result);
            }
Exemple #8
0
            internal List <Interface.InterfaceUtilization> GetInterfaceUtilizationHistory(Interface @interface)
            {
                List <Interface.InterfaceUtilization> result;

                if (@interface != null &&
                    Interfaces.FirstOrDefault(x => x == @interface) != null &&
                    _netUtilization.ContainsKey(@interface.Name))
                {
                    result = _netUtilization[@interface.Name];
                }
                else
                {
                    result = new List <Interface.InterfaceUtilization>(0);
                }
                return(result);
            }
Exemple #9
0
            public void AddNetworkUtilization(Interface iface, Interface.InterfaceUtilization item)
            {
                if (iface == null)
                {
                    return;
                }

                var ownIface = Interfaces.FirstOrDefault(x => x == iface);

                if (ownIface == null)
                {
                    return;
                }

                List <Interface.InterfaceUtilization> data;

                if (!_netUtilization.ContainsKey(ownIface.Name))
                {
                    data = new List <Interface.InterfaceUtilization>(1024);
                    _netUtilization[ownIface.Name] = data;
                }
                else
                {
                    data = _netUtilization[ownIface.Name];
                }

                if (!item.InAvgBps.HasValue)
                {
                    item.InAvgBps = item.InMaxBps;
                }
                if (!item.OutAvgBps.HasValue)
                {
                    item.OutAvgBps = item.OutMaxBps;
                }

                if (iface.Speed.HasValue && iface.Speed.Value > 0)
                {
                    item.MaxLoad = (short)(100 * (item.InMaxBps + item.OutMaxBps) / iface.Speed);
                    item.AvgLoad = (short)(100 * (item.InAvgBps + item.OutAvgBps) / iface.Speed);
                }

                UpdateHistoryStorage(data, item, x => x.DateTime);
            }
Exemple #10
0
        /// <summary>
        /// Retrieves the WiFi profiles and interfaces and updates the View.
        /// </summary>
        private async Task DownloadProfilesAsync()
        {
            BusyStateManager.EnterBusy();
            BusyStateManager.SetMessage(SeverityType.Info, "Retrieving profiles and interfaces.");

            /* Temporary store selected interface and wifi profile so they can be restored after download. */
            Guid?  interfaceId = SelectedInterface?.Id;
            string profileName = SelectedWiFiProfile?.ProfileName;

            /* Download wifi profiles and interfaces. */
            IEnumerable <Profile> profiles = await _mainController.GetWiFiProfilesAsync();

            IEnumerable <Interface> interfaces = await _mainController.GetWiFiInterfacesAsync();

            if (profiles == default(IEnumerable <Profile>) || interfaces == default(IEnumerable <Interface>))
            {
                WiFiProfiles = new ObservableCollection <Profile>(Enumerable.Empty <Profile>());
                WiFiProfilesViewSource.Source = WiFiProfiles;
                Interfaces = new ObservableCollection <Interface>(Enumerable.Empty <Interface>());
            }
            else
            {
                WiFiProfiles = new ObservableCollection <Profile>(profiles);
                WiFiProfilesViewSource.Source = WiFiProfiles;
                Interfaces = new ObservableCollection <Interface>(interfaces);
            }

            /* Restore selected interface and wifi profile. */
            Interface selectedInterface   = Interfaces.Where(x => x.Id == interfaceId).FirstOrDefault();
            Profile   selectedWifiProfile = WiFiProfiles.Where(x => x.Id == interfaceId &&
                                                               x.ProfileName == profileName).FirstOrDefault();

            SelectedInterface = selectedInterface == default(Interface) ?
                                Interfaces.FirstOrDefault() : selectedInterface;
            if (selectedWifiProfile != default(Profile))
            {
                SelectedWiFiProfile = selectedWifiProfile;
            }

            BusyStateManager.SetMessage(SeverityType.None);
            BusyStateManager.ExitBusy();
        }
Exemple #11
0
 public Interface GetInterface(string id) => Interfaces.FirstOrDefault(i => i.Id == id);
 public Interface GetFirstFreeInterface()
 {
     return(Interfaces.FirstOrDefault(x => !x.IsConnected));
 }
Exemple #13
0
            private async Task GetAllInterfacesAsync()
            {
                const string query = @"
SELECT Name,
       DeviceID,
       NetConnectionID,
       Description,
       MACAddress,
       Speed,
       InterfaceIndex
  FROM Win32_NetworkAdapter
 WHERE NetConnectionStatus = 2"; //connected adapters.
                //'AND PhysicalAdapter = True' causes exceptions with old windows versions.
                var indexMap = new Dictionary <uint, Interface>();

                using (var q = Wmi.Query(Endpoint, query))
                {
                    foreach (var data in await q.GetDynamicResultAsync().ConfigureAwait(false))
                    {
                        string id = $"{data.DeviceID}";
                        var    i  = Interfaces.FirstOrDefault(x => x.Id == id);
                        if (i == null)
                        {
                            i = new Interface();
                            Interfaces.Add(i);
                        }
                        indexMap[data.InterfaceIndex] = i;

                        i.Id              = $"{data.DeviceID}";
                        i.Alias           = "!alias";
                        i.Caption         = data.NetConnectionID == "Ethernet" ? data.Name : data.NetConnectionID;
                        i.FullName        = data.Description;
                        i.NodeId          = Id;
                        i.LastSync        = DateTime.UtcNow;
                        i.Name            = data.Name;
                        i.PhysicalAddress = data.MACAddress;
                        i.Speed           = data.Speed;
                        i.Status          = NodeStatus.Active;
                        i.TypeDescription = "";
                        i.IPs             = new List <IPNet>();
                    }
                }

                const string ipQuery = @"
Select InterfaceIndex, IPAddress, IPSubnet, DHCPEnabled
  From WIn32_NetworkAdapterConfiguration 
 Where IPEnabled = 'True'";

                using (var q = Wmi.Query(Endpoint, ipQuery))
                {
                    foreach (var data in await q.GetDynamicResultAsync().ConfigureAwait(false))
                    {
                        Interface i;
                        if (indexMap.TryGetValue(data.InterfaceIndex, out i))
                        {
                            i.DHCPEnabled = data.DHCPEnabled;
                            string[] ips = data.IPAddress as string[],
                            subnets = data.IPSubnet as string[];
                            for (var j = 0; j < (ips?.Length).GetValueOrDefault(0); j++)
                            {
                                IPNet net;
                                int   cidr;
                                if (int.TryParse(subnets[j], out cidr) && IPNet.TryParse(ips[j], cidr, out net))
                                {
                                    i.IPs.Add(net);
                                }
                                else if (IPNet.TryParse(ips[j], subnets[j], out net))
                                {
                                    i.IPs.Add(net);
                                }
                            }
                        }
                    }
                }
            }