comparison ServerMonitor/Objects/Checks/Check.cs @ 4:3142e52cbe69

Lots more progress
author Brad Greco <brad@bgreco.net>
date Sun, 10 Feb 2019 20:51:26 -0500
parents 453ecc1ed9ea
children 052aa62cb42a
comparison
equal deleted inserted replaced
3:96f0b028176d 4:3142e52cbe69
57 57
58 public string LastMessage { get; set; } 58 public string LastMessage { get; set; }
59 59
60 public CheckStatus Status { get; set; } 60 public CheckStatus Status { get; set; }
61 61
62 public CheckStatus LastRunStatus { get; set; }
63
62 public CheckStatus FailStatus { get; set; } 64 public CheckStatus FailStatus { get; set; }
63 65
64 [XmlIgnore] 66 [XmlIgnore]
65 public Server Server { get; set; } 67 public Server Server { get; set; }
66 68
88 // throw new NotImplementedException(); 90 // throw new NotImplementedException();
89 //} 91 //}
90 92
91 public async Task<CheckResult> ExecuteAsync(CancellationToken token = default(CancellationToken), bool update = true) 93 public async Task<CheckResult> ExecuteAsync(CancellationToken token = default(CancellationToken), bool update = true)
92 { 94 {
93 //TODO check cancellation token before proceeding 95 if (token.IsCancellationRequested)
96 return null;
97
94 CheckResult result; 98 CheckResult result;
95 DateTime startTime = DateTime.Now; 99 DateTime startTime = DateTime.Now;
96 try 100 try
97 { 101 {
98 Task<CheckResult> checkTask = ExecuteCheckAsync(token); 102 Task<CheckResult> checkTask = ExecuteCheckAsync(token);
120 result.EndTime = DateTime.Now; 124 result.EndTime = DateTime.Now;
121 // If a check is executed from the CheckForm, we don't want to update the status or log the event. 125 // If a check is executed from the CheckForm, we don't want to update the status or log the event.
122 if (update) 126 if (update)
123 { 127 {
124 Status = result.CheckStatus; 128 Status = result.CheckStatus;
129 LastRunStatus = result.CheckStatus;
125 LastMessage = result.Message; 130 LastMessage = result.Message;
126 LastRunTime = result.EndTime; 131 LastRunTime = result.EndTime;
127 } 132 }
128 return result; 133 return result;
129 } 134 }
220 bool failed = false; 225 bool failed = false;
221 foreach (CheckResult result in results) 226 foreach (CheckResult result in results)
222 { 227 {
223 if (result == null) 228 if (result == null)
224 continue; 229 continue;
225 if (result.CheckStatus != CheckStatus.Success) 230 if (result.Failed)
226 failed = true; 231 failed = true;
227 message.AppendLine(result.Message); 232 message.AppendLine(result.Message);
228 } 233 }
229 return failed ? Fail(message.ToString().Trim()) : Pass(message.ToString().Trim()); 234 return failed ? Fail(message.ToString().Trim()) : Pass(message.ToString().Trim());
230 } 235 }