diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-04-16 09:27:48 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-04-16 09:27:48 +0300 |
| commit | eafb576fe1bf76898b9cc17671a89d1585e2c8e4 (patch) | |
| tree | d833a983eb84c53b35b19a45af475aa3e88953c0 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels | |
| parent | cf441513c1010eb4363e985b3b7af61a8503456e (diff) | |
| parent | 53f93d7fd2d2aa4571bad6e93e0c519fce242753 (diff) | |
| download | Tango-eafb576fe1bf76898b9cc17671a89d1585e2c8e4.tar.gz Tango-eafb576fe1bf76898b9cc17671a89d1585e2c8e4.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 40 |
1 files changed, 39 insertions, 1 deletions
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 @@ -556,6 +559,11 @@ namespace Tango.MachineStudio.Developer.ViewModels public RelayCommand StartJobCommand { get; set; } /// <summary> + /// Gets or sets the start job and record command. + /// </summary> + public RelayCommand StartJobAndRecordCommand { get; set; } + + /// <summary> /// Gets or sets the stop job command. /// </summary> public RelayCommand StopJobCommand { get; set; } @@ -642,6 +650,9 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Initializing relay commands..."); + _dataCaptureVM = ServiceLocator.Current.GetInstance<DataCapture.ViewModels.MainViewVM>(); + _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(); + } + } + + /// <summary> + /// Starts the job and record using the data capture module. + /// </summary> + private void StartJobAndRecord() + { + _isRecording = true; + _dataCaptureVM.StartDiagnosticsRecording(); + StartJob(); + } + + /// <summary> + /// Stops the recording if in progress. + /// </summary> + private void StopRecordingIfInProgress() + { + if (_isRecording) + { + _isRecording = false; + InvokeUI(() => _dataCaptureVM.StopRecorderOrPlayer()); } } |
