public void AddHistoryItem(FixedSizeQueue <NetworkStatQueue> from, int count, FixedSizeQueue <NetworkStatQueue> to, long index)
        {
            if (from.Count() < count)
            {
                return;
            }
            double down = 0;
            double up   = 0;

            for (int i = 1; i <= count; i++)
            {
                NetworkStatQueue sample = from.ElementAt(history.Count() - i);
                down += sample.Download;
                up   += sample.Upload;
            }
            down /= count;
            up   /= count;

            var hourSample = new NetworkStatQueue
            {
                SampleID = index,
                Download = down,
                Upload   = up
            };

            to.Enqueue(hourSample);
        }
        // Takes the last 2 samples and gets the current bandwidth values
        // The converted bandwidth is used to create the hour and day history instead of using the totals
        public void UpdateBandwidth()
        {
            if (historyTotals.Count() < 2)
            {
                return;
            }

            NetworkStatQueue sample  = historyTotals.ElementAt(historyTotals.Count() - 1);
            NetworkStatQueue sample2 = historyTotals.ElementAt(historyTotals.Count() - 2);
            double           down    = sample.Download - sample2.Download;
            double           up      = sample.Upload - sample2.Upload;
            var hourSample           = new NetworkStatQueue
            {
                SampleID = sample.SampleID,
                Download = down,
                Upload   = up
            };

            history.Enqueue(hourSample);
        }
        public void AddInterface(NetworkInterface adapter)
        {
            if (adapter.NetworkInterfaceType == NetworkInterfaceType.Tunnel || adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
            {
                return;
            }
            if (adapter.OperationalStatus == OperationalStatus.Down)
            {
                return;
            }

            bool found = false;

            foreach (var s in _interfaces)
            {
                if (s.name == adapter.Name)
                {
                    found = true;
                }
            }
            if (found == false)
            {
                var inf = new StatNetworkItem(adapter.Name);
                _interfaces.Add(inf);
                sessionID = DateTime.Now.Ticks;
            }

            foreach (var s in _interfaces)
            {
                if (s.name == adapter.Name)
                {
                    if (resetAddresses)
                    {
                        s.address = null;
                        IPInterfaceProperties properties = adapter.GetIPProperties();
                        UnicastIPAddressInformationCollection uniCast = properties.UnicastAddresses;
                        foreach (UnicastIPAddressInformation uni in uniCast)
                        {
                            var address = uni.Address.ToString();
                            if (address.Contains("127."))
                            {
                                continue;
                            }

                            Match match = Regex.Match(address, @"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", RegexOptions.IgnoreCase);
                            if (match.Success)
                            {
                                s.address = address;
                            }
                        }
                    }

                    var ns = new NetworkStatQueue
                    {
                        Upload   = adapter.GetIPv4Statistics().BytesSent,
                        Download = adapter.GetIPv4Statistics().BytesReceived,
                        SampleID = historyIndex
                    };
                    s.historyTotals.Enqueue(ns);
                    s.UpdateBandwidth();
                }
            }
        }
        public void AddInterface(NetworkInterface adapter)
        {
            if (adapter.NetworkInterfaceType == NetworkInterfaceType.Tunnel || adapter.NetworkInterfaceType == NetworkInterfaceType.Loopback)
                return;
            if (adapter.OperationalStatus == OperationalStatus.Down)
                return;

                bool found = false;
                foreach (var s in _interfaces){
                    if (s.name == adapter.Name)
                    {
                        found = true;
                    }
                }
                if(found == false){
                    var inf = new StatNetworkItem(adapter.Name);
                     _interfaces.Add(inf);
                    sessionID = DateTime.Now.Ticks;
                }

                foreach (var s in _interfaces){
                    if(s.name == adapter.Name){
                        if (resetAddresses)
                        {
                            s.address = null;
                            IPInterfaceProperties properties = adapter.GetIPProperties();
                            UnicastIPAddressInformationCollection uniCast = properties.UnicastAddresses;
                            foreach (UnicastIPAddressInformation uni in uniCast)
                            {
                                var address = uni.Address.ToString();
                                if (address.Contains("127."))
                                    continue;

                                Match match = Regex.Match(address, @"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", RegexOptions.IgnoreCase);
                                if (match.Success)
                                {
                                    s.address = address;
                                }
                            }
                        }

                         var ns = new NetworkStatQueue
                         {
                             Upload = adapter.GetIPv4Statistics().BytesSent,
                             Download = adapter.GetIPv4Statistics().BytesReceived,
                             SampleID = historyIndex
                         };
                        s.historyTotals.Enqueue(ns);
                        s.UpdateBandwidth();
                    }
                }
        }
        // Takes the last 2 samples and gets the current bandwidth values
        // The converted bandwidth is used to create the hour and day history instead of using the totals
        public void UpdateBandwidth()
        {
            if (historyTotals.Count() < 2)
                return;

            NetworkStatQueue sample = historyTotals.ElementAt(historyTotals.Count() - 1);
            NetworkStatQueue sample2 = historyTotals.ElementAt(historyTotals.Count() - 2);
            double down = sample.Download - sample2.Download;
            double up = sample.Upload - sample2.Upload;
            var hourSample = new NetworkStatQueue
            {
                SampleID = sample.SampleID,
                Download = down,
                Upload = up
            };
            history.Enqueue(hourSample);
        }
        public void AddHistoryItem(FixedSizeQueue<NetworkStatQueue> from, int count, FixedSizeQueue<NetworkStatQueue> to, long index)
        {
            if (from.Count() < count)
                return;
            double down = 0;
            double up = 0;
            for (int i = 1; i <= count; i++)
            {
                NetworkStatQueue sample = from.ElementAt(history.Count() - i);
                down += sample.Download;
                up += sample.Upload;
            }
            down /= count;
            up /= count;

            var hourSample = new NetworkStatQueue
            {
                SampleID = index,
                Download = down,
                Upload = up
            };
            to.Enqueue(hourSample);
        }