Пример #1
0
        public PingInformation GetInternetUserPingInformation(int internetUserId)
        {
            var lastFailed = _pingRepository.GetLastFailedInternetUserPing(internetUserId);

            if (lastFailed != null)
            {
                var lastSuccessfull = _pingRepository.GetLastSuccessfullInternetUserPing(internetUserId, lastFailed.Recorded);
                if (lastSuccessfull != null && lastSuccessfull.Recorded > lastFailed.Recorded)
                {
                    TimeSpan duration = DateTime.Now.Subtract(lastSuccessfull.Recorded);
                    return(new PingInformation
                    {
                        LastFailDate = lastFailed.Recorded,
                        Uptime = (long)duration.TotalMilliseconds
                    });
                }

                return(new PingInformation
                {
                    LastFailDate = lastFailed.Recorded,
                    Uptime = 0
                });
            }

            var firstSuccessfull = _pingRepository.GetFirstSuccessfullInternetUserPing(internetUserId);

            if (firstSuccessfull != null)
            {
                TimeSpan durationFirst = DateTime.Now.Subtract(firstSuccessfull.Recorded);
                return(new PingInformation
                {
                    LastFailDate = null,
                    Uptime = (long)durationFirst.TotalMilliseconds
                });
            }

            return(null);
        }