aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-11-20 13:27:36 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-11-20 13:27:36 +0200
commitc272cdaaa43f7bf2fefcb36bbfe49624fc4a5ff1 (patch)
treebcc9ccd584d7cc706f6453e7a906fa3f1485ef53 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common
parentfa8459be63d8f76059d1e71ab86c01e0a13851b5 (diff)
downloadTango-c272cdaaa43f7bf2fefcb36bbfe49624fc4a5ff1.tar.gz
Tango-c272cdaaa43f7bf2fefcb36bbfe49624fc4a5ff1.zip
Added job runs logger to machine studio.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/DefaultJobRunsLogger.cs110
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/IJobRunsLogger.cs14
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs5
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj4
4 files changed, 132 insertions, 1 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/DefaultJobRunsLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/DefaultJobRunsLogger.cs
new file mode 100644
index 000000000..fb01e3aa8
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/DefaultJobRunsLogger.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL;
+using Tango.BL.Entities;
+using Tango.BL.Enumerations;
+using Tango.Core;
+using Tango.Core.DI;
+using Tango.Integration.ExternalBridge;
+using Tango.Integration.Operation;
+using Tango.MachineStudio.Common.StudioApplication;
+
+namespace Tango.MachineStudio.Common.JobRunsLogging
+{
+ public class DefaultJobRunsLogger : ExtendedObject, IJobRunsLogger
+ {
+ private ObservablesContext _context;
+ private DateTime _start_date;
+ private Job _job;
+ private IStudioApplicationManager applicationManager;
+
+ public void Init(IStudioApplicationManager appManager)
+ {
+ applicationManager = appManager;
+ _context = ObservablesContext.CreateDefault();
+ applicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged;
+ }
+
+ private void ApplicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient machine)
+ {
+ if (machine != null)
+ {
+ machine.PrintingStarted -= Machine_PrintingStarted;
+ machine.PrintingStarted += Machine_PrintingStarted;
+ machine.PrintingCompleted -= Machine_PrintingCompleted;
+ machine.PrintingCompleted += Machine_PrintingCompleted;
+ machine.PrintingAborted -= Machine_PrintingAborted;
+ machine.PrintingAborted += Machine_PrintingAborted;
+ machine.PrintingFailed -= Machine_PrintingFailed;
+ machine.PrintingFailed += Machine_PrintingFailed;
+ }
+ }
+
+ private void Machine_PrintingFailed(object sender, PrintingFailedEventArgs e)
+ {
+ if (e.Job.Guid == _job.Guid)
+ {
+ Task.Factory.StartNew(() =>
+ {
+ _context.JobRuns.Add(new JobRun()
+ {
+ StartDate = _start_date,
+ EndDate = DateTime.UtcNow,
+ JobGuid = _job.Guid,
+ JobRunStatus = JobRunStatus.Failed,
+ FailedMessage = e.Exception.Message,
+ });
+
+ _context.SaveChanges();
+ });
+ }
+ }
+
+ private void Machine_PrintingAborted(object sender, PrintingEventArgs e)
+ {
+ if (e.Job.Guid == _job.Guid)
+ {
+ Task.Factory.StartNew(() =>
+ {
+ _context.JobRuns.Add(new JobRun()
+ {
+ StartDate = _start_date,
+ EndDate = DateTime.UtcNow,
+ JobGuid = _job.Guid,
+ JobRunStatus = JobRunStatus.Aborted,
+ });
+
+ _context.SaveChanges();
+ });
+ }
+ }
+
+ private void Machine_PrintingCompleted(object sender, PrintingEventArgs e)
+ {
+ if (e.Job.Guid == _job.Guid)
+ {
+ Task.Factory.StartNew(() =>
+ {
+ _context.JobRuns.Add(new JobRun()
+ {
+ StartDate = _start_date,
+ EndDate = DateTime.UtcNow,
+ JobGuid = _job.Guid,
+ JobRunStatus = JobRunStatus.Completed,
+ });
+
+ _context.SaveChanges();
+ });
+ }
+ }
+
+ private void Machine_PrintingStarted(object sender, PrintingEventArgs e)
+ {
+ _job = e.Job;
+ _start_date = DateTime.UtcNow;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/IJobRunsLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/IJobRunsLogger.cs
new file mode 100644
index 000000000..c3eca953b
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/IJobRunsLogger.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.MachineStudio.Common.StudioApplication;
+
+namespace Tango.MachineStudio.Common.JobRunsLogging
+{
+ public interface IJobRunsLogger
+ {
+ void Init(IStudioApplicationManager appManager);
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs
index 1a0499f2c..3e54a327b 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/StudioApplication/IStudioApplicationManager.cs
@@ -16,6 +16,11 @@ namespace Tango.MachineStudio.Common.StudioApplication
public interface IStudioApplicationManager : INotifyPropertyChanged
{
/// <summary>
+ /// Occurs when the application is ready.
+ /// </summary>
+ event EventHandler ApplicationReady;
+
+ /// <summary>
/// Occurs when the connected machine property has changed.
/// </summary>
event EventHandler<IExternalBridgeClient> ConnectedMachineChanged;
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 551ec93c0..4259bbb04 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
@@ -101,6 +101,8 @@
<Compile Include="Html\IHtmlPresenter.cs" />
<None Include="Helpers\GraphsHelper.cs" />
<Compile Include="IStudioViewModel.cs" />
+ <Compile Include="JobRunsLogging\DefaultJobRunsLogger.cs" />
+ <Compile Include="JobRunsLogging\IJobRunsLogger.cs" />
<Compile Include="MachineStudioSettings.cs" />
<Compile Include="Messages\MachineConnectionChangedMessage.cs" />
<Compile Include="Navigation\INavigationBlocker.cs" />
@@ -301,7 +303,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file