Mercurial > servermonitor
view ServerMonitor/Objects/CheckResult.cs @ 1:9e92780ebc0f
Additional validation for SSH check
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Tue, 01 Jan 2019 21:14:47 -0500 |
parents | 3e1a2131f897 |
children | 453ecc1ed9ea |
line wrap: on
line source
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 }; } } }