示例#1
0
        public void CalculateUpDown()
        {
            HistoryTimeline = HistoryTimeline.OrderByDescending(o => o.CreatedUtc).ToList();
            History         = History.OrderByDescending(o => o.CreatedUtc).ToList();
            HistoryHealth   = HistoryHealth.OrderByDescending(o => o.CreatedUtc).ToList();

            LastReportedUtc = CreatedUtc;
            var hasErrors = false;
            var isUp      = false;

            var list = HistoryHealth.Where(o =>
                                           o.Errors.Length > 0 ||
                                           o.Internet.HasValue && o.Internet.Value == false ||
                                           o.Permissions.HasValue && o.Permissions.Value == false
                                           )
                       .OrderByDescending(o => o.CreatedUtc).ToList();

            hasErrors = list.Count > 0;

            while (!isUp)
            {
                if (History.Count > 0)
                {
                    var h = History.OrderBy(o => o.CreatedUtc).Last();
                    if (h != null)
                    {
                        isUp            = h.CreatedUtc.AddMinutes(Program.ClientConfig.OfflineAfterMinutes) > DateTime.UtcNow;
                        LastReportedUtc = h.CreatedUtc;
                    }
                }

                if (HistoryHealth.Count > 0)
                {
                    var h = HistoryHealth.OrderBy(o => o.CreatedUtc).Last();
                    if (h != null)
                    {
                        isUp = h.CreatedUtc.AddMinutes(Program.ClientConfig.OfflineAfterMinutes) > DateTime.UtcNow;
                        if (h.CreatedUtc > LastReportedUtc)
                        {
                            LastReportedUtc = h.CreatedUtc;
                        }
                    }
                }

                if (HistoryTimeline.Count > 0)
                {
                    var h = HistoryTimeline.OrderBy(o => o.CreatedUtc).Last();
                    if (h != null)
                    {
                        isUp = h.CreatedUtc.AddMinutes(Program.ClientConfig.OfflineAfterMinutes) > DateTime.UtcNow;
                        if (h.CreatedUtc > LastReportedUtc)
                        {
                            LastReportedUtc = h.CreatedUtc;
                        }
                    }
                }

                break;
            }

            if (hasErrors)
            {
                StatusUp = isUp ? UpDownStatus.UpWithErrors : UpDownStatus.DownWithErrors;
            }
            else
            {
                StatusUp = isUp ? UpDownStatus.Up : UpDownStatus.Down;
            }
        }
示例#2
0
 public void AddHistoryHealth(HistoryHealth model)
 {
     this.HistoryHealth.Add(model);
     this.CalculateUpDown();
 }
示例#3
0
 public void AddHistoryHealth(HistoryHealth model)
 {
     HistoryHealth.Add(model);
     CalculateUpDown();
 }