diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging')
2 files changed, 20 insertions, 50 deletions
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 89b8920d9..11d156292 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -18,7 +18,6 @@ using Tango.MachineStudio.Common.StudioApplication; using Tango.PMR.Diagnostics; using Tango.Integration.Operation; using Tango.Core.ExtensionMethods; -using Tango.Transport; namespace Tango.MachineStudio.Common.EventLogging { @@ -29,7 +28,6 @@ namespace Tango.MachineStudio.Common.EventLogging public class DefaultEventLogger : ExtendedObject, IEventLogger { private ObservablesContext _db; - private static object _lockInit = new object(); private Thread _logThread; private ConcurrentQueue<MachinesEvent> _events; private IStudioApplicationManager _application; @@ -48,15 +46,6 @@ namespace Tango.MachineStudio.Common.EventLogging #endregion - #region Properties - - /// <summary> - /// Gets or sets a value indicating whether to save the incoming events to database. - /// </summary> - public bool SaveToDB { get; set; } - - #endregion - #region Constructors /// <summary> @@ -68,8 +57,6 @@ namespace Tango.MachineStudio.Common.EventLogging { _hostName = Environment.MachineName; - SaveToDB = true; - _events = new ConcurrentQueue<MachinesEvent>(); _pendingEvents = new List<MachinesEvent>(); @@ -90,27 +77,24 @@ namespace Tango.MachineStudio.Common.EventLogging private void Init() { - lock (_lockInit) + if (!_isInitialized) { - if (!_isInitialized) + try { - try - { - _db = ObservablesContext.CreateDefault(); - - _db.EventTypes.ToList(); + _db = ObservablesContext.CreateDefault(); - foreach (var type in _db.EventTypes) - { - _eventTypesGuids.Add((EventTypes)type.Code, type); - } + _db.EventTypes.ToList(); - _isInitialized = true; - } - catch + foreach (var type in _db.EventTypes) { - _isInitialized = false; + _eventTypesGuids.Add((EventTypes)type.Code, type); } + + _isInitialized = true; + } + catch + { + _isInitialized = false; } } } @@ -143,8 +127,6 @@ namespace Tango.MachineStudio.Common.EventLogging machine.RequestSent += Machine_RequestSent; machine.RequestFailed += Machine_RequestFailed; machine.ResponseReceived += Machine_ResponseReceived; - - SaveToDB = !(machine is IExternalBridgeSecureClient); } } @@ -155,7 +137,7 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="message">The message.</param> private void Machine_RequestSent(object sender, IMessage message) { - //Log(EventTypes.REQUEST_SENT, String.Format("Sending request '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); + Log(EventTypes.REQUEST_SENT, String.Format("Sending request '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); } /// <summary> @@ -165,7 +147,7 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="e">The <see cref="RequestFailedEventArgs"/> instance containing the event data.</param> private void Machine_RequestFailed(object sender, RequestFailedEventArgs e) { - //Log(EventTypes.REQUEST_FAILED, String.Format("Request failed '{0}'...{1}{2}{1}{3}", e.Message.GetType().Name, Environment.NewLine, e.Message.ToJsonString(), e.Exception.ToString())); + Log(EventTypes.REQUEST_FAILED, String.Format("Request failed '{0}'...{1}{2}{1}{3}", e.Message.GetType().Name, Environment.NewLine, e.Message.ToJsonString(), e.Exception.ToString())); } /// <summary> @@ -175,7 +157,7 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="message">The message.</param> private void Machine_ResponseReceived(object sender, IMessage message) { - //Log(EventTypes.RESPONSE_RECEIVED, String.Format("Response received '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); + Log(EventTypes.RESPONSE_RECEIVED, String.Format("Response received '{0}'...{1}{2}", message.GetType().Name, Environment.NewLine, message.ToJsonString())); } /// <summary> @@ -198,10 +180,10 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="events">The events.</param> private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable<MachinesEvent> events) { - //foreach (var ev in events) - //{ - // Log(String.Format("Event '{0}' resolved.", ev.EventType.Name)); - //} + foreach (var ev in events) + { + Log(String.Format("Event '{0}' resolved.", ev.EventType.Name)); + } } #endregion @@ -214,8 +196,6 @@ namespace Tango.MachineStudio.Common.EventLogging /// <param name="machineEvent">The machine event.</param> public void Log(MachinesEvent machineEvent) { - Init(); - machineEvent.HostName = _hostName; machineEvent.EventType = _eventTypesGuids[machineEvent.Type]; @@ -263,7 +243,7 @@ namespace Tango.MachineStudio.Common.EventLogging machineEvent.EventType = _eventTypesGuids[eventType]; machineEvent.EventTypeGuid = machineEvent.EventType.Guid; - if (write_to_db && SaveToDB) + if (write_to_db) { Log(machineEvent); } @@ -327,11 +307,6 @@ namespace Tango.MachineStudio.Common.EventLogging /// </summary> public void FlushAll() { - if (!SaveToDB) - { - return; - } - bool _saveChanges = false; while (_events.Count > 0) 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 44916ec21..ceb399d24 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs @@ -20,11 +20,6 @@ namespace Tango.MachineStudio.Common.EventLogging event EventHandler<MachinesEvent> NewLog; /// <summary> - /// Gets or sets a value indicating whether to save the incoming events to database. - /// </summary> - bool SaveToDB { get; set; } - - /// <summary> /// Logs the specified machine event. /// </summary> /// <param name="machineEvent">The machine event.</param> |
