From d6f46df0e9ccd08276912bcdcded246de0bc4447 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 15 Mar 2018 12:29:05 +0200 Subject: Implemented virtual machine selection when connecting via USB. --- .../ViewModels/MainViewVM.cs | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 57f1d704c..84c4e2dd3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -26,6 +26,7 @@ using Tango.MachineStudio.UI.SupervisingController; using Tango.MachineStudio.UI.Views; using Tango.MachineStudio.UI.Windows; using Tango.PMR.Stubs; +using Tango.Settings; using Tango.SharedUI; using Tango.SharedUI.Helpers; using Tango.Transport.Adapters; @@ -333,21 +334,31 @@ namespace Tango.MachineStudio.UI.ViewModels } else { - using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) + _notificationProvider.ShowModalDialog(async (vm) => { - try + if (vm.SelectedMachine != null) { - await x.SelectedMachine.Connect(); - ApplicationManager.ConnectedMachine = x.SelectedMachine; - } - catch (Exception ex) - { - logManager.Log(ex); - _notificationProvider.ShowError(ex.Message); - } + using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) + { + try + { + await x.SelectedMachine.Connect(); + x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; + ApplicationManager.ConnectedMachine = x.SelectedMachine; - InvalidateRelayCommands(); - } + SettingsManager.Default.MachineStudio.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; + SettingsManager.SaveDefaultSettings(); + } + catch (Exception ex) + { + logManager.Log(ex); + _notificationProvider.ShowError(ex.Message); + } + + InvalidateRelayCommands(); + } + } + }); } InvalidateRelayCommands(); -- cgit v1.3.1 From ffe61a7cf745230b1436dbedf1610af72a618a0c Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 15 Mar 2018 16:12:43 +0200 Subject: Working on machine events. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1048576 -> 1048576 bytes .../ViewModels/MainViewVM.cs | 1 - .../ViewModels/LocalSynchronizationViewVM.cs | 1 - .../ViewModels/RemoteSynchronizationViewVM.cs | 1 - .../EventLogging/DefaultEventLogger.cs | 153 ++++++++++++++---- .../EventLogging/IEventLogger.cs | 3 + .../Tango.MachineStudio.Common.csproj | 3 + .../Tango.MachineStudio.Common/packages.config | 1 + .../Tango.MachineStudio.UI/App.xaml.cs | 12 ++ .../Modules/DefaultStudioModuleLoader.cs | 1 - .../DefaultStudioApplicationManager.cs | 1 - .../Tango.MachineStudio.UI/ViewModelLocator.cs | 3 + .../ViewModels/LoadingViewVM.cs | 6 +- .../ViewModels/LoginViewVM.cs | 7 +- .../ViewModels/MainViewVM.cs | 18 ++- .../Windows/ExceptionWindow.xaml | 2 +- .../Visual_Studio/Tango.BL/Entities/Machine.cs | 40 +++++ .../Tango.BL/Entities/MachinesEvent.cs | 20 +++ .../Tango.BL/Enumerations/ActionTypes.cs | 6 + .../Tango.BL/Enumerations/EventTypes.cs | 12 +- .../Visual_Studio/Tango.Core/ExtendedObject.cs | 9 ++ .../Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs | 2 + .../Tango.DAL.Remote/DB/MACHINES_EVENTS.cs | 1 + .../Tango.DAL.Remote/DB/RemoteADO.edmx | 25 ++- .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 136 ++++++++-------- .../Visual_Studio/Tango.Emulations/EmulatorBase.cs | 2 - .../Tango.Emulations/Emulators/MachineEmulator.cs | 13 +- .../Emulators/MachineEventState.cs | 46 ++++++ .../Tango.Emulations/Tango.Emulations.csproj | 1 + .../Diagnostics/DiagnosticsFilePlayer.cs | 1 - .../Diagnostics/DiagnosticsFileRecorder.cs | 1 - .../Operation/IMachineOperator.cs | 21 +++ .../Tango.Integration/Operation/MachineOperator.cs | 173 ++++++++++++++++++--- .../Operation/RequestFailedEventArgs.cs | 22 +++ .../Services/ExternalBridgeScanner.cs | 1 - .../Tango.Integration/Tango.Integration.csproj | 1 + Software/Visual_Studio/Tango.Stubs/StubBase.cs | 2 - .../Tango.Transport/TransporterBase.cs | 1 - .../Tango.MachineEM.UI/Views/MainView.xaml | 25 ++- 40 files changed, 614 insertions(+), 160 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Emulations/Emulators/MachineEventState.cs create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/RequestFailedEventArgs.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 07c583c5e..f46432121 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 15dbbbd39..3e11070a5 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index b2dded955..4a16be957 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -54,7 +54,6 @@ namespace Tango.MachineStudio.Developer.ViewModels private IAuthenticationProvider _authentication; private ObservablesContext _machineDbContext; private ObservablesContext _activeJobDbContext; - private LogManager LogManager = LogManager.Default; private SpeechSynthesizer _speech; private SoundPlayer _soundPlayer; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs index fbc2e2d49..2621f622a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/LocalSynchronizationViewVM.cs @@ -33,7 +33,6 @@ namespace Tango.MachineStudio.Synchronization.ViewModels private INotificationProvider _notification; private bool _isWorking; private MainViewVM _mainView; - private LogManager LogManager = LogManager.Default; #region Constructors diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs index 0fa1ce149..57b3af1a8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Synchronization/ViewModels/RemoteSynchronizationViewVM.cs @@ -40,7 +40,6 @@ namespace Tango.MachineStudio.Synchronization.ViewModels private RemoteDB _remoteDB; private LocalDB _localDB; private MainViewVM _mainView; - private LogManager LogManager = LogManager.Default; #region Constructors diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index c22ce335c..ff4badffe 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -1,4 +1,5 @@ -using System; +using Google.Protobuf; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -8,21 +9,32 @@ using System.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; using Tango.BL.Enumerations; +using Tango.Core; +using Tango.Integration.Services; using Tango.Logging; using Tango.MachineStudio.Common.Authentication; +using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.StudioApplication; using Tango.PMR.Diagnostics; +using Tango.Integration.Operation; namespace Tango.MachineStudio.Common.EventLogging { - public class DefaultEventLogger : IEventLogger + /// + /// Represents the default database events logger. + /// + /// + public class DefaultEventLogger : ExtendedObject, IEventLogger { private ObservablesContext _db; private Thread _logThread; private ConcurrentQueue _events; private IStudioApplicationManager _application; private IAuthenticationProvider _authentication; - private Dictionary _eventTypesGuids; + private Dictionary _eventTypesGuids; + private String _hostName; + + #region Constructors /// /// Initializes a new instance of the class. @@ -31,12 +43,14 @@ namespace Tango.MachineStudio.Common.EventLogging /// The authentication provider. public DefaultEventLogger(IStudioApplicationManager applicationManager, IAuthenticationProvider authenticationProvider) { + _hostName = Environment.MachineName; + _events = new ConcurrentQueue(); _db = ObservablesContext.CreateDefault(); _db.Configuration.LazyLoadingEnabled = false; - _eventTypesGuids = new Dictionary(); + _eventTypesGuids = new Dictionary(); _db.ActionTypes.ToList(); _db.EventTypesCategories.ToList(); @@ -45,7 +59,7 @@ namespace Tango.MachineStudio.Common.EventLogging foreach (var type in _db.EventTypes) { - _eventTypesGuids.Add((EventTypes)type.Code, type.Guid); + _eventTypesGuids.Add((EventTypes)type.Code, type); } _application = applicationManager; @@ -53,14 +67,93 @@ namespace Tango.MachineStudio.Common.EventLogging _logThread = new Thread(LogThreadMethod); _logThread.IsBackground = true; _logThread.Start(); + + _application.ConnectedMachineChanged += _application_ConnectedMachineChanged; + } + + #endregion + + #region Event Handlers + + /// + /// Handle the application manager connected machine changed event. + /// + /// The sender. + /// The machine. + private void _application_ConnectedMachineChanged(object sender, IExternalBridgeClient machine) + { + if (machine != null) + { + if (machine.MachineEventsStateProvider != null) + { + machine.MachineEventsStateProvider.NewEvents -= MachineEventsStateProvider_NewEvents; + machine.MachineEventsStateProvider.NewEvents += MachineEventsStateProvider_NewEvents; + } + + machine.RequestSent -= Machine_RequestSent; + machine.RequestFailed -= Machine_RequestFailed; + machine.ResponseReceived -= Machine_ResponseReceived; + + machine.RequestSent += Machine_RequestSent; + machine.RequestFailed += Machine_RequestFailed; + machine.ResponseReceived += Machine_ResponseReceived; + } + } + + /// + /// Handles the RequestSent event of the connected machine. + /// + /// The sender. + /// The message. + private void Machine_RequestSent(object sender, IMessage message) + { + Log(EventTypes.RequestSent, String.Format("Sending request '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); } + /// + /// Handles the RequestFailed event of the connected machine. + /// + /// The source of the event. + /// The instance containing the event data. + private void Machine_RequestFailed(object sender, RequestFailedEventArgs e) + { + Log(EventTypes.RequestFailed, String.Format("Request failed '{0}'...{1}{2}{1}{3}", e.Message.GetType().Name, Environment.NewLine, e.Message.ToJsonString(), e.Exception.ToString())); + } + + /// + /// Handles the ResponseReceived event of the connected machine. + /// + /// The sender. + /// The message. + private void Machine_ResponseReceived(object sender, IMessage message) + { + Log(EventTypes.ResponseReceived, String.Format("Response received '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); + } + + /// + /// Handles the connected machine events state provider NewEvents event. + /// + /// The sender. + /// The events. + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable events) + { + foreach (var ev in events) + { + Log(ev); + } + } + + #endregion + + #region Logging + /// /// Logs the specified machine event. /// /// The machine event. public void Log(MachinesEvent machineEvent) { + LogManager.Log("Logging event " + machineEvent.EventType.Name + " - " + machineEvent.Description); _events.Enqueue(machineEvent); } @@ -72,11 +165,12 @@ namespace Tango.MachineStudio.Common.EventLogging public void Log(EventTypes eventType, string message) { MachinesEvent machineEvent = new MachinesEvent(); - machineEvent.MachineGuid = _application.ConnectedMachine.Guid; + machineEvent.MachineGuid = _application.ConnectedMachine != null ? _application.ConnectedMachine.Guid : null; machineEvent.DateTime = DateTime.UtcNow; machineEvent.Description = message; - machineEvent.EventTypeGuid = _eventTypesGuids[eventType]; - machineEvent.UserGuid = _authentication.CurrentUser.Guid; + machineEvent.EventType = _eventTypesGuids[eventType]; + machineEvent.UserGuid = _authentication.CurrentUser != null ? _authentication.CurrentUser.Guid : null; + machineEvent.HostName = _hostName; Log(machineEvent); } @@ -96,7 +190,7 @@ namespace Tango.MachineStudio.Common.EventLogging /// The exception. public void Log(Exception exception) { - Log(EventTypes.ApplicationException, exception.Message); + Log(EventTypes.ApplicationException, exception.ToString()); } /// @@ -108,37 +202,42 @@ namespace Tango.MachineStudio.Common.EventLogging Log(EventTypes.ApplicationInformation, message); } + /// + /// Logging thread loop. + /// private void LogThreadMethod() { - try + while (true) { - while (true) + bool _saveChanges = false; + + while (_events.Count > 0) { - bool _saveChanges = false; + MachinesEvent ev = null; - while (_events.Count > 0) + if (_events.TryDequeue(out ev)) { - MachinesEvent ev = null; - - if (_events.TryDequeue(out ev)) - { - _db.MachinesEvents.Add(ev); - _saveChanges = true; - } + _db.MachinesEvents.Add(ev); + _saveChanges = true; } + } - if (_saveChanges) + if (_saveChanges) + { + try { _db.SaveChanges(); } - - Thread.Sleep(5000); + catch (Exception ex) + { + LogManager.Log(ex, "Error saving machine event to database."); + } } - } - catch (Exception ex) - { - LogManager.Default.Log(ex, "Error saving machine event to database."); + + Thread.Sleep(5000); } } + + #endregion } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs index 645bd4a95..bafdca914 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs @@ -9,6 +9,9 @@ using Tango.PMR.Diagnostics; namespace Tango.MachineStudio.Common.EventLogging { + /// + /// Represents a database events logger. + /// public interface IEventLogger { /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 7c28cb4c8..15ab97a27 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -46,6 +46,9 @@ ..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll + + ..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + ..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config index cf0df03c8..8cd12859b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/packages.config @@ -2,6 +2,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs index a7596e16c..f94a6c9d9 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs @@ -12,6 +12,8 @@ using Tango.BL.Entities; using Tango.Logging; using Tango.MachineStudio.UI.Windows; using Tango.Settings; +using Microsoft.Practices.ServiceLocation; +using Tango.MachineStudio.Common.EventLogging; namespace Tango.MachineStudio.UI { @@ -67,6 +69,16 @@ namespace Tango.MachineStudio.UI } catch { } + try + { + var eventLogger = ServiceLocator.Current.GetInstance(); + if (eventLogger != null) + { + eventLogger.Log(e.Exception); + } + } + catch { } + Application.Current.Dispatcher.Invoke(() => { ExceptionWindow exWin = new ExceptionWindow(e.Exception); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs index 16526cee6..121d429ec 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs @@ -29,7 +29,6 @@ namespace Tango.MachineStudio.UI.Modules private IAuthenticationProvider _authenticationProvider; private bool _loaded; public event EventHandler ModulesLoaded; - private LogManager LogManager = LogManager.Default; /// /// Initializes a new instance of the class. diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index f48ddb0e2..b4b1c5153 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -31,7 +31,6 @@ namespace Tango.MachineStudio.UI.StudioApplication private INavigationManager _navigationManager; private IStudioModuleLoader _moduleLoader; private List _openedWindows; - private LogManager LogManager = LogManager.Default; /// /// Initializes a new instance of the class. diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index 675022276..571122eb5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -6,6 +6,7 @@ using Tango.Integration.Services; using Tango.Logging; using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Diagnostics; +using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; @@ -57,6 +58,7 @@ namespace Tango.MachineStudio.UI SimpleIoc.Default.Unregister(); SimpleIoc.Default.Unregister(); SimpleIoc.Default.Unregister(); + SimpleIoc.Default.Unregister(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); @@ -66,6 +68,7 @@ namespace Tango.MachineStudio.UI SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 9ee8471ec..54b83a5cc 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -13,6 +13,7 @@ using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; using Tango.BL; +using Tango.MachineStudio.Common.EventLogging; namespace Tango.MachineStudio.UI.ViewModels { @@ -25,6 +26,7 @@ namespace Tango.MachineStudio.UI.ViewModels private INotificationProvider _notificationProvider; private INavigationManager _navigationManager; private IStudioModuleLoader _studioModuleLoader; + private IEventLogger _eventLogger; private LogManager logManager = LogManager.Default; public IStudioApplicationManager ApplicationManager { get; set; } @@ -42,8 +44,9 @@ namespace Tango.MachineStudio.UI.ViewModels /// The navigation manager. /// The studio module loader. /// The notification provider. - public LoadingViewVM(IStudioApplicationManager applicationManager, INavigationManager navigationManager, IStudioModuleLoader studioModuleLoader, INotificationProvider notificationProvider) + public LoadingViewVM(IStudioApplicationManager applicationManager, INavigationManager navigationManager, IStudioModuleLoader studioModuleLoader, INotificationProvider notificationProvider, IEventLogger eventLogger) { + _eventLogger = eventLogger; ApplicationManager = applicationManager; _navigationManager = navigationManager; _studioModuleLoader = studioModuleLoader; @@ -67,6 +70,7 @@ namespace Tango.MachineStudio.UI.ViewModels { _studioModuleLoader.LoadModules(); _navigationManager.NavigateTo(NavigationView.LoginView); + _eventLogger.Log("Application started successfully"); IsLoading = false; }); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index c5936eea8..7fefe4a41 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Tango.Core.Commands; using Tango.Core.Cryptography; using Tango.MachineStudio.Common.Authentication; +using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; using Tango.Settings; @@ -25,6 +26,7 @@ namespace Tango.MachineStudio.UI.ViewModels private IAuthenticationProvider _authenticationProvider; private INavigationManager _navigationManager; private INotificationProvider _notificationProvider; + private IEventLogger _eventLogger; private Rfc2898Cryptographer cryptographer; private String _email; @@ -60,11 +62,12 @@ namespace Tango.MachineStudio.UI.ViewModels /// The authentication provider. /// The navigation manager. /// The notification provider. - public LoginViewVM(IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider) + public LoginViewVM(IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger) { _notificationProvider = notificationProvider; _navigationManager = navigationManager; _authenticationProvider = authenticationProvider; + _eventLogger = eventLogger; LoginCommand = new RelayCommand(Login); cryptographer = new Rfc2898Cryptographer(); @@ -89,6 +92,8 @@ namespace Tango.MachineStudio.UI.ViewModels SettingsManager.Default.MachineStudio.LastLoginPassword = RememberMe ? cryptographer.Encrypt(password) : null; SettingsManager.SaveDefaultSettings(); + + _eventLogger.Log("User logged in"); } catch { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 84c4e2dd3..ba94cd860 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -16,6 +16,7 @@ using Tango.Integration.Services; using Tango.Logging; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Authentication; +using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; @@ -43,7 +44,7 @@ namespace Tango.MachineStudio.UI.ViewModels private INavigationManager _navigation; private bool _isDisconnecting; private Thread _updateCheckThread; - private LogManager logManager = LogManager.Default; + private IEventLogger _eventLogger; /// /// Gets or sets the current loaded module. @@ -201,8 +202,10 @@ namespace Tango.MachineStudio.UI.ViewModels IStudioModuleLoader studioModuleLoader, INotificationProvider notificationProvider, IStudioApplicationManager applicationManager, - INavigationManager navigationManager) : base(view) + INavigationManager navigationManager, + IEventLogger eventLogger) : base(view) { + _eventLogger = eventLogger; _navigation = navigationManager; AuthenticationProvider = authenticationProvider; StudioModuleLoader = studioModuleLoader; @@ -250,7 +253,7 @@ namespace Tango.MachineStudio.UI.ViewModels } catch (Exception ex) { - logManager.Log(ex, "Error in version update periodic check..."); + LogManager.Log(ex, "Error in version update periodic check..."); } Thread.Sleep(TimeSpan.FromMinutes(4)); @@ -320,11 +323,12 @@ namespace Tango.MachineStudio.UI.ViewModels else { ApplicationManager.ConnectedMachine = x.SelectedMachine; + _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP",x.SelectedMachine.SerialNumber)); } } catch (Exception ex) { - logManager.Log(ex); + LogManager.Log(ex); _notificationProvider.ShowError(ex.Message); } @@ -345,13 +349,13 @@ namespace Tango.MachineStudio.UI.ViewModels await x.SelectedMachine.Connect(); x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; ApplicationManager.ConnectedMachine = x.SelectedMachine; - + _eventLogger.Log(String.Format("Successfully connected to machine {0} via USB", x.SelectedMachine.SerialNumber)); SettingsManager.Default.MachineStudio.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; SettingsManager.SaveDefaultSettings(); } catch (Exception ex) { - logManager.Log(ex); + LogManager.Log(ex); _notificationProvider.ShowError(ex.Message); } @@ -447,7 +451,7 @@ namespace Tango.MachineStudio.UI.ViewModels } catch (Exception ex) { - logManager.Log(ex, "Error popping out module " + module.Name); + LogManager.Log(ex, "Error popping out module " + module.Name); _notificationProvider.ShowError("Error popping out module " + module.Name); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Windows/ExceptionWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Windows/ExceptionWindow.xaml index c08a08842..892e4944f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Windows/ExceptionWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Windows/ExceptionWindow.xaml @@ -43,7 +43,7 @@ - + diff --git a/Software/Visual_Studio/Tango.BL/Entities/Machine.cs b/Software/Visual_Studio/Tango.BL/Entities/Machine.cs index f92d7bcdd..361605796 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Machine.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Machine.cs @@ -137,6 +137,46 @@ namespace Tango.BL.Entities } + protected String _externalbridgepassword; + /// + /// Gets or sets the machine external bridge password. + /// + [Column("EXTERNAL_BRIDGE_PASSWORD")] + + public String ExternalBridgePassword + { + get + { + return _externalbridgepassword; + } + + set + { + _externalbridgepassword = value; RaisePropertyChanged(nameof(ExternalBridgePassword)); + } + + } + + protected Boolean _synchronized; + /// + /// Gets or sets the machine synchronized. + /// + [Column("SYNCHRONIZED")] + + public Boolean Synchronized + { + get + { + return _synchronized; + } + + set + { + _synchronized = value; RaisePropertyChanged(nameof(Synchronized)); + } + + } + protected ObservableCollection _cats; /// /// Gets or sets the machine cats. diff --git a/Software/Visual_Studio/Tango.BL/Entities/MachinesEvent.cs b/Software/Visual_Studio/Tango.BL/Entities/MachinesEvent.cs index 3e2a38b37..717faacb6 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/MachinesEvent.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/MachinesEvent.cs @@ -14,6 +14,26 @@ namespace Tango.BL.Entities public partial class MachinesEvent : ObservableEntity { + protected String _hostname; + /// + /// Gets or sets the machinesevent host name. + /// + [Column("HOST_NAME")] + + public String HostName + { + get + { + return _hostname; + } + + set + { + _hostname = value; RaisePropertyChanged(nameof(HostName)); + } + + } + protected String _machineguid; /// /// Gets or sets the machinesevent machine guid. diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/ActionTypes.cs b/Software/Visual_Studio/Tango.BL/Enumerations/ActionTypes.cs index 500dcdd4d..e8a46921c 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/ActionTypes.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/ActionTypes.cs @@ -33,5 +33,11 @@ namespace Tango.BL.Enumerations [Description("System Shutdown")] OverallPowerDown = 3, + /// + /// (Displays a graceful notification to the user) + /// + [Description("Displays a graceful notification to the user")] + SoftVisualNotification = 4, + } } diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs b/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs index cfe00bc1e..8fabeb952 100644 --- a/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs +++ b/Software/Visual_Studio/Tango.BL/Enumerations/EventTypes.cs @@ -196,10 +196,10 @@ namespace Tango.BL.Enumerations ResponseReceived = 30, /// - /// (Occures when a request to the machine had timed out) + /// (Occures when a request to the machine has failed) /// - [Description("Occures when a request to the machine had timed out")] - RequestTimeout = 31, + [Description("Occures when a request to the machine has failed")] + RequestFailed = 31, /// /// (Occures when the application has encountered some error) @@ -207,12 +207,6 @@ namespace Tango.BL.Enumerations [Description("Occures when the application has encountered some error")] ApplicationException = 32, - /// - /// (Occures when a user has loged in to the system) - /// - [Description("Occures when a user has loged in to the system")] - UserLogin = 33, - /// /// (General application event logs) /// diff --git a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs index 6cccbe425..72120dc6b 100644 --- a/Software/Visual_Studio/Tango.Core/ExtendedObject.cs +++ b/Software/Visual_Studio/Tango.Core/ExtendedObject.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using Tango.Core.Commands; +using Tango.Logging; namespace Tango.Core { @@ -18,6 +19,14 @@ namespace Tango.Core [Serializable] public class ExtendedObject : INotifyPropertyChanged { + /// + /// Gets the default log manager. + /// + public LogManager LogManager + { + get { return LogManager.Default; } + } + /// /// Occurs when a property has changed. /// diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs index 0c2c0b37c..edee20789 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE.cs @@ -32,6 +32,8 @@ namespace Tango.DAL.Remote.DB public string ORGANIZATION_GUID { get; set; } public string MACHINE_VERSION_GUID { get; set; } public string CONFIGURATION_GUID { get; set; } + public string EXTERNAL_BRIDGE_PASSWORD { get; set; } + public bool SYNCHRONIZED { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection CATS { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINES_EVENTS.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINES_EVENTS.cs index 6dae4b687..d83f123a2 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINES_EVENTS.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINES_EVENTS.cs @@ -17,6 +17,7 @@ namespace Tango.DAL.Remote.DB public int ID { get; set; } public string GUID { get; set; } public System.DateTime LAST_UPDATED { get; set; } + public string HOST_NAME { get; set; } public string MACHINE_GUID { get; set; } public string EVENT_TYPE_GUID { get; set; } public string USER_GUID { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx index 26a4a023e..e6a140558 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -586,6 +586,8 @@ + + @@ -604,9 +606,10 @@ - + + - + @@ -1532,7 +1535,7 @@ - + @@ -1544,7 +1547,7 @@ - + @@ -3200,6 +3203,8 @@ + + @@ -3227,9 +3232,10 @@ - + + - + @@ -4318,7 +4324,7 @@ - + @@ -4344,7 +4350,7 @@ - + @@ -5115,6 +5121,8 @@ + + @@ -5146,6 +5154,7 @@ + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram index e99881cac..a44b04a03 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,74 +5,74 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.Emulations/EmulatorBase.cs b/Software/Visual_Studio/Tango.Emulations/EmulatorBase.cs index b195d5ccc..161277459 100644 --- a/Software/Visual_Studio/Tango.Emulations/EmulatorBase.cs +++ b/Software/Visual_Studio/Tango.Emulations/EmulatorBase.cs @@ -18,8 +18,6 @@ namespace Tango.Emulations /// public abstract class EmulatorBase : ExtendedObject, IEmulator { - private LogManager LogManager = LogManager.Default; - #region Properties private bool _isStarted; diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index d34292e15..3d24c357c 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -41,9 +41,10 @@ namespace Tango.Emulations.Emulators private double _graphFrequency; private List _digitalOutputPinsStates; private List _digitalInputPinsStates; - private LogManager LogManager = LogManager.Default; private List _componentsStates; + public List EventsStates { get; set; } + #region Constructors /// @@ -70,6 +71,8 @@ namespace Tango.Emulations.Emulators private void Init() { + EventsStates = MachineEventState.GetAllEventsStates(); + _motorJoggingRequestCodes = new List(); _motorHomingRequestCodes = new List(); _dispenserJoggingRequestCodes = new List(); @@ -270,6 +273,8 @@ namespace Tango.Emulations.Emulators res.DigitalPins.AddRange(_digitalOutputPinsStates.Concat(_digitalInputPinsStates)); res.ComponentsStates.AddRange(_componentsStates); + res.Events.AddRange(EventsStates.Where(x => x.IsActive).Select(x => new Event() { Type = x.EventType, Message = "Generated by Tango Embedded Emulator" })); + res.Version = "1.0.0.0"; res.VersionBuildDate = DateTime.Now.ToString(); res.VersionName = "Embedded Emulator"; @@ -583,6 +588,12 @@ namespace Tango.Emulations.Emulators }); } + #endregion + + #region Public Methods + + + #endregion } } diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEventState.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEventState.cs new file mode 100644 index 000000000..188747646 --- /dev/null +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEventState.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.PMR.Diagnostics; + +namespace Tango.Emulations.Emulators +{ + public class MachineEventState : ExtendedObject + { + private EventType _eventType; + + public EventType EventType + { + get { return _eventType; } + set { _eventType = value; RaisePropertyChangedAuto(); } + } + + public String Description + { + get { return _eventType.ToDescription(); } + } + + private bool _isActive; + + public bool IsActive + { + get { return _isActive; } + set { _isActive = value; RaisePropertyChangedAuto(); } + } + + public static List GetAllEventsStates() + { + List states = new List(); + + foreach (var value in Enum.GetValues(typeof(EventType)).OfType()) + { + states.Add(new MachineEventState() { EventType = value }); + } + + return states; + } + } +} diff --git a/Software/Visual_Studio/Tango.Emulations/Tango.Emulations.csproj b/Software/Visual_Studio/Tango.Emulations/Tango.Emulations.csproj index 7d6de2aa0..e369c8488 100644 --- a/Software/Visual_Studio/Tango.Emulations/Tango.Emulations.csproj +++ b/Software/Visual_Studio/Tango.Emulations/Tango.Emulations.csproj @@ -51,6 +51,7 @@ + diff --git a/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFilePlayer.cs b/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFilePlayer.cs index 7c70d53b7..1900e49e1 100644 --- a/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFilePlayer.cs +++ b/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFilePlayer.cs @@ -24,7 +24,6 @@ namespace Tango.Integration.Diagnostics private long _diagnosticsDataOffset; //Holds the actual starting position for the diagnostics packets. private Thread _playThread; //Holds the playing thread. private TaskCompletionSource _stopTaskSource; //Holds the "Stop" async method completion source. - private LogManager LogManager = LogManager.Default; #region Events diff --git a/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFileRecorder.cs b/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFileRecorder.cs index e0b772e5a..9f62ae355 100644 --- a/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFileRecorder.cs +++ b/Software/Visual_Studio/Tango.Integration/Diagnostics/DiagnosticsFileRecorder.cs @@ -30,7 +30,6 @@ namespace Tango.Integration.Diagnostics private TaskCompletionSource _stopCompletionSource; //Holds the "Stop" async method completion source. private DiagnosticsTimeCodeChannel _timeCodeChannel; //Holds the diagnostics time code channel. private Stopwatch _stopWatch; //Holds the stop watch for keeping tracks over frames time stamps. - private LogManager LogManager = LogManager.Default; #region Properties diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index b1e40284e..c1ef978a4 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -12,6 +12,7 @@ using System.Reactive.Linq; using Tango.PMR.Debugging; using Tango.PMR.Hardware; using Tango.BL.Entities; +using Google.Protobuf; namespace Tango.Integration.Operation { @@ -21,6 +22,26 @@ namespace Tango.Integration.Operation /// public interface IMachineOperator : ITransporter { + /// + /// Occurs when a request has been sent. + /// + event EventHandler RequestSent; + + /// + /// Occurs when a request response has been received. + /// + event EventHandler ResponseReceived; + + /// + /// Occurs when a response has been sent. + /// + event EventHandler ResponseSent; + + /// + /// Occurs when a request has failed. + /// + event EventHandler RequestFailed; + /// /// Occurs when there is new diagnostics data available. /// diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 7440f2ee4..19b416173 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -19,6 +19,7 @@ using Tango.Settings; using System.IO; using Tango.BL.Entities; using Tango.PMR.Hardware; +using Google.Protobuf; namespace Tango.Integration.Operation { @@ -48,8 +49,32 @@ namespace Tango.Integration.Operation /// Occurs when there is new diagnostics data available. /// public event EventHandler DiagnosticsDataAvailable; + + /// + /// Occurs when a new debug log is available. + /// public event EventHandler DebugLogAvailable; + /// + /// Occurs when a request has been sent. + /// + public event EventHandler RequestSent; + + /// + /// Occurs when a response has been sent. + /// + public event EventHandler ResponseSent; + + /// + /// Occurs when a request has timed out. + /// + public event EventHandler RequestFailed; + + /// + /// Occurs when a request response has been received. + /// + public event EventHandler ResponseReceived; + #endregion #region Properties @@ -137,22 +162,32 @@ namespace Tango.Integration.Operation { var request = new PushDiagnosticsRequest(); - LogRequest(request); + LogRequestSent(request); + + bool responseLogged = false; SendContinuousRequest(request).ObserveOn(new NewThreadScheduler()).Subscribe( (response) => { _diagnosticsSent = true; OnDiagnosticsDataAvailable(response); + + if (!responseLogged) + { + + responseLogged = true; + } }, (ex) => { _diagnosticsSent = false; + LogManager.Log(ex, "Diagnostics response has reached an exception."); //Do I need separate event for each one ?? }, () => { _diagnosticsSent = false; + LogManager.Log("Diagnostics response completed!?", LogCategory.Warning); //What to do now ?? }); } @@ -171,7 +206,7 @@ namespace Tango.Integration.Operation if (value && State == TransportComponentState.Connected && !_debugSent) { var request = new DebugLogRequest(); - LogRequest(request); + LogRequestSent(request); SendContinuousRequest(request).ObserveOn(new NewThreadScheduler()) .Subscribe @@ -226,6 +261,42 @@ namespace Tango.Integration.Operation DebugLogAvailable?.Invoke(this, data); } + /// + /// Called when the request has been sent + /// + /// The request. + protected virtual void OnRequestSent(IMessage request) + { + RequestSent?.Invoke(this, request); + } + + /// + /// Called when the response has been received + /// + /// The response. + protected virtual void OnResponseReceived(IMessage response) + { + ResponseReceived?.Invoke(this, response); + } + + /// + /// Called when the response has been sent + /// + /// The response. + protected virtual void OnResponseSent(IMessage response) + { + ResponseSent?.Invoke(this, response); + } + + /// + /// Called when the request has been failed + /// + /// The request. + protected virtual void OnRequestFailed(IMessage request, Exception exception) + { + RequestFailed?.Invoke(this, new RequestFailedEventArgs(request, exception)); + } + #endregion #region Protected Methods @@ -335,16 +406,24 @@ namespace Tango.Integration.Operation } }); - LogRequest(request); + LogRequestSent(request); + bool responseLogged = false; SendContinuousRequest(request).Subscribe((response) => { handler.RaiseStatusReceived(response.Message.Status); + + if (!responseLogged) + { + responseLogged = true; + LogResponseReceived(response.Message); + } }, (ex) => { if (!handler.IsCanceled) { handler.RaiseFailed(ex); + LogRequestFailed(request, ex); } }, () => { @@ -364,8 +443,22 @@ namespace Tango.Integration.Operation UploadProcessParametersRequest request = new UploadProcessParametersRequest(); request.ProcessParameters = new ProcessParameters(); processParameters.MapPrimitivesTo(request.ProcessParameters); - LogRequest(request); - return await SendRequest(request); + + UploadProcessParametersResponse response = null; + + try + { + LogRequestSent(request); + response = await SendRequest(request); + LogResponseReceived(response); + } + catch (Exception ex) + { + LogRequestFailed(request, ex); + throw ex; + } + + return response; } /// @@ -377,7 +470,7 @@ namespace Tango.Integration.Operation { UploadHardwareConfigurationRequest request = new UploadHardwareConfigurationRequest(); request.HardwareConfiguration = hardwareConfiguration; - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -388,8 +481,21 @@ namespace Tango.Integration.Operation /// public async Task StartMotorJogging(MotorJoggingRequest request) { - LogRequest(request); - return await SendRequest(request); + MotorJoggingResponse response = null; + + try + { + LogRequestSent(request); + response = await SendRequest(request); + LogResponseReceived(response); + } + catch (Exception ex) + { + LogRequestFailed(request, ex); + throw ex; + } + + return response; } /// @@ -399,7 +505,7 @@ namespace Tango.Integration.Operation /// public async Task StopMotorJogging(MotorAbortJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -410,7 +516,7 @@ namespace Tango.Integration.Operation /// public IObservable StartMotorHoming(MotorHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return SendContinuousRequest(request).Select(x => x.Message); } @@ -421,7 +527,7 @@ namespace Tango.Integration.Operation /// public async Task StopMotorHoming(MotorAbortHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -432,7 +538,7 @@ namespace Tango.Integration.Operation /// public async Task StartDispenserJogging(DispenserJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -443,7 +549,7 @@ namespace Tango.Integration.Operation /// public async Task StopDispenserJogging(DispenserAbortJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -454,7 +560,7 @@ namespace Tango.Integration.Operation /// public IObservable StartDispenserHoming(DispenserHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return SendContinuousRequest(request).Select(x => x.Message); } @@ -465,7 +571,7 @@ namespace Tango.Integration.Operation /// public async Task StopDispenserHoming(DispenserAbortHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -476,7 +582,7 @@ namespace Tango.Integration.Operation /// public async Task SetDigitalOut(SetDigitalOutRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -487,7 +593,7 @@ namespace Tango.Integration.Operation /// public async Task StartThreadJogging(ThreadJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -498,7 +604,7 @@ namespace Tango.Integration.Operation /// public async Task StopThreadJogging(ThreadAbortJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -509,7 +615,7 @@ namespace Tango.Integration.Operation /// public async Task SetComponentValue(SetComponentValueRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest(request); } @@ -518,12 +624,33 @@ namespace Tango.Integration.Operation #region Private Methods /// - /// Logs the request. + /// Logs the request sent. + /// + /// The message. + private void LogRequestSent(IMessage message) + { + _logManager.Log(String.Format("Sending request '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); + OnRequestSent(message); + } + + /// + /// Logs the request failed. + /// + /// The message. + private void LogRequestFailed(IMessage message, Exception ex) + { + _logManager.Log(String.Format("Request failed '{0}'...{1}{2}{1}{3}", message.GetType().Name, Environment.NewLine, message.ToJsonString(), ex.ToString()), LogCategory.Error); + OnRequestFailed(message, ex); + } + + /// + /// Logs the response received. /// - /// The object. - private void LogRequest(Object obj) + /// The message. + private void LogResponseReceived(IMessage message) { - _logManager.Log(String.Format("Sending message '{0}'...{1}{2}", obj.GetType().Name, Environment.NewLine, obj.ToJsonString())); + _logManager.Log(String.Format("Response received '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); + OnResponseReceived(message); } #endregion diff --git a/Software/Visual_Studio/Tango.Integration/Operation/RequestFailedEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/RequestFailedEventArgs.cs new file mode 100644 index 000000000..e946dd0c1 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/RequestFailedEventArgs.cs @@ -0,0 +1,22 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Integration.Operation +{ + public class RequestFailedEventArgs : EventArgs + { + public IMessage Message { get; set; } + + public Exception Exception { get; set; } + + public RequestFailedEventArgs(IMessage message, Exception exception) + { + Message = message; + Exception = exception; + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs index b8e9b2c6d..ee65c7227 100644 --- a/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs +++ b/Software/Visual_Studio/Tango.Integration/Services/ExternalBridgeScanner.cs @@ -30,7 +30,6 @@ namespace Tango.Integration.Services private Thread _tcpDiscoveryThread; private Thread _usbDiscoveryThread; private UdpClient _server; - private LogManager LogManager = LogManager.Default; private ObservableCollection _availableMachines; /// diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 6b14ec784..8f4b9fc8e 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -87,6 +87,7 @@ + diff --git a/Software/Visual_Studio/Tango.Stubs/StubBase.cs b/Software/Visual_Studio/Tango.Stubs/StubBase.cs index ffebcb628..2d591168a 100644 --- a/Software/Visual_Studio/Tango.Stubs/StubBase.cs +++ b/Software/Visual_Studio/Tango.Stubs/StubBase.cs @@ -14,8 +14,6 @@ namespace Tango.Stubs { public abstract class StubBase : ExtendedObject, IStub { - private LogManager LogManager = LogManager.Default; - [ParameterIgnore] public ITransporter Transporter { get; set; } diff --git a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs index 2ca9c51ba..fbaf9d9fb 100644 --- a/Software/Visual_Studio/Tango.Transport/TransporterBase.cs +++ b/Software/Visual_Studio/Tango.Transport/TransporterBase.cs @@ -32,7 +32,6 @@ namespace Tango.Transport private Thread _keepAliveThread; private ITransportAdapter _adapter; private Dictionary _pendingResponses; - private LogManager LogManager = LogManager.Default; #region Events diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml index 8779da1ff..8b19f5a17 100644 --- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml @@ -7,9 +7,10 @@ xmlns:editors="clr-namespace:Tango.SharedUI.Editors;assembly=Tango.SharedUI" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:fa="http://schemas.fontawesome.io/icons/" + xmlns:vm="clr-namespace:Tango.MachineEM.UI.ViewModels" xmlns:local="clr-namespace:Tango.MachineEM.UI.Views" mc:Ignorable="d" - d:DesignHeight="720" d:DesignWidth="1000" Foreground="Gainsboro"> + d:DesignHeight="720" d:DesignWidth="1000" Foreground="Gainsboro" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" > @@ -49,9 +50,31 @@ + + + + + + + + HARDWARE EVENTS + + + + + + + + + + + + -- cgit v1.3.1 From 2836f1031bf9c1414a80620e040c1414a45c1648 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 15 Mar 2018 20:04:52 +0200 Subject: Working on machine events ! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 1048576 -> 1048576 bytes Software/Graphics/error-message.png | Bin 0 -> 2141 bytes Software/Graphics/exception.png | Bin 1528 -> 6679 bytes .../EventLogging/DefaultEventLogger.cs | 51 ++++++++++----- .../Images/error-message.png | Bin 0 -> 2141 bytes .../Tango.MachineStudio.UI/Images/exception.png | Bin 1528 -> 6679 bytes .../Tango.MachineStudio.UI.csproj | 3 + .../ViewModels/MainViewVM.cs | 38 ++++++++++- .../Tango.MachineStudio.UI/Views/MainView.xaml | 61 +++++++++++++++++ .../Tango.BL/EntitiesExtensions/MachineEvent.cs | 59 +++++++++++++++++ Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 1 + .../Operation/DefaultMachineEventsStateProvider.cs | 72 +++++++++++++++++---- .../Operation/IMachineEventsStateProvider.cs | 17 ++++- 14 files changed, 268 insertions(+), 34 deletions(-) create mode 100644 Software/Graphics/error-message.png create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/error-message.png create mode 100644 Software/Visual_Studio/Tango.BL/EntitiesExtensions/MachineEvent.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 40dc38df3..f3bd407f1 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 98a0a5ed0..833108156 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Graphics/error-message.png b/Software/Graphics/error-message.png new file mode 100644 index 000000000..c7c719b8a Binary files /dev/null and b/Software/Graphics/error-message.png differ diff --git a/Software/Graphics/exception.png b/Software/Graphics/exception.png index 9a4abb703..7b941818c 100644 Binary files a/Software/Graphics/exception.png and b/Software/Graphics/exception.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index ff4badffe..3763a06b4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -33,6 +33,7 @@ namespace Tango.MachineStudio.Common.EventLogging private IAuthenticationProvider _authentication; private Dictionary _eventTypesGuids; private String _hostName; + private bool _isInitialized; #region Constructors @@ -47,21 +48,8 @@ namespace Tango.MachineStudio.Common.EventLogging _events = new ConcurrentQueue(); - _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; - _eventTypesGuids = new Dictionary(); - _db.ActionTypes.ToList(); - _db.EventTypesCategories.ToList(); - _db.EventTypesGroups.ToList(); - _db.EventTypes.ToList(); - - foreach (var type in _db.EventTypes) - { - _eventTypesGuids.Add((EventTypes)type.Code, type); - } - _application = applicationManager; _authentication = authenticationProvider; _logThread = new Thread(LogThreadMethod); @@ -73,6 +61,31 @@ namespace Tango.MachineStudio.Common.EventLogging #endregion + #region Private Methods + + private void Init() + { + if (!_isInitialized) + { + _db = ObservablesContext.CreateDefault(); + _db.Configuration.LazyLoadingEnabled = false; + + _db.ActionTypes.ToList(); + _db.EventTypesCategories.ToList(); + _db.EventTypesGroups.ToList(); + _db.EventTypes.ToList(); + + foreach (var type in _db.EventTypes) + { + _eventTypesGuids.Add((EventTypes)type.Code, type); + } + + _isInitialized = true; + } + } + + #endregion + #region Event Handlers /// @@ -135,7 +148,7 @@ namespace Tango.MachineStudio.Common.EventLogging /// /// The sender. /// The events. - private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable events) + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable events) { foreach (var ev in events) { @@ -153,6 +166,11 @@ namespace Tango.MachineStudio.Common.EventLogging /// The machine event. public void Log(MachinesEvent machineEvent) { + machineEvent.MachineGuid = _application.ConnectedMachine != null ? _application.ConnectedMachine.Guid : null; + machineEvent.UserGuid = _authentication.CurrentUser != null ? _authentication.CurrentUser.Guid : null; + machineEvent.HostName = _hostName; + machineEvent.EventType = _eventTypesGuids[machineEvent.Type]; + LogManager.Log("Logging event " + machineEvent.EventType.Name + " - " + machineEvent.Description); _events.Enqueue(machineEvent); } @@ -164,13 +182,12 @@ namespace Tango.MachineStudio.Common.EventLogging /// The message. public void Log(EventTypes eventType, string message) { + Init(); + MachinesEvent machineEvent = new MachinesEvent(); - machineEvent.MachineGuid = _application.ConnectedMachine != null ? _application.ConnectedMachine.Guid : null; machineEvent.DateTime = DateTime.UtcNow; machineEvent.Description = message; machineEvent.EventType = _eventTypesGuids[eventType]; - machineEvent.UserGuid = _authentication.CurrentUser != null ? _authentication.CurrentUser.Guid : null; - machineEvent.HostName = _hostName; Log(machineEvent); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/error-message.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/error-message.png new file mode 100644 index 000000000..c7c719b8a Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/error-message.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png index 9a4abb703..7b941818c 100644 Binary files a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png and b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/exception.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 6a879e965..95c2a9925 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -421,6 +421,9 @@ + + + if $(ConfigurationName) == Debug $(TargetDir)linkgen.exe -s "$(TargetPath)" -d "$(TargetDir)Utilities\Machine Studio.lnk" diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index ba94cd860..b3c6236f8 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Integration.Services; using Tango.Logging; @@ -75,6 +76,16 @@ namespace Tango.MachineStudio.UI.ViewModels set { _isMenuOpened = value; RaisePropertyChangedAuto(); } } + private bool _isMachineErrorsOpened; + /// + /// Gets or sets a value indicating whether to display the machine errors. + /// + public bool IsMachineErrorsOpened + { + get { return _isMachineErrorsOpened; } + set { _isMachineErrorsOpened = value; RaisePropertyChangedAuto(); } + } + /// /// Gets or sets the start module command. /// @@ -225,6 +236,31 @@ namespace Tango.MachineStudio.UI.ViewModels _updateCheckThread = new Thread(UpdateCheckThreadMethod); _updateCheckThread.IsBackground = true; _updateCheckThread.Start(); + + ApplicationManager.ConnectedMachineChanged += (sender, machine) => + { + if (machine != null) + { + machine.MachineEventsStateProvider.NewEvents -= MachineEventsStateProvider_NewEvents; + machine.MachineEventsStateProvider.NewEvents += MachineEventsStateProvider_NewEvents; + + machine.MachineEventsStateProvider.EventsResolved -= MachineEventsStateProvider_EventsResolved; + machine.MachineEventsStateProvider.EventsResolved += MachineEventsStateProvider_EventsResolved; + } + }; + } + + private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable e) + { + if (ApplicationManager.ConnectedMachine.MachineEventsStateProvider.Events.Count == 0) + { + IsMachineErrorsOpened = false; + } + } + + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable e) + { + IsMachineErrorsOpened = true; } private void UpdateCheckThreadMethod() @@ -323,7 +359,7 @@ namespace Tango.MachineStudio.UI.ViewModels else { ApplicationManager.ConnectedMachine = x.SelectedMachine; - _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP",x.SelectedMachine.SerialNumber)); + _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber)); } } catch (Exception ex) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index 8e6fa36f5..beade3d88 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -9,6 +9,7 @@ xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:db="clr-namespace:Tango.MachineStudio.DB.Views;assembly=Tango.MachineStudio.DB" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" @@ -225,6 +226,17 @@ + + + + Press to view + + hardware messages + + + + + /// - public class DefaultMachineEventsStateProvider : IMachineEventsStateProvider + public class DefaultMachineEventsStateProvider : ExtendedObject, IMachineEventsStateProvider { - private ReadOnlyCollection _events; + private ReadOnlyCollection _events; /// /// Gets the current machine events. /// - public ReadOnlyCollection Events + public ReadOnlyCollection Events { get { @@ -26,22 +28,38 @@ namespace Tango.Integration.Operation } } + /// + /// Gets or sets a value indicating whether this instance has events. + /// + public bool HasEvents + { + get + { + return Events.Count > 0; + } + } + /// /// Occurs when new events are available. /// - public event EventHandler> NewEvents; + public event EventHandler> NewEvents; /// /// Occurs when a new events states has been received. /// - public event EventHandler> EventsReceived; + public event EventHandler> EventsReceived; + + /// + /// Occurs when old events has been resolved. + /// + public event EventHandler> EventsResolved; /// /// Initializes a new instance of the class. /// public DefaultMachineEventsStateProvider() { - _events = new ReadOnlyCollection(new Collection()); + _events = new ReadOnlyCollection(new Collection()); } /// @@ -50,19 +68,38 @@ namespace Tango.Integration.Operation /// The events. public void ApplyEvents(IEnumerable events) { - List currentEvents = Events.ToList(); - List newEvents = events.Where(x => !currentEvents.Exists(y => y.Type == x.Type)).ToList(); - _events = new ReadOnlyCollection(new Collection(events.ToList())); - OnNewEvents(newEvents); - OnEventsReceived(events); + List receivedEvents = events.Select(x => new MachinesEvent(x)).ToList(); + + List newEvents = receivedEvents.Where(x => !_events.ToList().Exists(y => y.Type == x.Type)).ToList(); + List oldEvents = _events.Where(x => !receivedEvents.Exists(y => y.Type == x.Type)).ToList(); + + _events = new ReadOnlyCollection(receivedEvents); + + if (newEvents.Count > 0) + { + OnNewEvents(newEvents); + } + if (oldEvents.Count > 0) + { + OnEventsResolved(oldEvents); + } + + OnEventsReceived(_events); + + RaisePropertyChanged(nameof(HasEvents)); + + if (newEvents.Count > 0 || oldEvents.Count > 0) + { + RaisePropertyChanged(nameof(Events)); + } } /// /// Called when the new has been events /// /// The events. - protected virtual void OnNewEvents(IEnumerable events) + protected virtual void OnNewEvents(IEnumerable events) { NewEvents?.Invoke(this, events); } @@ -71,9 +108,18 @@ namespace Tango.Integration.Operation /// Called when the events has been received /// /// The events. - protected virtual void OnEventsReceived(IEnumerable events) + protected virtual void OnEventsReceived(IEnumerable events) { EventsReceived?.Invoke(this, events); } + + /// + /// Called when the events has been resolved + /// + /// The events. + protected virtual void OnEventsResolved(IEnumerable events) + { + EventsResolved?.Invoke(this, events); + } } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs index bb7215254..6b3fc2e2c 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineEventsStateProvider.cs @@ -4,6 +4,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL.Entities; using Tango.PMR.Diagnostics; namespace Tango.Integration.Operation @@ -16,17 +17,27 @@ namespace Tango.Integration.Operation /// /// Gets the current machine events. /// - ReadOnlyCollection Events { get; } + ReadOnlyCollection Events { get; } + + /// + /// Gets or sets a value indicating whether this instance has events. + /// + bool HasEvents { get; } /// /// Occurs when new events are available. /// - event EventHandler> NewEvents; + event EventHandler> NewEvents; + + /// + /// Occurs when old events has been resolved. + /// + event EventHandler> EventsResolved; /// /// Occurs when a new events states has been received. /// - event EventHandler> EventsReceived; + event EventHandler> EventsReceived; /// /// Applies the collection of events received from the machine operator. -- cgit v1.3.1