diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ServerMonitor/Objects/CheckResult.cs	Mon Dec 31 18:32:14 2018 -0500
@@ -0,0 +1,47 @@
+using ServerMonitorApp.Properties;
+using System;
+using System.Drawing;
+
+namespace ServerMonitorApp
+{
+    public class CheckResult
+    {
+        public const string dateFormat = "yyyy-MM-dd HH:mm:ss.fff";
+
+        public Check Check { get; private set; }
+
+        public CheckStatus CheckStatus { get; private set; }
+
+        public string Message { get; private set; }
+
+        public DateTime StartTime { get; set; }
+
+        public DateTime EndTime { get; set; }
+
+        public CheckResult(Check check, CheckStatus status, string message)
+        {
+            Check = check;
+            CheckStatus = status;
+            Message = message;
+        }
+
+        public string ToLogString()
+        {
+            return string.Format("{0:00000} {1} {2} {3} {4}",
+                Check.Id,
+                StartTime.ToString(dateFormat).Replace("T", " "),
+                EndTime.ToString(dateFormat).Replace("T", " "),
+                CheckStatus,
+                Message.Replace("\r\n", "\n").Replace('\r', '\n').Replace("\n", "\\n"));
+        }
+
+        public static CheckResult FromLogString(Check check, string logString)
+        {
+            DateTime startTime = DateTime.Parse(logString.Substring(6, 23));
+            DateTime endTime = DateTime.Parse(logString.Substring(30, 23));
+            int messageStartPos = logString.IndexOf(' ', 54);
+            Enum.TryParse(logString.Substring(54, messageStartPos - 54), out CheckStatus status);
+            return new CheckResult(check, status, logString.Substring(messageStartPos + 1)) { StartTime = startTime, EndTime = endTime };
+        }
+    }
+}
\ No newline at end of file