From 9c0bad738d47742f39f2b02b240591653da6bc12 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 12 Apr 2018 12:47:19 +0300 Subject: Added changes to PMR hardware. Implemented Start Job and Record. Fixed issue with logs timeline event width. Implemented 'Event Resolved' event to event logs. --- .../ViewModels/MainViewVM.cs | 40 +++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index cdfeee54d..036b01e34 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -35,6 +35,7 @@ using System.Speech.Synthesis; using System.Media; using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Speech; +using Microsoft.Practices.ServiceLocation; namespace Tango.MachineStudio.Developer.ViewModels { @@ -58,6 +59,8 @@ namespace Tango.MachineStudio.Developer.ViewModels private ObservablesContext _activeJobDbContext; private IEventLogger _eventLogger; private ISpeechProvider _speech; + private DataCapture.ViewModels.MainViewVM _dataCaptureVM; + private bool _isRecording; #region Properties @@ -555,6 +558,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public RelayCommand StartJobCommand { get; set; } + /// + /// Gets or sets the start job and record command. + /// + public RelayCommand StartJobAndRecordCommand { get; set; } + /// /// Gets or sets the stop job command. /// @@ -642,6 +650,9 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Initializing relay commands..."); + _dataCaptureVM = ServiceLocator.Current.GetInstance(); + _dataCaptureVM.RelayCommandsInvalidated += (_, __) => StartJobAndRecordCommand.RaiseCanExecuteChanged(); + //Initialize Commands... EditMachineCommand = new RelayCommand(EditMachine, () => SelectedMachine != null); EditRMLCommand = new RelayCommand(EditRML, () => SelectedRML != null); @@ -656,6 +667,7 @@ namespace Tango.MachineStudio.Developer.ViewModels SaveJobCommand = new RelayCommand(SaveActiveJob, () => SelectedMachine != null); DiscardJobCommand = new RelayCommand(BackToJobs, () => SelectedMachine != null); StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); + StartJobAndRecordCommand = new RelayCommand(StartJobAndRecord, () => !_dataCaptureVM.Recorder.IsRecording && !_dataCaptureVM.Player.IsPlaying && ActiveJob != null && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); LoadJobCommand = new RelayCommand(LoadSelectedJob, () => SelectedMachineJob != null); @@ -1053,7 +1065,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (segment.ID != -1) { _speech.SpeakInfo(String.Format("Segment {0} Started.", segment.SegmentIndex)); - _eventLogger.Log(String.Format("Segment {0} Started.", segment.SegmentIndex)); + _eventLogger.Log(String.Format("Segment {0} Started.", segment.SegmentIndex) + Environment.NewLine + segment.ToJsonString()); } else { @@ -1081,6 +1093,7 @@ namespace Tango.MachineStudio.Developer.ViewModels InvokeUI(() => { _notification.ShowError("Job failed. " + ex.Message); + StopRecordingIfInProgress(); }); }; @@ -1089,12 +1102,14 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log(String.Format("Job {0} has completed.", RunningJob.Name)); _eventLogger.Log(String.Format("Job {0} has completed.", RunningJob.Name)); SetJobCompleted(); + StopRecordingIfInProgress(); }; _jobHandler.Canceled += (x, y) => { LogManager.Log(String.Format("Job {0} has been canceled.", RunningJob.Name)); _eventLogger.Log(String.Format("Job {0} has been canceled.", RunningJob.Name)); + StopRecordingIfInProgress(); //Finally Canceled.. }; } @@ -1104,6 +1119,29 @@ namespace Tango.MachineStudio.Developer.ViewModels _eventLogger.Log(ex, "An error occurred while starting the job."); _notification.ShowError("An error occurred while starting the job. " + Environment.NewLine + ex.Message); SetJobFailed(); + StopRecordingIfInProgress(); + } + } + + /// + /// Starts the job and record using the data capture module. + /// + private void StartJobAndRecord() + { + _isRecording = true; + _dataCaptureVM.StartDiagnosticsRecording(); + StartJob(); + } + + /// + /// Stops the recording if in progress. + /// + private void StopRecordingIfInProgress() + { + if (_isRecording) + { + _isRecording = false; + InvokeUI(() => _dataCaptureVM.StopRecorderOrPlayer()); } } -- cgit v1.3.1