Mercurial > servermonitor
comparison ServerMonitor/Objects/CheckResult.cs @ 0:3e1a2131f897
Initial commit. Ping check, scheduling, UI working. SSH check mostly working.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 31 Dec 2018 18:32:14 -0500 |
parents | |
children | 453ecc1ed9ea |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3e1a2131f897 |
---|---|
1 using ServerMonitorApp.Properties; | |
2 using System; | |
3 using System.Drawing; | |
4 | |
5 namespace ServerMonitorApp | |
6 { | |
7 public class CheckResult | |
8 { | |
9 public const string dateFormat = "yyyy-MM-dd HH:mm:ss.fff"; | |
10 | |
11 public Check Check { get; private set; } | |
12 | |
13 public CheckStatus CheckStatus { get; private set; } | |
14 | |
15 public string Message { get; private set; } | |
16 | |
17 public DateTime StartTime { get; set; } | |
18 | |
19 public DateTime EndTime { get; set; } | |
20 | |
21 public CheckResult(Check check, CheckStatus status, string message) | |
22 { | |
23 Check = check; | |
24 CheckStatus = status; | |
25 Message = message; | |
26 } | |
27 | |
28 public string ToLogString() | |
29 { | |
30 return string.Format("{0:00000} {1} {2} {3} {4}", | |
31 Check.Id, | |
32 StartTime.ToString(dateFormat).Replace("T", " "), | |
33 EndTime.ToString(dateFormat).Replace("T", " "), | |
34 CheckStatus, | |
35 Message.Replace("\r\n", "\n").Replace('\r', '\n').Replace("\n", "\\n")); | |
36 } | |
37 | |
38 public static CheckResult FromLogString(Check check, string logString) | |
39 { | |
40 DateTime startTime = DateTime.Parse(logString.Substring(6, 23)); | |
41 DateTime endTime = DateTime.Parse(logString.Substring(30, 23)); | |
42 int messageStartPos = logString.IndexOf(' ', 54); | |
43 Enum.TryParse(logString.Substring(54, messageStartPos - 54), out CheckStatus status); | |
44 return new CheckResult(check, status, logString.Substring(messageStartPos + 1)) { StartTime = startTime, EndTime = endTime }; | |
45 } | |
46 } | |
47 } |