diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs | 108 |
1 files changed, 105 insertions, 3 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 788d2b178..1550e97e1 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -28,6 +28,9 @@ using Tango.PPC.Common.EventLogging; using Tango.BL.Enumerations; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.WatchDog; +using Tango.PPC.UI.Dialogs; +using Tango.Core.Threading; +using Tango.PPC.Common.Messages; namespace Tango.PPC.UI.PPCApplication { @@ -47,6 +50,7 @@ namespace Tango.PPC.UI.PPCApplication private INotificationProvider _notificationProvider; private WatchDogServer _watchdogServer; private ObservablesContext _machineContext; + private ActionTimer _screenLockTimer; /// <summary> /// Occurs when a system restart is required. @@ -89,6 +93,11 @@ namespace Tango.PPC.UI.PPCApplication public bool IsShuttingDown { get; private set; } /// <summary> + /// Gets a value indicating whether the application is in technician mode. + /// </summary> + public bool IsInTechnicianMode { get; private set; } + + /// <summary> /// Gets the application version. /// </summary> public Version Version @@ -110,6 +119,16 @@ namespace Tango.PPC.UI.PPCApplication } } + private bool _isScreenLocked; + /// <summary> + /// Gets or sets a value indicating whether the screen is currently locked. + /// </summary> + public bool IsScreenLocked + { + get { return _isScreenLocked; } + set { _isScreenLocked = value; RaisePropertyChangedAuto(); } + } + /// <summary> /// Initializes a new instance of the <see cref="DefaultPPCApplicationManager"/> class. /// </summary> @@ -300,6 +319,8 @@ namespace Tango.PPC.UI.PPCApplication /// </summary> private void FinalizeModuleInitialization() { + var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); + LogManager.Log("Finalizing application initialization..."); LogManager.Log("Initializing Machine Provider..."); @@ -329,6 +350,31 @@ namespace Tango.PPC.UI.PPCApplication LogManager.Log($"Invoking {vm.GetType().Name}.OnApplicationReady..."); vm.OnApplicationReady(); } + + if (settings.EnableTechnicianModeByDefault) + { + EnterTechnicianMode(false); + } + + if (settings.EnableLockScreen) + { + _screenLockTimer = new ActionTimer(settings.LockScreenTimeout); + _screenLockTimer.ResetReplace(ScreenLockTimerAction); + } + + TangoMessenger.Default.Register<MachineSettingsSavedMessage>((msg) => + { + if (_screenLockTimer != null) + { + _screenLockTimer.Dispose(); + } + + if (settings.EnableLockScreen) + { + _screenLockTimer = new ActionTimer(settings.LockScreenTimeout); + _screenLockTimer.ResetReplace(ScreenLockTimerAction); + } + }); }); } @@ -412,10 +458,32 @@ namespace Tango.PPC.UI.PPCApplication /// <summary> /// Enteres the application technician mode. /// </summary> - public void EnterTechnicianMode() + public async void EnterTechnicianMode(bool displayNotification = true) { - _moduleLoader.AllModules.ToList().ForEach(x => x.OnTechnicianEntered()); - _notificationProvider.ShowInfo("Technician mode is now enabled."); + if (displayNotification) + { + var vm = await _notificationProvider.ShowDialog<TechnicianModeLoginViewVM>(); + + if (vm.DialogResult) + { + if (vm.Password == "Aa123456") + { + IsInTechnicianMode = true; + _moduleLoader.AllModules.ToList().ForEach(x => x.OnTechnicianEntered()); + await _notificationProvider.ShowInfo("Technician mode is now enabled."); + } + else + { + await _notificationProvider.ShowError("Invalid technician mode password."); + EnterTechnicianMode(); + } + } + } + else + { + IsInTechnicianMode = true; + _moduleLoader.AllModules.ToList().ForEach(x => x.OnTechnicianEntered()); + } } /// <summary> @@ -423,8 +491,42 @@ namespace Tango.PPC.UI.PPCApplication /// </summary> public void ExitTechnicianMode() { + IsInTechnicianMode = false; _moduleLoader.AllModules.ToList().ForEach(x => x.OnTechnicianExited()); _notificationProvider.ShowInfo("Technician mode is now disabled."); } + + /// <summary> + /// Invokes a dialog for entering a password and releasing the screen lock. + /// </summary> + public async void ReleaseScreenLock() + { + if (IsScreenLocked) + { + var vm = await _notificationProvider.ShowDialog<ScreenLockViewVM>(); + + if (vm.DialogResult) + { + if (vm.Password == SettingsManager.Default.GetOrCreate<PPCSettings>().LockScreenPassword) + { + IsScreenLocked = false; + ResetScreenLockTimer(); + } + } + } + } + + public void ResetScreenLockTimer() + { + if (_screenLockTimer != null) + { + _screenLockTimer.ResetReplace(ScreenLockTimerAction); + } + } + + private void ScreenLockTimerAction() + { + IsScreenLocked = true; + } } } |
