From c272cdaaa43f7bf2fefcb36bbfe49624fc4a5ff1 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 20 Nov 2018 13:27:36 +0200 Subject: Added job runs logger to machine studio. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1516 bytes .../JobRunsLogging/DefaultJobRunsLogger.cs | 110 +++++++++++++++ .../JobRunsLogging/IJobRunsLogger.cs | 14 ++ .../StudioApplication/IStudioApplicationManager.cs | 5 + .../Tango.MachineStudio.Common.csproj | 4 +- .../DefaultStudioApplicationManager.cs | 16 ++- .../Tango.MachineStudio.UI.csproj | 2 +- .../Tango.MachineStudio.UI/ViewModelLocator.cs | 4 + .../Visual_Studio/Tango.BL/Builders/JobBuilder.cs | 8 ++ .../Tango.BL/Builders/JobRunsBuilder.cs | 31 +++++ Software/Visual_Studio/Tango.BL/Entities/JobRun.cs | 57 ++++++-- .../Tango.BL/EntitiesExtensions/JobRun.cs | 32 +++++ .../Tango.BL/Enumerations/JobRunStatus.cs | 15 +++ Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 5 +- .../Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs | 3 +- .../Tango.DAL.Remote/DB/RemoteADO.edmx | 9 +- .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 150 ++++++++++----------- 19 files changed, 371 insertions(+), 94 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/DefaultJobRunsLogger.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/JobRunsLogging/IJobRunsLogger.cs create mode 100644 Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs create mode 100644 Software/Visual_Studio/Tango.BL/EntitiesExtensions/JobRun.cs create mode 100644 Software/Visual_Studio/Tango.BL/Enumerations/JobRunStatus.cs (limited to 'Software') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index db0d38fa8..947bb2bdb 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 9ce09a6ab..c0f243190 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 6336d80ca..120d5e694 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ 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 @@ -15,6 +15,11 @@ namespace Tango.MachineStudio.Common.StudioApplication /// public interface IStudioApplicationManager : INotifyPropertyChanged { + /// + /// Occurs when the application is ready. + /// + event EventHandler ApplicationReady; + /// /// Occurs when the connected machine property has changed. /// 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 @@ + + @@ -301,7 +303,7 @@ - + \ No newline at end of file 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 3864708fc..6303b1ac8 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -26,6 +26,7 @@ using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.UI.Views; using Tango.Integration.Operation; using Tango.MachineStudio.UI.Windows; +using Tango.MachineStudio.Common.JobRunsLogging; namespace Tango.MachineStudio.UI.StudioApplication { @@ -39,15 +40,22 @@ namespace Tango.MachineStudio.UI.StudioApplication private INavigationManager _navigationManager; private IStudioModuleLoader _moduleLoader; private INotificationProvider _notification; + private IJobRunsLogger _jobRunsLogger; private List _openedWindows; private List _notified_view_models; + /// + /// Occurs when the application is ready. + /// + public event EventHandler ApplicationReady; + /// /// Initializes a new instance of the class. /// /// The navigation manager. - public DefaultStudioApplicationManager(INavigationManager navigationManager, IStudioModuleLoader moduleLoader, INotificationProvider notification) + public DefaultStudioApplicationManager(INavigationManager navigationManager, IStudioModuleLoader moduleLoader, INotificationProvider notification, IJobRunsLogger jobRunsLogger) { + _jobRunsLogger = jobRunsLogger; _moduleLoader = moduleLoader; _navigationManager = navigationManager; _notification = notification; @@ -332,7 +340,7 @@ namespace Tango.MachineStudio.UI.StudioApplication /// public void NotifyApplicationReady() { - TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => + TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => { if (!_notified_view_models.Contains(x)) { @@ -340,6 +348,9 @@ namespace Tango.MachineStudio.UI.StudioApplication _notified_view_models.Add(x); } }); + + ApplicationReady?.Invoke(this, new EventArgs()); + _jobRunsLogger.Init(this); } /// @@ -360,5 +371,6 @@ namespace Tango.MachineStudio.UI.StudioApplication ConnectedMachine = null; } } + } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 4fb14ba47..39f748ceb 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -591,7 +591,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\Microsoft.WITDataStore32.dll" "$(Ta - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index 10aa86ad1..8bb33d007 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -7,6 +7,7 @@ using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Html; +using Tango.MachineStudio.Common.JobRunsLogging; using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; @@ -68,6 +69,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); @@ -75,6 +77,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); @@ -83,6 +86,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(new TeamFoundationServiceExtendedClient("https://twinetfs.visualstudio.com", String.Empty, "szzfokrceo4rhd4eqi5qpmxn3pa5iwl3q7tlqd36l2m7smz2ynoa")); + TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/Tango.BL/Builders/JobBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/JobBuilder.cs index a0a88f4a7..d8d58d69b 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/JobBuilder.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/JobBuilder.cs @@ -77,5 +77,13 @@ namespace Tango.BL.Builders new UserBuilder(Context).Set(Entity.UserGuid).Build(); }); } + + public virtual JobBuilder WithJobRuns() + { + return AddStep(6, () => + { + Context.JobRuns.Where(x => x.JobGuid == Entity.Guid).OrderBy(x => x.StartDate).ToList(); + }); + } } } diff --git a/Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs new file mode 100644 index 000000000..0a02c6a23 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/JobRunsBuilder.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class JobRunsBuilder : EntityBuilderBase + { + public JobRunsBuilder(ObservablesContext context) : base(context) + { + + } + + protected override IQueryable OnSetQuery(IQueryable query) + { + return query.Include(x => x.Job); + } + + public virtual JobRunsBuilder WithJobEvents() + { + return AddStep(2, () => + { + Context.MachinesEvents.Where(x => x.MachineGuid == Entity.Job.MachineGuid && x.DateTime >= Entity.StartDate && x.DateTime <= Entity.EndDate).OrderBy(x => x.DateTime).ToList(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs index b4ecf4f5a..6e953f5ce 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/JobRun.cs @@ -21,6 +21,11 @@ using Tango.Core; namespace Tango.BL.Entities { + + /// + /// + /// + [Table("JOB_RUNS")] public partial class JobRun : ObservableEntity { @@ -29,7 +34,9 @@ namespace Tango.BL.Entities public event EventHandler EndDateChanged; - public event EventHandler SuccessfulChanged; + public event EventHandler StatusChanged; + + public event EventHandler FailedMessageChanged; public event EventHandler JobChanged; @@ -115,30 +122,60 @@ namespace Tango.BL.Entities } } - protected Boolean _successful; + protected Int32 _status; + + /// + /// 0 = COMPLETED + /// 1 = ABORTED + /// 2 = FAILED + /// + + [Column("STATUS")] + + public Int32 Status + { + get + { + return _status; + } + + set + { + if (_status != value) + { + _status = value; + + StatusChanged?.Invoke(this, value); + + RaisePropertyChanged(nameof(Status)); + } + } + } + + protected String _failedmessage; /// - /// Gets or sets the jobrun successful. + /// Gets or sets the jobrun failed message. /// - [Column("SUCCESSFUL")] + [Column("FAILED_MESSAGE")] - public Boolean Successful + public String FailedMessage { get { - return _successful; + return _failedmessage; } set { - if (_successful != value) + if (_failedmessage != value) { - _successful = value; + _failedmessage = value; - SuccessfulChanged?.Invoke(this, value); + FailedMessageChanged?.Invoke(this, value); - RaisePropertyChanged(nameof(Successful)); + RaisePropertyChanged(nameof(FailedMessage)); } } } diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/JobRun.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/JobRun.cs new file mode 100644 index 000000000..555857f53 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/JobRun.cs @@ -0,0 +1,32 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Enumerations; + +namespace Tango.BL.Entities +{ + public partial class JobRun + { + [NotMapped] + [JsonIgnore] + public JobRunStatus JobRunStatus + { + get { return (JobRunStatus)Status; } + set { Status = (int)value; } + } + + protected override void RaisePropertyChanged(string propName) + { + base.RaisePropertyChanged(propName); + + if (propName == nameof(Status)) + { + RaisePropertyChanged(nameof(JobRunStatus)); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Enumerations/JobRunStatus.cs b/Software/Visual_Studio/Tango.BL/Enumerations/JobRunStatus.cs new file mode 100644 index 000000000..5abc98073 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Enumerations/JobRunStatus.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.BL.Enumerations +{ + public enum JobRunStatus + { + Completed, + Aborted, + Failed, + } +} diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index cf95ea9bc..b8cc1b1e3 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -89,6 +89,7 @@ + @@ -112,6 +113,7 @@ + @@ -154,6 +156,7 @@ + @@ -345,7 +348,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs index bb93a87c2..9e5cf6049 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/JOB_RUNS.cs @@ -20,7 +20,8 @@ namespace Tango.DAL.Remote.DB public string JOB_GUID { get; set; } public System.DateTime START_DATE { get; set; } public System.DateTime END_DATE { get; set; } - public bool SUCCESSFUL { get; set; } + public int STATUS { get; set; } + public string FAILED_MESSAGE { get; set; } public virtual JOB JOB { 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 46591fb34..1fbc101b3 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -589,7 +589,8 @@ - + + @@ -3658,7 +3659,8 @@ - + + @@ -5935,7 +5937,8 @@ - + + 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 8667820a2..8a1e6296e 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,81 +5,81 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.3.1