using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Threading; // Ooganizer Namespaces using Foo.Platform; using Foo.DataAccessLayer; using Foo.DataAccessLayer.DataTypes; using System.Runtime.InteropServices; namespace Foo.ClientServices.ButtonWPForm { /// /// This class is responsible for launch all secondary threads required for this application as /// well as hold any variables that are needed by all classes /// created. /// [ComVisible(false)] internal class ComponentState { // Declare the Log4net Variable private static log4net.ILog Log = Logger.GetLog4NetInterface(MethodBase.GetCurrentMethod().DeclaringType); /// /// This class manages the state / main variables of the COM+ that maybe needed by multiple classes. /// It is responsible for starting and stopping any secondary threads. /// static ComponentState() { // We must subscribe to assembly resolver Log.Info(string.Format("{0}() - ButtonWPFormCCW ComponentState() called. Application is starting...", MethodBase.GetCurrentMethod().Name)); // Let's Preload the Database *Right here, right now* that should be good for all of us Data.Artifacts.DoesArtifactExistInSystem(DataTypeHelpers.CreateLocationOnlyArtifact("C:\\Dummy.file")); // Start Dispatcher Thread Log.Info(string.Format("{0}() - ButtonWPFormCCW ComponentState() called. Activating DispatcherThread", MethodBase.GetCurrentMethod().Name)); DispatcherThread.Run = true; // Start ButtonHookKeepAlive Thread if (!DebugSpec.SkipCaptionButtonStarter) { Log.Info(string.Format("{0}() - ButtonWPFormCCW ComponentState() called. Calling CaptionButtonStarter", MethodBase.GetCurrentMethod().Name)); CaptionButtonStarter.Run = true; } else { Log.Info(string.Format("{0}() - ButtonWPFormCCW ComponentState() called. Skipping CaptionButtonStarter due to DebugSpec Settings", MethodBase.GetCurrentMethod().Name)); } } /// /// Private Variables /// private static bool s_bApplicationIsRunning = false; /// /// Use this to enable/disable all threads and variables for /// the component states /// public static bool ApplicationIsRunning { get { return s_bApplicationIsRunning; } set { if (!value) { Log.Info(string.Format("{0}() - ComponentState() sApplicationRunning set to False", MethodBase.GetCurrentMethod().Name)); DispatcherThread.Run = false; CaptionButtonStarter.Run = false; } s_bApplicationIsRunning = value; } } /// /// Use this to access the ButtonFormMgr Object in order to /// communicate to ButtonForms (Setter should only be called by /// DispatcherThread) /// public static ButtonFormMgr ButtonFormMgr { get { return DispatcherThread.s_ButtonFormMgr; } } } }