Example #1
0
        public static AdapterVendors CreateVendorLookup()
        {
            AdapterVendors vendors = new AdapterVendors();

            try
            {
                vendors.LoadFromOui();
            }
            catch
            {
                throw new Exception(Localizer.GetString("ErrorLoadingVendorNames"));
            }

            return(vendors);
        }
Example #2
0
 public NetworkDataCacheN()
 {
     _av = new AdapterVendors();
 }
        private void InternalStationsRead()
        {
            // do shit here!
            //
            List <IPInfo> ipInfoDataList = null;
            var           getInfoList    = new Func <List <IPInfo> >(() =>
            {
                if (ipInfoDataList == null)
                {
                    ipInfoDataList = IPInfo.GetIPInfo();
                }
                return(ipInfoDataList);
            });

            // they are not checked yet
            for (int i = 0; i < _stationUsers.Count; i++)
            {
                _stationUsers[0]._checked = false;
            }

            var  newUsers    = new List <StationUser>();
            bool userAdded   = false,
                 userRemoved = false,
                 userUpdated = false;

            foreach (var station in _wlanManager.Stations)
            {
                var stationMac = station.Value.MacAddress;

                var stationUser = _stationUsers.FirstOrDefault(a => a.MacAddress == stationMac);
                if (stationUser == null)
                {
                    stationUser = new StationUser
                    {
                        Status     = StationUser.UserStatus.Connecting,
                        HostName   = "",
                        IpAddress  = "",
                        JoinDate   = DateTime.Now,
                        MacAddress = stationMac,
                        Vendor     = AdapterVendors.GetVendor(stationMac)
                    };
                    _stationUsers.Add(stationUser);
                    newUsers.Add(stationUser);
                    userAdded = true;
                }
                stationUser._checked = true;

                // user is not connected yet!
                if (string.IsNullOrEmpty(stationUser.IpAddress) ||
                    string.IsNullOrEmpty(stationUser.HostName) ||
                    stationUser.HostName.Length == 0)
                {
                    var stationMacCompare = station.Value.MacAddress.ToLowerInvariant().Replace(':', '-');
                    var ipInfo            = getInfoList().FirstOrDefault(a => a.MacAddress.ToLowerInvariant() == stationMacCompare);

                    if (ipInfo != null)
                    {
                        stationUser.IpAddress = ipInfo.IPAddress;
                        stationUser.HostName  = ipInfo.HostName;
                        if (stationUser.HostName == null)
                        {
                            stationUser.HostName         = stationMac;
                            stationUser.HostNameResolved = false;
                        }
                        else
                        {
                            stationUser.HostNameResolved = true;
                        }
                        userUpdated        = true;
                        stationUser.Status = StationUser.UserStatus.Connected;
                    }
                    else
                    {
                        stationUser.HostName         = stationMac;
                        stationUser.IpAddress        = "";
                        stationUser.HostNameResolved = false;
                    }
                }
                else if (stationUser.HostNameResolved == false)
                {
                    if (stationUser.CanTryResolveHost())
                    {
                        if (stationUser.ResolveHostName())
                        {
                            userUpdated = true;
                        }
                    }
                    else
                    {
                        // do not read the host name again
                        stationUser.HostNameResolved = true;
                    }
                }
            }

            for (int i = _stationUsers.Count - 1; i >= 0; i--)
            {
                var user = _stationUsers[i];
                if (!user._checked)
                {
                    userRemoved             = true;
                    _stationUsers[i].Status = StationUser.UserStatus.Disconnect;
                    _stationUsers.RemoveAt(i);
                }
                user._checked = false;
            }

            if (userAdded)
            {
                RaiseOnUserConnected(newUsers);
            }
            if (userUpdated)
            {
                RaiseOnUserUpdated();
            }
            if (userRemoved)
            {
                RaiseOnUserLeave();
            }
        }