Example #1
0
        public void AddPing(PingReplyWrapper reply, PingInfo info = null)
        {
            var result = reply != null && reply.Status == System.Net.NetworkInformation.IPStatus.Success
                ? reply.RoundtripTime
                : (long?)null;

            IsNetworkAccessible = result != null;
            if (info == null)
            {
                info = new PingInfo {
                    Time = DateTime.Now
                };
            }
            lock (Pings.GetLock())
            {
                Pings.Add(info);
            }
            info.Roundtrip = result;
            List <PingInfo> lastPings;

            lock (Pings.GetLock())
            {
                lastPings = Pings.Where(p => p.Time > DateTime.Now - Config.Instance.PingGraphTimeSize).ToList();
            }
            var lastPingsSuccess = lastPings.Where(p => p.Roundtrip != null).ToList();

            NetworkAvailability = 100.0 * lastPingsSuccess.Count / lastPings.Count;
            NetworkAvgRoundtrip = lastPingsSuccess.Count == 0
                ? 0
                : (long)lastPingsSuccess.Average(p => p.Roundtrip.Value);
        }