diff ServerMonitor/Objects/CheckResult.cs @ 29:f6235dc0a8ec

Add ability to play a sound on check failure.
author Brad Greco <brad@bgreco.net>
date Fri, 14 Jun 2019 21:01:55 -0400
parents 68d7834dc28e
children
line wrap: on
line diff
--- a/ServerMonitor/Objects/CheckResult.cs	Sun Jun 02 17:55:38 2019 -0400
+++ b/ServerMonitor/Objects/CheckResult.cs	Fri Jun 14 21:01:55 2019 -0400
@@ -47,6 +47,32 @@
             }
         }
 
+        /// <summary>Sound to play when the check fails.</summary>
+        /// <remarks>
+        /// Returns null if no sound should be played.
+        /// Returns string.Empty if the Windows default error sound should be played.
+        /// Otherwise, returns the path to the custom sound file that should be played.
+        /// </remarks>
+        public string FailSound
+        {
+            get
+            {
+                string setting = null;
+                // Use the global preferences for each status to determine the action to take.
+                switch (CheckStatus)
+                {
+                    case CheckStatus.Error: setting = Settings.Default.ErrorSound; break;
+                    case CheckStatus.Warning: setting = Settings.Default.WarningSound; break;
+                    case CheckStatus.Information: setting = Settings.Default.InformationSound; break;
+                    // On success (or any other status), do nothing.
+                }
+                if (int.TryParse(setting, out int index)) {
+                    return index == 0 ? null : string.Empty;
+                }
+                return setting;
+            }
+        }
+
         /// <summary>CheckResult constructor.</summary>
         /// <param name="check">The originating check of this check result.</param>
         /// <param name="status">The result status of the check execution.</param>