diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-15 16:12:43 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-15 16:12:43 +0200 |
| commit | ffe61a7cf745230b1436dbedf1610af72a618a0c (patch) | |
| tree | 6002737dd72c2e7237637aad3b3b23358ba8eb8e /Software/Visual_Studio | |
| parent | d6f46df0e9ccd08276912bcdcded246de0bc4447 (diff) | |
| download | Tango-ffe61a7cf745230b1436dbedf1610af72a618a0c.tar.gz Tango-ffe61a7cf745230b1436dbedf1610af72a618a0c.zip | |
Working on machine events.
Diffstat (limited to 'Software/Visual_Studio')
38 files changed, 614 insertions, 160 deletions
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 + /// <summary> + /// Represents the default database events logger. + /// </summary> + /// <seealso cref="IEventLogger" /> + public class DefaultEventLogger : ExtendedObject, IEventLogger { private ObservablesContext _db; private Thread _logThread; private ConcurrentQueue<MachinesEvent> _events; private IStudioApplicationManager _application; private IAuthenticationProvider _authentication; - private Dictionary<EventTypes, String> _eventTypesGuids; + private Dictionary<EventTypes, BL.Entities.EventType> _eventTypesGuids; + private String _hostName; + + #region Constructors /// <summary> /// Initializes a new instance of the <see cref="DefaultEventLogger"/> class. @@ -31,12 +43,14 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="authenticationProvider">The authentication provider.</param> public DefaultEventLogger(IStudioApplicationManager applicationManager, IAuthenticationProvider authenticationProvider) { + _hostName = Environment.MachineName; + _events = new ConcurrentQueue<MachinesEvent>(); _db = ObservablesContext.CreateDefault(); _db.Configuration.LazyLoadingEnabled = false; - _eventTypesGuids = new Dictionary<EventTypes, string>(); + _eventTypesGuids = new Dictionary<EventTypes, BL.Entities.EventType>(); _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 + + /// <summary> + /// Handle the application manager connected machine changed event. + /// </summary> + /// <param name="sender">The sender.</param> + /// <param name="machine">The machine.</param> + 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; + } + } + + /// <summary> + /// Handles the RequestSent event of the connected machine. + /// </summary> + /// <param name="sender">The sender.</param> + /// <param name="message">The message.</param> + 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())); } /// <summary> + /// Handles the RequestFailed event of the connected machine. + /// </summary> + /// <param name="sender">The source of the event.</param> + /// <param name="e">The <see cref="RequestFailedEventArgs"/> instance containing the event data.</param> + 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())); + } + + /// <summary> + /// Handles the ResponseReceived event of the connected machine. + /// </summary> + /// <param name="sender">The sender.</param> + /// <param name="message">The message.</param> + 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())); + } + + /// <summary> + /// Handles the connected machine events state provider NewEvents event. + /// </summary> + /// <param name="sender">The sender.</param> + /// <param name="events">The events.</param> + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable<Event> events) + { + foreach (var ev in events) + { + Log(ev); + } + } + + #endregion + + #region Logging + + /// <summary> /// Logs the specified machine event. /// </summary> /// <param name="machineEvent">The machine event.</param> 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 /// <param name="exception">The exception.</param> public void Log(Exception exception) { - Log(EventTypes.ApplicationException, exception.Message); + Log(EventTypes.ApplicationException, exception.ToString()); } /// <summary> @@ -108,37 +202,42 @@ namespace Tango.MachineStudio.Common.EventLogging Log(EventTypes.ApplicationInformation, message); } + /// <summary> + /// Logging thread loop. + /// </summary> 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 { + /// <summary> + /// Represents a database events logger. + /// </summary> public interface IEventLogger { /// <summary> 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 @@ <Reference Include="GalaSoft.MvvmLight.Platform, Version=5.3.0.19032, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL"> <HintPath>..\..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath> </Reference> + <Reference Include="Google.Protobuf, Version=3.4.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll</HintPath> + </Reference> <Reference Include="MahApps.Metro, Version=1.5.0.23, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL"> <HintPath>..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath> </Reference> 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 @@ <packages> <package id="CommonServiceLocator" version="1.3" targetFramework="net46" /> <package id="EntityFramework" version="6.0.0" targetFramework="net46" /> + <package id="Google.Protobuf" version="3.4.1" targetFramework="net46" /> <package id="MahApps.Metro" version="1.5.0" targetFramework="net46" /> <package id="MaterialDesignColors" version="1.1.2" targetFramework="net46" /> <package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net46" /> 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<IEventLogger>(); + 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; /// <summary> /// Initializes a new instance of the <see cref="DefaultStudioModuleLoader"/> 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<Window> _openedWindows; - private LogManager LogManager = LogManager.Default; /// <summary> /// Initializes a new instance of the <see cref="DefaultStudioApplicationManager" /> 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<ExternalBridgeScanner>(); SimpleIoc.Default.Unregister<IVideoCaptureProvider>(); SimpleIoc.Default.Unregister<IDiagnosticsFrameProvider>(); + SimpleIoc.Default.Unregister<IEventLogger>(); SimpleIoc.Default.Register<INotificationProvider, DefaultNotificationProvider>(); SimpleIoc.Default.Register<IAuthenticationProvider, DefaultAuthenticationProvider>(); @@ -66,6 +68,7 @@ namespace Tango.MachineStudio.UI SimpleIoc.Default.Register<ExternalBridgeScanner, ExternalBridgeScanner>(); SimpleIoc.Default.Register<IVideoCaptureProvider, DefaultVideoCaptureProvider>(); SimpleIoc.Default.Register<IDiagnosticsFrameProvider, DefaultDiagnosticsFrameProvider>(); + SimpleIoc.Default.Register<IEventLogger, DefaultEventLogger>(); SimpleIoc.Default.Register<MainViewVM>(); SimpleIoc.Default.Register<LoadingViewVM>(); 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 /// <param name="navigationManager">The navigation manager.</param> /// <param name="studioModuleLoader">The studio module loader.</param> /// <param name="notificationProvider">The notification provider.</param> - 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 /// <param name="authenticationProvider">The authentication provider.</param> /// <param name="navigationManager">The navigation manager.</param> /// <param name="notificationProvider">The notification provider.</param> - 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<String>(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; /// <summary> /// 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 @@ </Grid> <Grid Grid.Row="1" Margin="0 10 0 0"> - <TextBox Style="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="#515151" IsReadOnly="True" AcceptsReturn="True" Foreground="#FF5C5C" Padding="2" TextWrapping="Wrap" Text="{Binding Exception}"></TextBox> + <TextBox Style="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderBrush="#515151" IsReadOnly="True" AcceptsReturn="True" Foreground="#202020" Padding="2" TextWrapping="Wrap" Text="{Binding Exception}"></TextBox> </Grid> </Grid> 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; + /// <summary> + /// Gets or sets the machine external bridge password. + /// </summary> + [Column("EXTERNAL_BRIDGE_PASSWORD")] + + public String ExternalBridgePassword + { + get + { + return _externalbridgepassword; + } + + set + { + _externalbridgepassword = value; RaisePropertyChanged(nameof(ExternalBridgePassword)); + } + + } + + protected Boolean _synchronized; + /// <summary> + /// Gets or sets the machine synchronized. + /// </summary> + [Column("SYNCHRONIZED")] + + public Boolean Synchronized + { + get + { + return _synchronized; + } + + set + { + _synchronized = value; RaisePropertyChanged(nameof(Synchronized)); + } + + } + protected ObservableCollection<Cat> _cats; /// <summary> /// 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<MachinesEvent> { + protected String _hostname; + /// <summary> + /// Gets or sets the machinesevent host name. + /// </summary> + [Column("HOST_NAME")] + + public String HostName + { + get + { + return _hostname; + } + + set + { + _hostname = value; RaisePropertyChanged(nameof(HostName)); + } + + } + protected String _machineguid; /// <summary> /// 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, + /// <summary> + /// (Displays a graceful notification to the user) + /// </summary> + [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, /// <summary> - /// (Occures when a request to the machine had timed out) + /// (Occures when a request to the machine has failed) /// </summary> - [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, /// <summary> /// (Occures when the application has encountered some error) @@ -208,12 +208,6 @@ namespace Tango.BL.Enumerations ApplicationException = 32, /// <summary> - /// (Occures when a user has loged in to the system) - /// </summary> - [Description("Occures when a user has loged in to the system")] - UserLogin = 33, - - /// <summary> /// (General application event logs) /// </summary> [Description("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 { @@ -19,6 +20,14 @@ namespace Tango.Core public class ExtendedObject : INotifyPropertyChanged { /// <summary> + /// Gets the default log manager. + /// </summary> + public LogManager LogManager + { + get { return LogManager.Default; } + } + + /// <summary> /// Occurs when a property has changed. /// </summary> [field: NonSerialized] 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<CAT> 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 @@ <Property Name="ORGANIZATION_GUID" Type="varchar" MaxLength="36" Nullable="false" /> <Property Name="MACHINE_VERSION_GUID" Type="varchar" MaxLength="36" Nullable="false" /> <Property Name="CONFIGURATION_GUID" Type="varchar" MaxLength="36" Nullable="false" /> + <Property Name="EXTERNAL_BRIDGE_PASSWORD" Type="varchar" MaxLength="100" /> + <Property Name="SYNCHRONIZED" Type="bit" Nullable="false" /> </EntityType> <EntityType Name="MACHINES_CONFIGURATIONS"> <Key> @@ -604,9 +606,10 @@ <Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" /> <Property Name="GUID" Type="varchar" MaxLength="36" Nullable="false" /> <Property Name="LAST_UPDATED" Type="datetime2" Precision="3" Nullable="false" /> - <Property Name="MACHINE_GUID" Type="varchar" MaxLength="36" Nullable="false" /> + <Property Name="HOST_NAME" Type="varchar" MaxLength="100" Nullable="false" /> + <Property Name="MACHINE_GUID" Type="varchar" MaxLength="36" /> <Property Name="EVENT_TYPE_GUID" Type="varchar" MaxLength="36" Nullable="false" /> - <Property Name="USER_GUID" Type="varchar" MaxLength="36" Nullable="false" /> + <Property Name="USER_GUID" Type="varchar" MaxLength="36" /> <Property Name="DATE_TIME" Type="datetime2" Precision="3" Nullable="false" /> <Property Name="DESCRIPTION" Type="nvarchar" MaxLength="200" /> </EntityType> @@ -1532,7 +1535,7 @@ </ReferentialConstraint> </Association> <Association Name="FK_MACHINES_EVENTS_MACHINES"> - <End Role="MACHINES" Type="Self.MACHINES" Multiplicity="1" /> + <End Role="MACHINES" Type="Self.MACHINES" Multiplicity="0..1" /> <End Role="MACHINES_EVENTS" Type="Self.MACHINES_EVENTS" Multiplicity="*" /> <ReferentialConstraint> <Principal Role="MACHINES"> @@ -1544,7 +1547,7 @@ </ReferentialConstraint> </Association> <Association Name="FK_MACHINES_EVENTS_USERS"> - <End Role="USERS" Type="Self.USERS" Multiplicity="1" /> + <End Role="USERS" Type="Self.USERS" Multiplicity="0..1" /> <End Role="MACHINES_EVENTS" Type="Self.MACHINES_EVENTS" Multiplicity="*" /> <ReferentialConstraint> <Principal Role="USERS"> @@ -3200,6 +3203,8 @@ <Property Name="ORGANIZATION_GUID" Type="String" Nullable="false" MaxLength="36" FixedLength="false" Unicode="false" /> <Property Name="MACHINE_VERSION_GUID" Type="String" Nullable="false" MaxLength="36" FixedLength="false" Unicode="false" /> <Property Name="CONFIGURATION_GUID" Type="String" Nullable="false" MaxLength="36" FixedLength="false" Unicode="false" /> + <Property Name="EXTERNAL_BRIDGE_PASSWORD" Type="String" MaxLength="100" FixedLength="false" Unicode="false" /> + <Property Name="SYNCHRONIZED" Type="Boolean" Nullable="false" /> <NavigationProperty Name="CATS" Relationship="RemoteModel.FK_CATS_MACHINES" FromRole="MACHINE" ToRole="CAT" /> <NavigationProperty Name="CONFIGURATION" Relationship="RemoteModel.FK_MACHINES_CONFIGURATIONS" FromRole="MACHINE" ToRole="CONFIGURATION" /> <NavigationProperty Name="JOBS" Relationship="RemoteModel.FK_JOBS_MACHINES" FromRole="MACHINE" ToRole="JOB" /> @@ -3227,9 +3232,10 @@ <Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" /> <Property Name="GUID" Type="String" Nullable="false" MaxLength="36" FixedLength="false" Unicode="false" /> <Property Name="LAST_UPDATED" Type="DateTime" Nullable="false" Precision="3" /> - <Property Name="MACHINE_GUID" Type="String" Nullable="false" MaxLength="36" FixedLength="false" Unicode="false" /> + <Property Name="HOST_NAME" Type="String" Nullable="false" MaxLength="100" FixedLength="false" Unicode="false" /> + <Property Name="MACHINE_GUID" Type="String" MaxLength="36" FixedLength="false" Unicode="false" /> <Property Name="EVENT_TYPE_GUID" Type="String" Nullable="false" MaxLength="36" FixedLength="false" Unicode="false" /> - <Property Name="USER_GUID" Type="String" Nullable="false" MaxLength="36" FixedLength="false" Unicode="false" /> + <Property Name="USER_GUID" Type="String" MaxLength="36" FixedLength="false" Unicode="false" /> <Property Name="DATE_TIME" Type="DateTime" Nullable="false" Precision="3" /> <Property Name="DESCRIPTION" Type="String" MaxLength="200" FixedLength="false" Unicode="true" /> <NavigationProperty Name="EVENT_TYPES" Relationship="RemoteModel.FK_MACHINES_EVENTS_EVENTS" FromRole="MACHINES_EVENTS" ToRole="EVENT_TYPES" /> @@ -4318,7 +4324,7 @@ </ReferentialConstraint> </Association> <Association Name="FK_MACHINES_EVENTS_MACHINES"> - <End Type="RemoteModel.MACHINE" Role="MACHINE" Multiplicity="1" /> + <End Type="RemoteModel.MACHINE" Role="MACHINE" Multiplicity="0..1" /> <End Type="RemoteModel.MACHINES_EVENTS" Role="MACHINES_EVENTS" Multiplicity="*" /> <ReferentialConstraint> <Principal Role="MACHINE"> @@ -4344,7 +4350,7 @@ </ReferentialConstraint> </Association> <Association Name="FK_MACHINES_EVENTS_USERS"> - <End Type="RemoteModel.USER" Role="USER" Multiplicity="1" /> + <End Type="RemoteModel.USER" Role="USER" Multiplicity="0..1" /> <End Type="RemoteModel.MACHINES_EVENTS" Role="MACHINES_EVENTS" Multiplicity="*" /> <ReferentialConstraint> <Principal Role="USER"> @@ -5115,6 +5121,8 @@ <EntitySetMapping Name="MACHINES"> <EntityTypeMapping TypeName="RemoteModel.MACHINE"> <MappingFragment StoreEntitySet="MACHINES"> + <ScalarProperty Name="SYNCHRONIZED" ColumnName="SYNCHRONIZED" /> + <ScalarProperty Name="EXTERNAL_BRIDGE_PASSWORD" ColumnName="EXTERNAL_BRIDGE_PASSWORD" /> <ScalarProperty Name="CONFIGURATION_GUID" ColumnName="CONFIGURATION_GUID" /> <ScalarProperty Name="MACHINE_VERSION_GUID" ColumnName="MACHINE_VERSION_GUID" /> <ScalarProperty Name="ORGANIZATION_GUID" ColumnName="ORGANIZATION_GUID" /> @@ -5146,6 +5154,7 @@ <ScalarProperty Name="USER_GUID" ColumnName="USER_GUID" /> <ScalarProperty Name="EVENT_TYPE_GUID" ColumnName="EVENT_TYPE_GUID" /> <ScalarProperty Name="MACHINE_GUID" ColumnName="MACHINE_GUID" /> + <ScalarProperty Name="HOST_NAME" ColumnName="HOST_NAME" /> <ScalarProperty Name="LAST_UPDATED" ColumnName="LAST_UPDATED" /> <ScalarProperty Name="GUID" ColumnName="GUID" /> <ScalarProperty Name="ID" ColumnName="ID" /> 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 @@ <!-- Diagram content (shape and connector positions) --> <edmx:Diagrams> <Diagram DiagramId="f9ae01d708754bbd997add25a4bacc79" Name="Diagram1"> - <EntityTypeShape EntityType="RemoteModel.ACTION_TYPES" Width="1.5" PointX="8" PointY="38.75" /> - <EntityTypeShape EntityType="RemoteModel.ADDRESS" Width="1.5" PointX="1.5" PointY="40" /> - <EntityTypeShape EntityType="RemoteModel.APPLICATION_DISPLAY_PANEL_VERSIONS" Width="1.5" PointX="1.5" PointY="71" /> - <EntityTypeShape EntityType="RemoteModel.APPLICATION_FIRMWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="80.5" /> - <EntityTypeShape EntityType="RemoteModel.APPLICATION_OS_VERSIONS" Width="1.5" PointX="1.5" PointY="73.875" /> - <EntityTypeShape EntityType="RemoteModel.APPLICATION_VERSIONS" Width="1.5" PointX="1.5" PointY="57.125" /> - <EntityTypeShape EntityType="RemoteModel.BRUSH_STOPS" Width="1.5" PointX="14.75" PointY="14.125" /> - <EntityTypeShape EntityType="RemoteModel.CARTRIDGE_TYPES" Width="1.5" PointX="3" PointY="28.125" /> - <EntityTypeShape EntityType="RemoteModel.CAT" Width="1.5" PointX="5.25" PointY="12.25" /> - <EntityTypeShape EntityType="RemoteModel.CCT" Width="1.5" PointX="5.25" PointY="31.5" /> - <EntityTypeShape EntityType="RemoteModel.COLOR_CATALOGS" Width="1.5" PointX="12.5" PointY="20.5" /> - <EntityTypeShape EntityType="RemoteModel.COLOR_SPACES" Width="1.5" PointX="10.25" PointY="22.25" /> - <EntityTypeShape EntityType="RemoteModel.CONFIGURATION" Width="1.5" PointX="0.75" PointY="61.75" /> - <EntityTypeShape EntityType="RemoteModel.CONTACT" Width="1.5" PointX="1.5" PointY="49.875" /> - <EntityTypeShape EntityType="RemoteModel.DISPENSER_TYPES" Width="1.5" PointX="3" PointY="22.125" /> - <EntityTypeShape EntityType="RemoteModel.EMBEDDED_FIRMWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="68.125" /> - <EntityTypeShape EntityType="RemoteModel.EMBEDDED_SOFTWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="54.25" /> - <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES" Width="1.5" PointX="8" PointY="42.25" /> - <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES_ACTIONS" Width="1.5" PointX="10.25" PointY="42.75" /> - <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES_CATEGORIES" Width="1.5" PointX="5.75" PointY="41.25" /> - <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES_GROUPS" Width="1.5" PointX="5.75" PointY="44.375" /> - <EntityTypeShape EntityType="RemoteModel.FIBER_SHAPES" Width="1.5" PointX="0.75" PointY="24.375" /> - <EntityTypeShape EntityType="RemoteModel.FIBER_SYNTHS" Width="1.5" PointX="0.75" PointY="18.125" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_DANCER_TYPES" Width="1.5" PointX="1.5" PointY="92.125" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_DANCERS" Width="1.5" PointX="3.75" PointY="81.75" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_MOTOR_TYPES" Width="1.5" PointX="1.5" PointY="88.125" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_MOTORS" Width="1.5" PointX="3.75" PointY="75.75" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_PID_CONTROL_TYPES" Width="1.5" PointX="4.5" PointY="68.125" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_PID_CONTROLS" Width="1.5" PointX="6.75" PointY="75.75" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="76.875" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_WINDER_TYPES" Width="1.5" PointX="1.5" PointY="84.125" /> - <EntityTypeShape EntityType="RemoteModel.HARDWARE_WINDERS" Width="1.5" PointX="3.75" PointY="72" /> - <EntityTypeShape EntityType="RemoteModel.IDS_PACK_FORMULAS" Width="1.5" PointX="3" PointY="60.875" /> - <EntityTypeShape EntityType="RemoteModel.IDS_PACKS" Width="1.5" PointX="5.25" PointY="36.125" /> - <EntityTypeShape EntityType="RemoteModel.JOB_RUNS" Width="1.5" PointX="12.5" PointY="12.875" /> - <EntityTypeShape EntityType="RemoteModel.JOB" Width="1.5" PointX="10.25" PointY="12.625" /> - <EntityTypeShape EntityType="RemoteModel.LINEAR_MASS_DENSITY_UNITS" Width="1.5" PointX="0.75" PointY="7.25" /> - <EntityTypeShape EntityType="RemoteModel.LIQUID_TYPES" Width="1.5" PointX="3" PointY="7.375" /> - <EntityTypeShape EntityType="RemoteModel.LIQUID_TYPES_RMLS" Width="1.5" PointX="5.25" PointY="8.625" /> - <EntityTypeShape EntityType="RemoteModel.MACHINE_STUDIO_VERSIONS" Width="1.5" PointX="10.25" PointY="26.375" /> - <EntityTypeShape EntityType="RemoteModel.MACHINE_VERSIONS" Width="1.5" PointX="0.75" PointY="30.625" /> - <EntityTypeShape EntityType="RemoteModel.MACHINE" Width="1.5" PointX="3" PointY="44.625" /> - <EntityTypeShape EntityType="RemoteModel.MACHINES_CONFIGURATIONS" Width="1.5" PointX="5.25" PointY="54.75" /> - <EntityTypeShape EntityType="RemoteModel.MACHINES_EVENTS" Width="1.5" PointX="10.25" PointY="33.375" /> - <EntityTypeShape EntityType="RemoteModel.MEDIA_COLORS" Width="1.5" PointX="0.75" PointY="21" /> - <EntityTypeShape EntityType="RemoteModel.MEDIA_CONDITIONS" Width="1.5" PointX="0.75" PointY="10.25" /> - <EntityTypeShape EntityType="RemoteModel.MEDIA_MATERIALS" Width="1.5" PointX="0.75" PointY="27.25" /> - <EntityTypeShape EntityType="RemoteModel.MEDIA_PURPOSES" Width="1.5" PointX="0.75" PointY="14.75" /> - <EntityTypeShape EntityType="RemoteModel.MID_TANK_TYPES" Width="1.5" PointX="3" PointY="36.75" /> - <EntityTypeShape EntityType="RemoteModel.ORGANIZATION" Width="1.5" PointX="0.75" PointY="36.25" /> - <EntityTypeShape EntityType="RemoteModel.PERMISSION" Width="1.5" PointX="13" PointY="32.25" /> - <EntityTypeShape EntityType="RemoteModel.PROCESS_PARAMETERS_TABLES" Width="1.5" PointX="7.5" PointY="15.125" /> - <EntityTypeShape EntityType="RemoteModel.PROCESS_PARAMETERS_TABLES_GROUPS" Width="1.5" PointX="5.25" PointY="16.375" /> - <EntityTypeShape EntityType="RemoteModel.RML" Width="1.5" PointX="3" PointY="12" /> - <EntityTypeShape EntityType="RemoteModel.ROLE" Width="1.5" PointX="13" PointY="28.125" /> - <EntityTypeShape EntityType="RemoteModel.ROLES_PERMISSIONS" Width="1.5" PointX="15.25" PointY="28.25" /> - <EntityTypeShape EntityType="RemoteModel.SEGMENT" Width="1.5" PointX="12.5" PointY="16.125" /> - <EntityTypeShape EntityType="RemoteModel.SPOOL_TYPES" Width="1.5" PointX="8" PointY="26.25" /> - <EntityTypeShape EntityType="RemoteModel.SYNC_CONFIGURATIONS" Width="1.5" PointX="0.75" PointY="0.75" /> - <EntityTypeShape EntityType="RemoteModel.TECH_CONTROLLERS" Width="1.5" PointX="2.75" PointY="0.75" /> - <EntityTypeShape EntityType="RemoteModel.TECH_DISPENSERS" Width="1.5" PointX="4.75" PointY="0.75" /> - <EntityTypeShape EntityType="RemoteModel.TECH_IOS" Width="1.5" PointX="5.75" PointY="3.75" /> - <EntityTypeShape EntityType="RemoteModel.TECH_MONITORS" Width="1.5" PointX="7.75" PointY="0.75" /> - <EntityTypeShape EntityType="RemoteModel.TECH_MOTORS" Width="1.5" PointX="7.75" PointY="5.75" /> - <EntityTypeShape EntityType="RemoteModel.TECH_VALVES" Width="1.5" PointX="9.75" PointY="0.75" /> - <EntityTypeShape EntityType="RemoteModel.USER" Width="1.5" PointX="8" PointY="21.25" /> - <EntityTypeShape EntityType="RemoteModel.USERS_ROLES" Width="1.5" PointX="15.25" PointY="22.125" /> - <EntityTypeShape EntityType="RemoteModel.WINDING_METHODS" Width="1.5" PointX="8" PointY="10.125" /> + <EntityTypeShape EntityType="RemoteModel.ACTION_TYPES" Width="1.5" PointX="7" PointY="58.75" /> + <EntityTypeShape EntityType="RemoteModel.ADDRESS" Width="1.5" PointX="1.5" PointY="77.375" /> + <EntityTypeShape EntityType="RemoteModel.APPLICATION_DISPLAY_PANEL_VERSIONS" Width="1.5" PointX="1.5" PointY="60.375" /> + <EntityTypeShape EntityType="RemoteModel.APPLICATION_FIRMWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="35" /> + <EntityTypeShape EntityType="RemoteModel.APPLICATION_OS_VERSIONS" Width="1.5" PointX="1.5" PointY="63.375" /> + <EntityTypeShape EntityType="RemoteModel.APPLICATION_VERSIONS" Width="1.5" PointX="1.5" PointY="51.625" /> + <EntityTypeShape EntityType="RemoteModel.BRUSH_STOPS" Width="1.5" PointX="10.75" PointY="18.25" /> + <EntityTypeShape EntityType="RemoteModel.CARTRIDGE_TYPES" Width="1.5" PointX="4" PointY="63.25" /> + <EntityTypeShape EntityType="RemoteModel.CAT" Width="1.5" PointX="5.25" PointY="11.75" /> + <EntityTypeShape EntityType="RemoteModel.CCT" Width="1.5" PointX="5.25" PointY="16" /> + <EntityTypeShape EntityType="RemoteModel.COLOR_CATALOGS" Width="1.5" PointX="8.5" PointY="4.625" /> + <EntityTypeShape EntityType="RemoteModel.COLOR_SPACES" Width="1.5" PointX="6.25" PointY="6.375" /> + <EntityTypeShape EntityType="RemoteModel.CONFIGURATION" Width="1.5" PointX="0.75" PointY="42.5" /> + <EntityTypeShape EntityType="RemoteModel.CONTACT" Width="1.5" PointX="1.5" PointY="73.25" /> + <EntityTypeShape EntityType="RemoteModel.DISPENSER_TYPES" Width="1.5" PointX="4" PointY="69.25" /> + <EntityTypeShape EntityType="RemoteModel.EMBEDDED_FIRMWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="54.625" /> + <EntityTypeShape EntityType="RemoteModel.EMBEDDED_SOFTWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="57.5" /> + <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES" Width="1.5" PointX="7" PointY="54.25" /> + <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES_ACTIONS" Width="1.5" PointX="9.25" PointY="54.75" /> + <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES_CATEGORIES" Width="1.5" PointX="4.75" PointY="53.125" /> + <EntityTypeShape EntityType="RemoteModel.EVENT_TYPES_GROUPS" Width="1.5" PointX="4.75" PointY="56.25" /> + <EntityTypeShape EntityType="RemoteModel.FIBER_SHAPES" Width="1.5" PointX="0.75" PointY="8.75" /> + <EntityTypeShape EntityType="RemoteModel.FIBER_SYNTHS" Width="1.5" PointX="0.75" PointY="20" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_DANCER_TYPES" Width="1.5" PointX="8.5" PointY="49.25" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_DANCERS" Width="1.5" PointX="10.75" PointY="42.875" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_MOTOR_TYPES" Width="1.5" PointX="5.5" PointY="48.25" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_MOTORS" Width="1.5" PointX="7.75" PointY="42.875" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_PID_CONTROL_TYPES" Width="1.5" PointX="7.5" PointY="27.25" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_PID_CONTROLS" Width="1.5" PointX="9.75" PointY="31.875" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_VERSIONS" Width="1.5" PointX="1.5" PointY="38" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_WINDER_TYPES" Width="1.5" PointX="1.5" PointY="5.25" /> + <EntityTypeShape EntityType="RemoteModel.HARDWARE_WINDERS" Width="1.5" PointX="3.75" PointY="38.125" /> + <EntityTypeShape EntityType="RemoteModel.IDS_PACK_FORMULAS" Width="1.5" PointX="4" PointY="59.875" /> + <EntityTypeShape EntityType="RemoteModel.IDS_PACKS" Width="1.5" PointX="6.25" PointY="37.875" /> + <EntityTypeShape EntityType="RemoteModel.JOB_RUNS" Width="1.5" PointX="7.5" PointY="23.75" /> + <EntityTypeShape EntityType="RemoteModel.JOB" Width="1.5" PointX="5.25" PointY="20.125" /> + <EntityTypeShape EntityType="RemoteModel.LINEAR_MASS_DENSITY_UNITS" Width="1.5" PointX="0.75" PointY="25.875" /> + <EntityTypeShape EntityType="RemoteModel.LIQUID_TYPES" Width="1.5" PointX="3" PointY="22" /> + <EntityTypeShape EntityType="RemoteModel.LIQUID_TYPES_RMLS" Width="1.5" PointX="8.25" PointY="16" /> + <EntityTypeShape EntityType="RemoteModel.MACHINE_STUDIO_VERSIONS" Width="1.5" PointX="5.25" PointY="29" /> + <EntityTypeShape EntityType="RemoteModel.MACHINE_VERSIONS" Width="1.5" PointX="0.75" PointY="31.75" /> + <EntityTypeShape EntityType="RemoteModel.MACHINE" Width="1.5" PointX="3" PointY="45.5" /> + <EntityTypeShape EntityType="RemoteModel.MACHINES_CONFIGURATIONS" Width="1.5" PointX="5.25" PointY="45.125" /> + <EntityTypeShape EntityType="RemoteModel.MACHINES_EVENTS" Width="1.5" PointX="9.25" PointY="38.25" /> + <EntityTypeShape EntityType="RemoteModel.MEDIA_COLORS" Width="1.5" PointX="0.75" PointY="11.625" /> + <EntityTypeShape EntityType="RemoteModel.MEDIA_CONDITIONS" Width="1.5" PointX="0.75" PointY="22.875" /> + <EntityTypeShape EntityType="RemoteModel.MEDIA_MATERIALS" Width="1.5" PointX="0.75" PointY="28.75" /> + <EntityTypeShape EntityType="RemoteModel.MEDIA_PURPOSES" Width="1.5" PointX="0.75" PointY="16.25" /> + <EntityTypeShape EntityType="RemoteModel.MID_TANK_TYPES" Width="1.5" PointX="4" PointY="66.125" /> + <EntityTypeShape EntityType="RemoteModel.ORGANIZATION" Width="1.5" PointX="0.75" PointY="68.625" /> + <EntityTypeShape EntityType="RemoteModel.PERMISSION" Width="1.5" PointX="8" PointY="0.75" /> + <EntityTypeShape EntityType="RemoteModel.PROCESS_PARAMETERS_TABLES" Width="1.5" PointX="7.5" PointY="31.125" /> + <EntityTypeShape EntityType="RemoteModel.PROCESS_PARAMETERS_TABLES_GROUPS" Width="1.5" PointX="5.25" PointY="32.375" /> + <EntityTypeShape EntityType="RemoteModel.RML" Width="1.5" PointX="3" PointY="13.5" /> + <EntityTypeShape EntityType="RemoteModel.ROLE" Width="1.5" PointX="8" PointY="12.625" /> + <EntityTypeShape EntityType="RemoteModel.ROLES_PERMISSIONS" Width="1.5" PointX="10.25" PointY="12.75" /> + <EntityTypeShape EntityType="RemoteModel.SEGMENT" Width="1.5" PointX="7.5" PointY="20.25" /> + <EntityTypeShape EntityType="RemoteModel.SPOOL_TYPES" Width="1.5" PointX="3" PointY="8.625" /> + <EntityTypeShape EntityType="RemoteModel.SYNC_CONFIGURATIONS" Width="1.5" PointX="0.75" PointY="2.25" /> + <EntityTypeShape EntityType="RemoteModel.TECH_CONTROLLERS" Width="1.5" PointX="3.75" PointY="2.25" /> + <EntityTypeShape EntityType="RemoteModel.TECH_DISPENSERS" Width="1.5" PointX="10.75" PointY="2.25" /> + <EntityTypeShape EntityType="RemoteModel.TECH_IOS" Width="1.5" PointX="10.75" PointY="5.25" /> + <EntityTypeShape EntityType="RemoteModel.TECH_MONITORS" Width="1.5" PointX="12.75" PointY="2.25" /> + <EntityTypeShape EntityType="RemoteModel.TECH_MOTORS" Width="1.5" PointX="10.75" PointY="9.25" /> + <EntityTypeShape EntityType="RemoteModel.TECH_VALVES" Width="1.5" PointX="12.75" PointY="7.25" /> + <EntityTypeShape EntityType="RemoteModel.USER" Width="1.5" PointX="3" PointY="29.75" /> + <EntityTypeShape EntityType="RemoteModel.USERS_ROLES" Width="1.5" PointX="10.25" PointY="27.625" /> + <EntityTypeShape EntityType="RemoteModel.WINDING_METHODS" Width="1.5" PointX="3" PointY="26.625" /> <AssociationConnector Association="RemoteModel.FK_EVENTS_ACTIONS_ACTIONS" /> <AssociationConnector Association="RemoteModel.FK_ORGANIZATIONS_ADDRESSES" /> <AssociationConnector Association="RemoteModel.FK_USERS_ADDRESSES" /> 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 /// <seealso cref="Tango.Emulations.IEmulator" /> 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<DigitalPin> _digitalOutputPinsStates; private List<DigitalPin> _digitalInputPinsStates; - private LogManager LogManager = LogManager.Default; private List<ValueComponentState> _componentsStates; + public List<MachineEventState> EventsStates { get; set; } + #region Constructors /// <summary> @@ -70,6 +71,8 @@ namespace Tango.Emulations.Emulators private void Init() { + EventsStates = MachineEventState.GetAllEventsStates(); + _motorJoggingRequestCodes = new List<int>(); _motorHomingRequestCodes = new List<int>(); _dispenserJoggingRequestCodes = new List<int>(); @@ -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"; @@ -584,5 +589,11 @@ 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<MachineEventState> GetAllEventsStates() + { + List<MachineEventState> states = new List<MachineEventState>(); + + foreach (var value in Enum.GetValues(typeof(EventType)).OfType<EventType>()) + { + 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 @@ </Compile> <Compile Include="EmulatorBase.cs" /> <Compile Include="Emulators\MachineEmulator.cs" /> + <Compile Include="Emulators\MachineEventState.cs" /> <Compile Include="Emulators\MobileEmulator.cs" /> <Compile Include="IEmulator.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> 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<object> _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<object> _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 { @@ -22,6 +23,26 @@ namespace Tango.Integration.Operation public interface IMachineOperator : ITransporter { /// <summary> + /// Occurs when a request has been sent. + /// </summary> + event EventHandler<IMessage> RequestSent; + + /// <summary> + /// Occurs when a request response has been received. + /// </summary> + event EventHandler<IMessage> ResponseReceived; + + /// <summary> + /// Occurs when a response has been sent. + /// </summary> + event EventHandler<IMessage> ResponseSent; + + /// <summary> + /// Occurs when a request has failed. + /// </summary> + event EventHandler<RequestFailedEventArgs> RequestFailed; + + /// <summary> /// Occurs when there is new diagnostics data available. /// </summary> event EventHandler<PushDiagnosticsResponse> DiagnosticsDataAvailable; 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. /// </summary> public event EventHandler<PushDiagnosticsResponse> DiagnosticsDataAvailable; + + /// <summary> + /// Occurs when a new debug log is available. + /// </summary> public event EventHandler<DebugLogResponse> DebugLogAvailable; + /// <summary> + /// Occurs when a request has been sent. + /// </summary> + public event EventHandler<IMessage> RequestSent; + + /// <summary> + /// Occurs when a response has been sent. + /// </summary> + public event EventHandler<IMessage> ResponseSent; + + /// <summary> + /// Occurs when a request has timed out. + /// </summary> + public event EventHandler<RequestFailedEventArgs> RequestFailed; + + /// <summary> + /// Occurs when a request response has been received. + /// </summary> + public event EventHandler<IMessage> ResponseReceived; + #endregion #region Properties @@ -137,22 +162,32 @@ namespace Tango.Integration.Operation { var request = new PushDiagnosticsRequest(); - LogRequest(request); + LogRequestSent(request); + + bool responseLogged = false; SendContinuousRequest<PushDiagnosticsRequest, PushDiagnosticsResponse>(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<DebugLogRequest, DebugLogResponse>(request).ObserveOn(new NewThreadScheduler()) .Subscribe @@ -226,6 +261,42 @@ namespace Tango.Integration.Operation DebugLogAvailable?.Invoke(this, data); } + /// <summary> + /// Called when the request has been sent + /// </summary> + /// <param name="response">The request.</param> + protected virtual void OnRequestSent(IMessage request) + { + RequestSent?.Invoke(this, request); + } + + /// <summary> + /// Called when the response has been received + /// </summary> + /// <param name="response">The response.</param> + protected virtual void OnResponseReceived(IMessage response) + { + ResponseReceived?.Invoke(this, response); + } + + /// <summary> + /// Called when the response has been sent + /// </summary> + /// <param name="response">The response.</param> + protected virtual void OnResponseSent(IMessage response) + { + ResponseSent?.Invoke(this, response); + } + + /// <summary> + /// Called when the request has been failed + /// </summary> + /// <param name="request">The request.</param> + 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<JobRequest, JobResponse>(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<UploadProcessParametersRequest, UploadProcessParametersResponse>(request); + + UploadProcessParametersResponse response = null; + + try + { + LogRequestSent(request); + response = await SendRequest<UploadProcessParametersRequest, UploadProcessParametersResponse>(request); + LogResponseReceived(response); + } + catch (Exception ex) + { + LogRequestFailed(request, ex); + throw ex; + } + + return response; } /// <summary> @@ -377,7 +470,7 @@ namespace Tango.Integration.Operation { UploadHardwareConfigurationRequest request = new UploadHardwareConfigurationRequest(); request.HardwareConfiguration = hardwareConfiguration; - LogRequest(request); + LogRequestSent(request); return await SendRequest<UploadHardwareConfigurationRequest, UploadHardwareConfigurationResponse>(request); } @@ -388,8 +481,21 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<MotorJoggingResponse> StartMotorJogging(MotorJoggingRequest request) { - LogRequest(request); - return await SendRequest<MotorJoggingRequest, MotorJoggingResponse>(request); + MotorJoggingResponse response = null; + + try + { + LogRequestSent(request); + response = await SendRequest<MotorJoggingRequest, MotorJoggingResponse>(request); + LogResponseReceived(response); + } + catch (Exception ex) + { + LogRequestFailed(request, ex); + throw ex; + } + + return response; } /// <summary> @@ -399,7 +505,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<MotorAbortJoggingResponse> StopMotorJogging(MotorAbortJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<MotorAbortJoggingRequest, MotorAbortJoggingResponse>(request); } @@ -410,7 +516,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public IObservable<MotorHomingResponse> StartMotorHoming(MotorHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return SendContinuousRequest<MotorHomingRequest, MotorHomingResponse>(request).Select(x => x.Message); } @@ -421,7 +527,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<MotorAbortHomingResponse> StopMotorHoming(MotorAbortHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<MotorAbortHomingRequest, MotorAbortHomingResponse>(request); } @@ -432,7 +538,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<DispenserJoggingResponse> StartDispenserJogging(DispenserJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<DispenserJoggingRequest, DispenserJoggingResponse>(request); } @@ -443,7 +549,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<DispenserAbortJoggingResponse> StopDispenserJogging(DispenserAbortJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<DispenserAbortJoggingRequest, DispenserAbortJoggingResponse>(request); } @@ -454,7 +560,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public IObservable<DispenserHomingResponse> StartDispenserHoming(DispenserHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return SendContinuousRequest<DispenserHomingRequest, DispenserHomingResponse>(request).Select(x => x.Message); } @@ -465,7 +571,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<DispenserAbortHomingResponse> StopDispenserHoming(DispenserAbortHomingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<DispenserAbortHomingRequest, DispenserAbortHomingResponse>(request); } @@ -476,7 +582,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<SetDigitalOutResponse> SetDigitalOut(SetDigitalOutRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<SetDigitalOutRequest, SetDigitalOutResponse>(request); } @@ -487,7 +593,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<ThreadJoggingResponse> StartThreadJogging(ThreadJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<ThreadJoggingRequest, ThreadJoggingResponse>(request); } @@ -498,7 +604,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<ThreadAbortJoggingResponse> StopThreadJogging(ThreadAbortJoggingRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<ThreadAbortJoggingRequest, ThreadAbortJoggingResponse>(request); } @@ -509,7 +615,7 @@ namespace Tango.Integration.Operation /// <returns></returns> public async Task<SetComponentValueResponse> SetComponentValue(SetComponentValueRequest request) { - LogRequest(request); + LogRequestSent(request); return await SendRequest<SetComponentValueRequest, SetComponentValueResponse>(request); } @@ -518,12 +624,33 @@ namespace Tango.Integration.Operation #region Private Methods /// <summary> - /// Logs the request. + /// Logs the request sent. + /// </summary> + /// <param name="message">The message.</param> + private void LogRequestSent(IMessage message) + { + _logManager.Log(String.Format("Sending request '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); + OnRequestSent(message); + } + + /// <summary> + /// Logs the request failed. + /// </summary> + /// <param name="message">The message.</param> + 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); + } + + /// <summary> + /// Logs the response received. /// </summary> - /// <param name="obj">The object.</param> - private void LogRequest(Object obj) + /// <param name="message">The message.</param> + 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<IExternalBridgeClient> _availableMachines; /// <summary> 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 @@ <Compile Include="Operation\IMachineOperator.cs" /> <Compile Include="Operation\MachineOperator.cs" /> <Compile Include="Operation\JobHandler.cs" /> + <Compile Include="Operation\RequestFailedEventArgs.cs" /> <Compile Include="Services\ComPortInfo.cs" /> <Compile Include="Services\ExternalBridgeScanner.cs" /> <Compile Include="Services\ExternalBridgeTcpClient.cs" /> 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<String, PendingResponse> _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}" > <UserControl.Resources> <converters:BooleanInverseConverter x:Key="BooleanInverseConverter"></converters:BooleanInverseConverter> @@ -49,9 +50,31 @@ </Grid.RowDefinitions> <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="1*"/> + <ColumnDefinition Width="280"/> + </Grid.ColumnDefinitions> <TextBox x:Name="txtLog" FontFamily="monospaced" TextChanged="txtLog_TextChanged" Text="{Binding Log}" Background="Transparent" Foreground="Red" FontSize="11" Padding="5" Style="{x:Null}" BorderThickness="0" IsReadOnly="True" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"> </TextBox> + + <Grid Grid.Column="1"> + <DockPanel> + <TextBlock DockPanel.Dock="Top" Margin="10 0 0 0">HARDWARE EVENTS</TextBlock> + <ListBox BorderThickness="0" Background="#66000000" Margin="10 10 10 40" ItemsSource="{Binding Emulator.EventsStates}" FontSize="11"> + <ListBox.ItemContainerStyle> + <Style TargetType="ListBoxItem"> + + </Style> + </ListBox.ItemContainerStyle> + <ListBox.ItemTemplate> + <DataTemplate> + <CheckBox FontSize="11" Content="{Binding EventType}" IsChecked="{Binding IsActive}" Margin="5"></CheckBox> + </DataTemplate> + </ListBox.ItemTemplate> + </ListBox> + </DockPanel> + </Grid> </Grid> <Grid x:Name="gridContent" Background="#151515" Margin="5" Visibility="Hidden"> |
