using System; using System.Collections.Generic; using System.Linq; using System.Text; using Watchdog.WatchdogLib.Other; namespace Watchdog { /// /// Keeps Track of RunTime State Variables/Objects /// public static class AppState { private static object s_LockObject = new Object(); #region Internal State Check Functions /// true if the Process Monitor is running, false otherwise internal static bool IsMonitorRunning() { lock (s_LockObject) { return AppState.State.GetStateValue(AppState.StateKey.ProcessMonitorStarted_bool, false); } } /// true if the Scheduler is running, false otherwise internal static bool IsSchedulerRunning() { lock (s_LockObject) { return AppState.State.GetStateValue(AppState.StateKey.SchedulerIsRunning_bool, false); } } /// true if the Process Monitor encountered errors, false otherwise internal static bool DidMonitorEncounterErrors() { lock (s_LockObject) { return AppState.State.GetStateValue(AppState.StateKey.ProcessMonitorEncounteredErrors_bool, false); } } /// true if the Application is called with Command-Line Parameters, false otherwise internal static bool IsInCommandLinePrmsMode() { lock (s_LockObject) { return AppState.State.GetStateValue(AppState.StateKey.IsInCommandLineMode_bool, false); } } /// true if the Application is attached to a Console Window For Output, false otherwise internal static bool IsAttachedToConsoleWindow() { lock (s_LockObject) { return AppState.State.GetStateValue(AppState.StateKey.IsAttachedToConsoleWindow_bool, false); } } /// When the application is in commandline mode, we want to make sure that a 'real' monitor instance is running, /// in order to communicate with it, this keeps track if that other instance is available internal static bool InCommandLineMode_IsMonitorInstanceAvailable() { lock (s_LockObject) { return AppState.State.GetStateValue(AppState.StateKey.InCommandLineMode_IsMonitorInstanceAvailable_bool, false); } } #endregion #region Internal State Set Functions /// /// Use this to set the Monitor is Running state to true/false /// internal static bool MonitorIsRunning(bool bIsRunning) { lock (s_LockObject) { return AppState.State.SetStateValue(AppState.StateKey.ProcessMonitorStarted_bool, bIsRunning); } } /// /// Use this to set the Scheduler is Running state to true/false /// internal static bool SchedulerIsRunning(bool bIsRunning) { lock (s_LockObject) { return AppState.State.SetStateValue(AppState.StateKey.SchedulerIsRunning_bool, bIsRunning); } } /// /// Use this to set the Monitor's Error State /// internal static bool MonitorEncounterErrors(bool bErrorsOccured) { lock (s_LockObject) { return AppState.State.SetStateValue(AppState.StateKey.ProcessMonitorEncounteredErrors_bool, bErrorsOccured); } } /// /// Use this to set that the Application is called with Command-Line Parameters /// internal static bool CommandLinePrmsMode(bool bIsInCommandLinePrmsMode) { lock (s_LockObject) { return AppState.State.SetStateValue(AppState.StateKey.IsInCommandLineMode_bool, bIsInCommandLinePrmsMode); } } /// /// Use this to set that the Application is attached to a Console Window for Output /// internal static bool AttachedToConsoleWindow(bool bItIsAttached) { lock (s_LockObject) { return AppState.State.SetStateValue(AppState.StateKey.IsAttachedToConsoleWindow_bool, bItIsAttached); } } /// /// Use this to set that the Application can communicate with the 'real' monitor instance that is running. /// internal static bool CommandLineMode_IsMonitorInstanceAvailable(bool bIsAvailable) { lock (s_LockObject) { return AppState.State.GetStateValue(AppState.StateKey.InCommandLineMode_IsMonitorInstanceAvailable_bool, bIsAvailable); } } #endregion /// /// Various Keys that we can use to save/get the GUI State /// internal enum StateKey { ProcessMonitorStarted_bool, ProcessMonitorEncounteredErrors_bool, SchedulerIsRunning_bool, IsInCommandLineMode_bool, IsAttachedToConsoleWindow_bool, InCommandLineMode_IsMonitorInstanceAvailable_bool, } // Initialize BkgdState internal static readonly StateM State = new StateM(typeof(StateKey)); } }