/*------------------------------------------------------------------------- // UNCLASSIFIED /*------------------------------------------------------------------------- RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON COMPANY. THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT. UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY. -------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Windows; using System.Windows.Threading; using NLog; using ProgramLib.GUI.View; namespace ProgramLib { /// /// Class that manages all GUIs /// internal class ProgramGuiManager : IDisposable { #region Private Members private Thread _guiManagerThread; private static NLog.ILogger _logger; private Dictionary _windowDict = new Dictionary(); private ManualResetEvent _allGuiInitializedEvent = new ManualResetEvent(false); private bool _isDisposed = false; #endregion #region Public Members public enum WINDOWS { LIVE_DATA, MANUAL_CONTROL, IMPEDANCE_CHECK, MSFR_TEST_CASES, CONFIRMATION, // DO NOT modify this. DEFAULT } #endregion /// /// constructor /// public ProgramGuiManager() { _logger = LogManager.GetCurrentClassLogger(); } public Window this[WINDOWS window] { get { if (window == WINDOWS.DEFAULT) { return _windowDict[(WINDOWS)0]; } return _windowDict[window]; } } /// /// Initialize all the GUIs /// public void Initialize() { _guiManagerThread = new Thread(new ThreadStart(GuiManagerThread)); _guiManagerThread.SetApartmentState(ApartmentState.STA); _guiManagerThread.Start(); _allGuiInitializedEvent.WaitOne(); } /// /// Constructor /// private void GuiManagerThread() { _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running..."); // instantiate all the windows here _windowDict[WINDOWS.LIVE_DATA] = new LiveDataWindow(); _windowDict[WINDOWS.MANUAL_CONTROL] = new ManualControlWindow(); _windowDict[WINDOWS.IMPEDANCE_CHECK] = new ImpedanceCheckWindow(); _windowDict[WINDOWS.MSFR_TEST_CASES] = new MsfrTestCasesWindow(); _windowDict[WINDOWS.CONFIRMATION] = new ConfirmationWindow(); _allGuiInitializedEvent.Set(); // Enter the event queue Dispatcher.Run(); _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting..."); } /// /// Destructor /// ~ProgramGuiManager() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ..."); } /// /// Open a wait window with countdown timer /// /// message to display /// number to seconds to wait /// public void DisplayWaitMessage(string message, double delaySec) { this[ProgramGuiManager.WINDOWS.DEFAULT].Dispatcher.Invoke((Action)delegate { WaitWindow waitWindow = new WaitWindow(message, delaySec); waitWindow.ShowDialog(); }); } /// /// Dispose of this object. /// public void Dispose() { _logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ..."); try { if (!_isDisposed) { _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() disposing"); _windowDict?.First().Value.Dispatcher.Invoke((Action)delegate { // shut down all windows foreach (var entry in _windowDict) { entry.Value.Close(); } // kill the GuiManagerthread Dispatcher.CurrentDispatcher.InvokeShutdown(); }); _isDisposed = true; } } catch (Exception) { } } } }