comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:3e1a2131f897
1 using ServerMonitorApp.Properties;
2 using System;
3 using System.Collections.Generic;
4 using System.ComponentModel;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9
10 namespace ServerMonitorApp
11 {
12 static class Helpers
13 {
14 public static void FormatImageButton(Button button)
15 {
16 button.Image = new Bitmap(button.Image, button.Height - 8, button.Height - 8);
17 }
18
19 public static string GetAllMessages(this Exception ex)
20 {
21 return "\t" + (ex.InnerException == null ? ex.Message : ex.Message + Environment.NewLine + ex.InnerException.GetAllMessages());
22 }
23
24 public static string GetDisplayName(Type type)
25 {
26 return type?.GetAttribute<DisplayNameAttribute>()?.DisplayName ?? type?.Name ?? "null";
27 }
28
29 public static bool IsNullOrEmpty(this string aString)
30 {
31 return aString == null || aString.Trim() == string.Empty;
32 }
33
34 public static T GetAttribute<T>(this Type type) where T : Attribute
35 {
36 return type.GetCustomAttributes(typeof(T), false).SingleOrDefault() as T;
37 }
38
39 public static Image GetIcon(this CheckStatus checkStatus)
40 {
41 switch (checkStatus)
42 {
43 case CheckStatus.Error: return Resources.error;
44 case CheckStatus.Warning: return Resources.warning;
45 case CheckStatus.Information: return Resources.info;
46 case CheckStatus.Success: return Resources.pass;
47 case CheckStatus.Running: return Resources.run;
48 default: return null;
49 }
50 }
51
52 public static bool In(this Enum value, params Enum[] values) {
53 return values.Contains(value);
54 }
55 }
56 }