using System.Drawing; using System.Text; using System.Web; using Kaleida.ServiceMonitor.Model.Email; namespace Kaleida.ServiceMonitor.Model.Runtime { public static class MonitorStateExtensions { public static SeverityLevel ToSeverityLevel(this MonitorState state) { if (!state.IsMonitoring) return SeverityLevel.NotMonitoring; if (state.OperationErrorCount == 0) return SeverityLevel.Operational; if (state.OperationErrorCount <= 1) return SeverityLevel.Temperamental; if (state.OperationErrorCount <= 10) return SeverityLevel.Unstable; if (state.OperationErrorCount <= 100) return SeverityLevel.Critical; return SeverityLevel.Dire; } public static Color ToColour(this SeverityLevel level) { switch (level) { case SeverityLevel.Operational: return Color.LightGreen; case SeverityLevel.Temperamental: return Color.Yellow; case SeverityLevel.Unstable: return Color.Orange; case SeverityLevel.Critical: return Color.LightCoral; case SeverityLevel.Dire: return Color.Crimson; default: return Color.Gray; } } public static string ToSummary(this SeverityLevel severityLevel) { return string.Format("{0} {1} ({2})", (int)severityLevel, severityLevel, severityLevel.ToColour().Name); } public static IHtmlString ToSummaryHtml(this SeverityLevel severityLevel) { var colour = severityLevel.ToColour(); var htmlColour = ColorTranslator.ToHtml(colour); var html = new StringBuilder(); html.AppendFormat("<span style='padding:4px; background-color: {0};'>", htmlColour); html.AppendFormat("{0} {1}", (int)severityLevel, severityLevel.ToString().HtmlEncode()); html.AppendFormat(" ({0})</span>", colour.Name); return html.ToString().AsRawHtml(); } } }
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)
Skills that self-taught computer programmers lack