diff ServerMonitor/Helpers.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/Helpers.cs	Mon Dec 31 18:32:14 2018 -0500
@@ -0,0 +1,56 @@
+using ServerMonitorApp.Properties;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace ServerMonitorApp
+{
+    static class Helpers
+    {
+        public static void FormatImageButton(Button button)
+        {
+            button.Image = new Bitmap(button.Image, button.Height - 8, button.Height - 8);
+        }
+
+        public static string GetAllMessages(this Exception ex)
+        {
+            return "\t" + (ex.InnerException == null ? ex.Message : ex.Message + Environment.NewLine + ex.InnerException.GetAllMessages());
+        }
+
+        public static string GetDisplayName(Type type)
+        {
+            return type?.GetAttribute<DisplayNameAttribute>()?.DisplayName ?? type?.Name ?? "null";
+        }
+
+        public static bool IsNullOrEmpty(this string aString)
+        {
+            return aString == null || aString.Trim() == string.Empty;
+        }
+
+        public static T GetAttribute<T>(this Type type) where T : Attribute
+        {
+            return type.GetCustomAttributes(typeof(T), false).SingleOrDefault() as T;
+        }
+
+        public static Image GetIcon(this CheckStatus checkStatus)
+        {
+            switch (checkStatus)
+            {
+                case CheckStatus.Error: return Resources.error;
+                case CheckStatus.Warning: return Resources.warning;
+                case CheckStatus.Information: return Resources.info;
+                case CheckStatus.Success: return Resources.pass;
+                case CheckStatus.Running: return Resources.run;
+                default: return null;
+            }
+        }
+
+        public static bool In(this Enum value, params Enum[] values) {
+            return values.Contains(value);
+        }
+    }
+}