diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-20 13:27:36 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-11-20 13:27:36 +0200 |
| commit | c272cdaaa43f7bf2fefcb36bbfe49624fc4a5ff1 (patch) | |
| tree | bcc9ccd584d7cc706f6453e7a906fa3f1485ef53 /Software/Visual_Studio/MachineStudio | |
| parent | fa8459be63d8f76059d1e71ab86c01e0a13851b5 (diff) | |
| download | Tango-c272cdaaa43f7bf2fefcb36bbfe49624fc4a5ff1.tar.gz Tango-c272cdaaa43f7bf2fefcb36bbfe49624fc4a5ff1.zip | |
Added job runs logger to machine studio.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
7 files changed, 151 insertions, 4 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 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<Window> _openedWindows; private List<IStudioViewModel> _notified_view_models; /// <summary> + /// Occurs when the application is ready. + /// </summary> + public event EventHandler ApplicationReady; + + /// <summary> /// Initializes a new instance of the <see cref="DefaultStudioApplicationManager" /> class. /// </summary> /// <param name="navigationManager">The navigation manager.</param> - 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 /// </summary> public void NotifyApplicationReady() { - TangoIOC.Default.GetAllInstancesByBase<IStudioViewModel>().ToList().ForEach(x => + TangoIOC.Default.GetAllInstancesByBase<IStudioViewModel>().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); } /// <summary> @@ -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 </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.DeltaBaseYearDayOfYear" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_BuildVersioningStyle="None.None.Increment.DeltaBaseYearDayOfYear" BuildVersion_UpdateFileVersion="True" BuildVersion_DetectChanges="True" BuildVersion_UseGlobalSettings="False" /> </VisualStudio> </ProjectExtensions> </Project>
\ 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<IHtmlPresenter>(); TangoIOC.Default.Unregister<ITeamFoundationServiceClient>(); TangoIOC.Default.Unregister<IDispatcherProvider>(); + TangoIOC.Default.Unregister<IJobRunsLogger>(); TangoIOC.Default.Register<IDispatcherProvider, DefaultDispatcherProvider>(new DefaultDispatcherProvider(Application.Current.Dispatcher)); @@ -75,6 +77,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Register<IAuthenticationProvider, DefaultAuthenticationProvider>(); TangoIOC.Default.Register<INavigationManager, DefaultNavigationManager>(); TangoIOC.Default.Register<IStudioModuleLoader, DefaultStudioModuleLoader>(); + TangoIOC.Default.Register<IJobRunsLogger, DefaultJobRunsLogger>(); TangoIOC.Default.Register<IStudioApplicationManager, DefaultStudioApplicationManager>(); TangoIOC.Default.Register<ExternalBridgeScanner, ExternalBridgeScanner>(); TangoIOC.Default.Register<IVideoCaptureProvider, DefaultVideoCaptureProvider>(); @@ -83,6 +86,7 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Register<ISpeechProvider, DefaultSpeechProvider>(); TangoIOC.Default.Register<IHtmlPresenter, DefaultHtmlPresenter>(); TangoIOC.Default.Register<TeamFoundationServiceExtendedClient>(new TeamFoundationServiceExtendedClient("https://twinetfs.visualstudio.com", String.Empty, "szzfokrceo4rhd4eqi5qpmxn3pa5iwl3q7tlqd36l2m7smz2ynoa")); + TangoIOC.Default.Register<MainViewVM>(); TangoIOC.Default.Register<LoadingViewVM>(); |
