Mercurial > servermonitor
view ServerMonitor/Objects/CheckResult.cs @ 3:96f0b028176d
File check
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Fri, 11 Jan 2019 22:34:18 -0500 |
parents | 453ecc1ed9ea |
children | 3142e52cbe69 |
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; 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.ConvertNewlines().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 }; } } }