From 5571ab086f6288b27117e3eaae443415a162403c Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 5 May 2020 19:24:45 +0300 Subject: Require Safety Level Operations ! --- .../ViewModels/ExternalBridgeViewVM.cs | 48 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs index 4b7d8978e..538b1f272 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs @@ -12,6 +12,7 @@ using Tango.PMR.Integration; using Tango.PPC.Common; using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.Navigation; +using Tango.PPC.UI.Dialogs; namespace Tango.PPC.UI.ViewModels { @@ -24,6 +25,10 @@ namespace Tango.PPC.UI.ViewModels { private bool _disconnecting; + //Full Name, Authentication time + private Dictionary _authenticatedSafetyUsers; + private const int KEEP_SAFETY_AUTHENTICATION_MINUTES = 1; + #region Properties private ExternalBridgeClientConnectedEventArgs _connection; @@ -64,6 +69,7 @@ namespace Tango.PPC.UI.ViewModels /// public ExternalBridgeViewVM() { + _authenticatedSafetyUsers = new Dictionary(); CloseSessionCommand = new RelayCommand(CloseSession, () => !_disconnecting); } @@ -133,7 +139,7 @@ namespace Tango.PPC.UI.ViewModels /// /// The sender. /// The instance containing the event data. - private void ExternalBridgeService_ConnectionRequest(object sender, ExternalBridgeClientConnectedEventArgs e) + private async void ExternalBridgeService_ConnectionRequest(object sender, ExternalBridgeClientConnectedEventArgs e) { LogManager.Log($"External bridge connection request received.\n{e.ToJsonString()}"); @@ -142,8 +148,6 @@ namespace Tango.PPC.UI.ViewModels e.ApplicationInformation.Version = ApplicationManager.Version.ToString(); e.ApplicationInformation.StartupDate = ApplicationManager.StartUpDate.ToUniversalTime().ToString(); - e.Confirmed = true; - Connection = e; User = Adapter.Users.SingleOrDefault(x => x.Guid == e.Request.UserGuid); @@ -153,6 +157,43 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log($"External bridge connection user has been identified as {User.Contact.FullName}"); } + if (e.Request.RequireSafetyLevelOperations) + { + DateTime lastAuthenticationTime; + bool bypassSafetyConfirmation = false; + + if (_authenticatedSafetyUsers.TryGetValue(e.Request.UserName, out lastAuthenticationTime)) + { + if (DateTime.Now < lastAuthenticationTime.AddMinutes(KEEP_SAFETY_AUTHENTICATION_MINUTES)) + { + bypassSafetyConfirmation = true; + e.Confirm(); + _authenticatedSafetyUsers[e.Request.UserName] = DateTime.Now; + } + } + + if (!bypassSafetyConfirmation) + { + SafetyLevelOperationsConfirmationViewVM vm = new SafetyLevelOperationsConfirmationViewVM(e); + await NotificationProvider.ShowDialog(vm); + + if (vm.DialogResult) + { + e.Confirm(); + _authenticatedSafetyUsers[e.Request.UserName] = DateTime.Now; + } + else + { + e.Decline("Safety level connection refused by the remote user."); + return; + } + } + } + else + { + e.Confirm(); + } + if (e.Request.Intent == ExternalBridgeLoginIntent.FullControl) { LogManager.Log("Navigating to external bridge view..."); @@ -164,6 +205,7 @@ namespace Tango.PPC.UI.ViewModels } else { + e.Decline("Connection password did not match the machine external bridge password."); LogManager.Log("Connection password did not match the machine external bridge password."); } } -- cgit v1.3.1 From 822707058d3fe957e03887a3969d553a65537031 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 5 May 2020 20:38:47 +0300 Subject: Improved safety operations handling from ExternalBridgeReceiver. Suppress firmware upgrade on remote upgrade feature. --- .../ApplicationUpgradeGeneratedViewVM.cs | 10 ++++++- .../Views/ApplicationUpgradeGeneratedView.xaml | 2 ++ .../RemoteUpgrade/IRemoteUpgradeManager.cs | 3 +- .../RemoteUpgrade/DefaultRemoteUpgradeManager.cs | 7 +++-- .../ViewModels/ExternalBridgeViewVM.cs | 9 ++---- .../ExternalBridge/ExternalBridgeReceiver.cs | 33 ++++++++++++++++++++-- 6 files changed, 49 insertions(+), 15 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeGeneratedViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeGeneratedViewVM.cs index 7ea8d49d6..f1737463d 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeGeneratedViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/ViewModels/ApplicationUpgradeGeneratedViewVM.cs @@ -95,6 +95,14 @@ namespace Tango.FSE.Upgrade.ViewModels set { _isCompleted = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } + private bool _suppressFirmwareUpgrade; + public bool SuppressFirmwareUpgrade + { + get { return _suppressFirmwareUpgrade; } + set { _suppressFirmwareUpgrade = value; RaisePropertyChangedAuto(); } + } + + public RelayCommand StartUpgradeCommand { get; set; } public RelayCommand SaveTupFileCommand { get; set; } public RelayCommand SelectTupFileLocationCommand { get; set; } @@ -170,7 +178,7 @@ namespace Tango.FSE.Upgrade.ViewModels try { IsFree = false; - Handler = await RemoteUpgradeManager.PerformRemoteApplicationUpgrade(TemporaryTupFile); + Handler = await RemoteUpgradeManager.PerformRemoteApplicationUpgrade(TemporaryTupFile, !SuppressFirmwareUpgrade); await Handler.WaitForCompletion(); IsCompleted = true; await MachineProvider.DisconnectAndWaitForReconnection(TimeSpan.FromSeconds(20), TimeSpan.FromMinutes(1)); diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/ApplicationUpgradeGeneratedView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/ApplicationUpgradeGeneratedView.xaml index c65744fdc..19816ae0e 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/ApplicationUpgradeGeneratedView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Upgrade/Views/ApplicationUpgradeGeneratedView.xaml @@ -40,6 +40,8 @@ + Suppress firmware upgrade + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs index ec06b2e8f..5cb831f0e 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/RemoteUpgrade/IRemoteUpgradeManager.cs @@ -39,8 +39,9 @@ namespace Tango.FSE.Common.RemoteUpgrade /// Performs a remote application upgrade using the specified .tup file. /// /// The .tup file. + /// Specify whether to upgrade the firmware while doing the complete upgrade. (SetupFirmware/FPGA) /// - Task PerformRemoteApplicationUpgrade(String tupFile); + Task PerformRemoteApplicationUpgrade(String tupFile, bool upgradeFirmware = true); /// /// Performs a remote firmware upgrade using the specified .tfp file. diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs index 8acfb99c6..870f9ca12 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/RemoteUpgrade/DefaultRemoteUpgradeManager.cs @@ -503,8 +503,9 @@ namespace Tango.FSE.UI.RemoteUpgrade /// Performs a remote application upgrade using the specified .tup file. /// /// The .tup file. + /// Specify whether to upgrade the firmware while doing the complete upgrade. (SetupFirmware/FPGA) /// - public Task PerformRemoteApplicationUpgrade(string tupFile) + public Task PerformRemoteApplicationUpgrade(string tupFile, bool upgradeFirmware = true) { Thread thread = null; RemoteUpgradeHandler handler = null; @@ -569,8 +570,8 @@ namespace Tango.FSE.UI.RemoteUpgrade new StartRemoteApplicationUpgradeRequest() { RemoteTupFilePath = remoteTempFile, - SetupFirmware = true, - SetupFPGA = true + SetupFirmware = upgradeFirmware, + SetupFPGA = upgradeFirmware }, new TransportContinuousRequestConfig() { ShouldLog = true, diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs index 538b1f272..f10e84d05 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs @@ -25,9 +25,7 @@ namespace Tango.PPC.UI.ViewModels { private bool _disconnecting; - //Full Name, Authentication time - private Dictionary _authenticatedSafetyUsers; - private const int KEEP_SAFETY_AUTHENTICATION_MINUTES = 1; + private const int KEEP_SAFETY_AUTHENTICATION_MINUTES = 5; #region Properties @@ -69,7 +67,6 @@ namespace Tango.PPC.UI.ViewModels /// public ExternalBridgeViewVM() { - _authenticatedSafetyUsers = new Dictionary(); CloseSessionCommand = new RelayCommand(CloseSession, () => !_disconnecting); } @@ -162,13 +159,12 @@ namespace Tango.PPC.UI.ViewModels DateTime lastAuthenticationTime; bool bypassSafetyConfirmation = false; - if (_authenticatedSafetyUsers.TryGetValue(e.Request.UserName, out lastAuthenticationTime)) + if (ExternalBridgeReceiver.LastSafetyLevelContactsTimes.TryGetValue(e.Request.UserName, out lastAuthenticationTime)) { if (DateTime.Now < lastAuthenticationTime.AddMinutes(KEEP_SAFETY_AUTHENTICATION_MINUTES)) { bypassSafetyConfirmation = true; e.Confirm(); - _authenticatedSafetyUsers[e.Request.UserName] = DateTime.Now; } } @@ -180,7 +176,6 @@ namespace Tango.PPC.UI.ViewModels if (vm.DialogResult) { e.Confirm(); - _authenticatedSafetyUsers[e.Request.UserName] = DateTime.Now; } else { diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs index 9c61f9e8b..f3d8711f1 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeReceiver.cs @@ -23,6 +23,13 @@ namespace Tango.Integration.ExternalBridge { public class ExternalBridgeReceiver : BasicTransporter { + /// + /// A dictionary containing the last time a user name has made a request or response. + /// This is used to bypass the safety operations confirmation. + /// FullName, Contact Time + /// + public static Dictionary LastSafetyLevelContactsTimes { get; private set; } + #region Message Handler private class MessageHandler @@ -53,7 +60,7 @@ namespace Tango.Integration.ExternalBridge private IMachineOperator _machineOperator; private Dictionary _messageHandlers; - private HashSet _safetyOperations; + private static HashSet _safetyOperations; //Static list containing all safety operations. #region Events @@ -76,6 +83,7 @@ namespace Tango.Integration.ExternalBridge public bool IsLoggedIn { get; private set; } public ExternalBridgeLoginIntent LoginIntent { get; private set; } + public String UserName { get; set; } public bool IsLoggedInAndRequiresDiagnostics { @@ -87,6 +95,12 @@ namespace Tango.Integration.ExternalBridge #region Constructors + static ExternalBridgeReceiver() + { + LastSafetyLevelContactsTimes = new Dictionary(); + _safetyOperations = new HashSet(); //TODO: initialize this from some repository of messages.. + } + public ExternalBridgeReceiver(IMachineOperator machineOperator) { ComponentName = $"External Bridge Receiver {_component_counter++}"; @@ -123,8 +137,6 @@ namespace Tango.Integration.ExternalBridge _messageHandlers.Add(MessageType.JobRequest, new MessageHandler(OnJobRequest, ExternalBridgeLoginIntent.Diagnostics)); _messageHandlers.Add(MessageType.StartPowerDownRequest, new MessageHandler(OnStartPowerDownRequest, ExternalBridgeLoginIntent.Diagnostics)); - - _safetyOperations = new HashSet(); } public ExternalBridgeReceiver(TcpClient tcpClient, IMachineOperator machineOperator) : this(machineOperator) @@ -155,6 +167,13 @@ namespace Tango.Integration.ExternalBridge return; } } + else + { + if (UserName != null) + { + LastSafetyLevelContactsTimes[UserName] = DateTime.Now; + } + } if (_messageHandlers.ContainsKey(container.Type)) { @@ -275,6 +294,7 @@ namespace Tango.Integration.ExternalBridge IsLoggedIn = true; LoginIntent = request.Message.Intent; + UserName = request.Message.UserName; var response = new ExternalBridgeLoginResponse(); response.Authenticated = true; @@ -289,6 +309,8 @@ namespace Tango.Integration.ExternalBridge UpdateMachineOperatorStatus((UpdateStatus)_machineOperator.Status); UseKeepAlive = true; + + LastSafetyLevelContactsTimes[UserName] = DateTime.Now; }, (reason) => { @@ -511,6 +533,11 @@ namespace Tango.Integration.ExternalBridge { try { + if (AllowSafetyLevelOperations && UserName != null) //Usually all clients require diagnostics so we will update the last contact time here.. + { + LastSafetyLevelContactsTimes[UserName] = DateTime.Now; + } + if (_diagnosticsToken != null) { var cloned = container.Clone(); -- cgit v1.3.1