aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-03-26 14:21:53 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-03-26 14:21:53 +0300
commit1061758f95b7ba633e6bcc2c3556b42f033b1a79 (patch)
treec3cf106aa6b73fe1e0bfcd6b88399a5721990eb0 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common
parent761686de34252d76bda126c738d82c021ef6bf5d (diff)
downloadTango-1061758f95b7ba633e6bcc2c3556b42f033b1a79.tar.gz
Tango-1061758f95b7ba633e6bcc2c3556b42f033b1a79.zip
Working on logging module !
Modified PID Control Table.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs92
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs11
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Messages/MachineConnectionChangedMessage.cs14
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj1
4 files changed, 91 insertions, 27 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 0f19d3b6d..d3fb0897f 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs
@@ -34,13 +34,14 @@ namespace Tango.MachineStudio.Common.EventLogging
private Dictionary<EventTypes, BL.Entities.EventType> _eventTypesGuids;
private String _hostName;
private bool _isInitialized;
+ private List<MachinesEvent> _pendingEvents;
#region Events
/// <summary>
/// Occurs when a new machine event has been logged.
/// </summary>
- public event EventHandler<MachinesEvent> NewLog;
+ public event EventHandler<MachinesEvent> NewLog;
#endregion
@@ -56,6 +57,7 @@ namespace Tango.MachineStudio.Common.EventLogging
_hostName = Environment.MachineName;
_events = new ConcurrentQueue<MachinesEvent>();
+ _pendingEvents = new List<MachinesEvent>();
_eventTypesGuids = new Dictionary<EventTypes, BL.Entities.EventType>();
@@ -90,7 +92,7 @@ namespace Tango.MachineStudio.Common.EventLogging
_eventTypesGuids.Add((EventTypes)type.Code, type);
}
- _isInitialized = true;
+ _isInitialized = true;
}
}
@@ -176,15 +178,33 @@ namespace Tango.MachineStudio.Common.EventLogging
/// <param name="machineEvent">The machine event.</param>
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);
+ if (_application.ConnectedMachine == null || _authentication.CurrentUser == null)
+ {
+ _pendingEvents.Add(machineEvent);
+ }
+ else
+ {
+ if (_pendingEvents.Count > 0)
+ {
+ var pending = _pendingEvents.ToList();
+ _pendingEvents.Clear();
+
+ foreach (var ev in pending)
+ {
+ Log(ev);
+ }
+ }
- NewLog?.Invoke(this, machineEvent);
+ LogManager.Log("Logging event " + machineEvent.EventType.Name + " - " + machineEvent.Description);
+ machineEvent.MachineGuid = _application.ConnectedMachine.Guid;
+ machineEvent.UserGuid = _authentication.CurrentUser.Guid;
+ machineEvent.User = _authentication.CurrentUser;
+ _events.Enqueue(machineEvent);
+ NewLog?.Invoke(this, machineEvent);
+ }
}
/// <summary>
@@ -223,6 +243,16 @@ namespace Tango.MachineStudio.Common.EventLogging
}
/// <summary>
+ /// Logs the specified exception using the <see cref="EventTypes.ApplicationException" />.
+ /// </summary>
+ /// <param name="exception">The exception.</param>
+ /// <param name="description"></param>
+ public void Log(Exception exception, string description)
+ {
+ Log(EventTypes.ApplicationException, description + Environment.NewLine + exception.ToString());
+ }
+
+ /// <summary>
/// Logs the specified message using the <see cref="EventTypes.ApplicationInformation"/>.
/// </summary>
/// <param name="message">The message.</param>
@@ -238,32 +268,40 @@ namespace Tango.MachineStudio.Common.EventLogging
{
while (true)
{
- bool _saveChanges = false;
+ FlushAll();
+ Thread.Sleep(5000);
+ }
+ }
- while (_events.Count > 0)
- {
- MachinesEvent ev = null;
+ /// <summary>
+ /// Immediately saves all pending events to database.
+ /// </summary>
+ public void FlushAll()
+ {
+ bool _saveChanges = false;
- if (_events.TryDequeue(out ev))
- {
- _db.MachinesEvents.Add(ev);
- _saveChanges = true;
- }
- }
+ while (_events.Count > 0)
+ {
+ MachinesEvent ev = null;
- if (_saveChanges)
+ if (_events.TryDequeue(out ev))
{
- try
- {
- _db.SaveChanges();
- }
- catch (Exception ex)
- {
- LogManager.Log(ex, "Error saving machine event to database.");
- }
+ ev.User = null;
+ _db.MachinesEvents.Add(ev);
+ _saveChanges = true;
}
+ }
- Thread.Sleep(5000);
+ if (_saveChanges)
+ {
+ try
+ {
+ _db.SaveChanges();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error saving machine event to database.");
+ }
}
}
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 aeecb4ae6..ce599a398 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/IEventLogger.cs
@@ -45,9 +45,20 @@ namespace Tango.MachineStudio.Common.EventLogging
void Log(Exception exception);
/// <summary>
+ /// Logs the specified exception using the <see cref="EventTypes.ApplicationException"/>.
+ /// </summary>
+ /// <param name="exception">The exception.</param>
+ void Log(Exception exception, String description);
+
+ /// <summary>
/// Logs the specified message using the <see cref="EventTypes.ApplicationInformation"/>.
/// </summary>
/// <param name="message">The message.</param>
void Log(String message);
+
+ /// <summary>
+ /// Immediately saves all pending events to database.
+ /// </summary>
+ void FlushAll();
}
}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Messages/MachineConnectionChangedMessage.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Messages/MachineConnectionChangedMessage.cs
new file mode 100644
index 000000000..90820ed47
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Messages/MachineConnectionChangedMessage.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Integration.Services;
+
+namespace Tango.MachineStudio.Common.Messages
+{
+ public class MachineConnectionChangedMessage : IStudioMessage
+ {
+ public IExternalBridgeClient Machine { get; set; }
+ }
+}
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 15ab97a27..df553f502 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
@@ -105,6 +105,7 @@
<Compile Include="EventLogging\IEventLogger.cs" />
<Compile Include="ExtensionMethods\CommonDialogExtensions.cs" />
<Compile Include="Helpers\GraphsHelper.cs" />
+ <Compile Include="Messages\MachineConnectionChangedMessage.cs" />
<Compile Include="Notifications\BarItem.cs" />
<Compile Include="Notifications\DialogViewVM.cs" />
<Compile Include="StudioApplication\IModuleRequestListener.cs" />