diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels')
5 files changed, 118 insertions, 55 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs index 264f41131..3e8c6f280 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs @@ -4,12 +4,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Entities; +using Tango.Core.Commands; using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Navigation; using Tango.PPC.Jobs.AppBarItems; using Tango.PPC.Jobs.AppButtons; using Tango.PPC.Jobs.Dialogs; +using Tango.PPC.Jobs.NavigationObjects; using Tango.PPC.Jobs.Views; namespace Tango.PPC.Jobs.ViewModels @@ -47,10 +49,24 @@ namespace Tango.PPC.Jobs.ViewModels #endregion + #region Commands + + /// <summary> + /// Gets or sets the go to job command. + /// </summary> + /// <value> + /// The go to job command. + /// </value> + public RelayCommand GoToJobCommand { get; set; } + + #endregion + public JobProgressViewVM() { _stop_job_btn = new StopPrintingButton(); _stop_job_btn.Pressed += _stop_job_btn_Pressed; + + GoToJobCommand = new RelayCommand(GoToJob); } private void _stop_job_btn_Pressed() @@ -61,6 +77,12 @@ namespace Tango.PPC.Jobs.ViewModels } } + private void GoToJob() + { + NavigationManager.NavigateWithObject<JobsModule, JobView, JobNavigationObject>(new JobNavigationObject() { Job = _handler.Job }); + NavigationManager.ClearHistoryExcept<JobsView>(); + } + #region Override Methods /// <summary> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs index cd7308afb..1a980fc4a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs @@ -9,7 +9,9 @@ using Tango.BL.Entities; using Tango.Core.Commands; using Tango.PPC.Common; using Tango.PPC.Common.Messages; +using Tango.PPC.Common.Navigation; using Tango.PPC.Jobs.Messages; +using Tango.PPC.Jobs.NavigationObjects; using Tango.PPC.Jobs.Views; namespace Tango.PPC.Jobs.ViewModels @@ -18,7 +20,7 @@ namespace Tango.PPC.Jobs.ViewModels /// Represents the job summary view model. /// </summary> /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> - public class JobSummeryViewVM : PPCViewModel + public class JobSummeryViewVM : PPCViewModel, INavigationObjectReceiver<JobSummeryNavigationObject> { private ObservablesContext _context; @@ -59,38 +61,11 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> public JobSummeryViewVM() { - RegisterForMessage<JobSelectedMessage>(HandleJobSelectedMessage); - DyeCommand = new RelayCommand(StartJob); EditCommand = new RelayCommand(EditJob); } /// <summary> - /// Handles the job selected message. - /// </summary> - /// <param name="message">The message.</param> - private async void HandleJobSelectedMessage(JobSelectedMessage message) - { - _context = message.Context; - Job = message.Job; - - Job = await new JobBuilder(_context).Set(Job.Guid) - .WithConfiguration() - .WithRML() - .WithUser() - .WithSegments() - .WithBrushStops() - .BuildAsync(); - - - try - { - EstimatedDuration = await Job.GetEstimatedDuration(); - } - catch { } - } - - /// <summary> /// Edits the job. /// </summary> private void EditJob() @@ -108,7 +83,7 @@ namespace Tango.PPC.Jobs.ViewModels { LogManager.Log("Start job command pressed. Starting job and navigating to job progress view..."); - PrintingManager.Print(Job, _context); + await PrintingManager.Print(Job, _context); await NavigationManager.NavigateTo<JobsModule>(false, nameof(JobProgressView)); } catch (Exception ex) @@ -125,5 +100,26 @@ namespace Tango.PPC.Jobs.ViewModels { } + + public async void OnNavigatedToWithObject(JobSummeryNavigationObject obj) + { + _context = obj.Context; + Job = obj.Job; + + Job = await new JobBuilder(_context).Set(Job.Guid) + .WithConfiguration() + .WithRML() + .WithUser() + .WithSegments() + .WithBrushStops() + .BuildAsync(); + + + try + { + EstimatedDuration = await Job.GetEstimatedDuration(); + } + catch { } + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs index f0cf87079..c7946ee6a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs @@ -396,7 +396,8 @@ namespace Tango.PPC.Jobs.ViewModels { LogManager.Log($"Loading selected job '{_job_to_load.Name}'..."); - NotificationProvider.SetGlobalBusyMessage("Loading job details..."); + //NotificationProvider.SetGlobalBusyMessage("Loading job details..."); + IsFree = false; _can_navigate_back = false; @@ -433,10 +434,6 @@ namespace Tango.PPC.Jobs.ViewModels SegmentsCollectionView = CollectionViewSource.GetDefaultView(Job.Segments); SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); - InvokeUIOnIdle(() => - { - NotificationProvider.ReleaseGlobalBusyMessage(); - }); _job_to_load = null; } @@ -471,10 +468,16 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log(ex, $"Error loading job '{_job_to_load.Name}'"); await NotificationProvider.ShowError("An error occurred while trying to load the selected job."); } + finally + { + InvokeUIOnIdle(() => + { + IsFree = true; + //NotificationProvider.ReleaseGlobalBusyMessage(); + }); + } } - - /// <summary> /// Saves the job. /// </summary> @@ -545,18 +548,18 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Starts the job. /// </summary> - private void StartJob() + private async void StartJob() { try { LogManager.Log("Start job command pressed. Starting job and navigating to job progress view..."); - PrintingManager.Print(Job, _db); - NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); + await PrintingManager.Print(Job, _db); + await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); } catch (Exception ex) { LogManager.Log(ex, "Could not start the current job."); - NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}."); + await NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}."); } } @@ -764,8 +767,11 @@ namespace Tango.PPC.Jobs.ViewModels /// <param name="brushStop">The brush stop.</param> public void OnBrushStopFieldValueChanged(BrushStop brushStop) { - brushStop.Corrected = false; - brushStop.OutOfGamutChecked = false; + if (brushStop != null) + { + brushStop.Corrected = false; + brushStop.OutOfGamutChecked = false; + } } /// <summary> @@ -802,20 +808,20 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Starts a sample dye. /// </summary> - private void StartSampleDye() + private async void StartSampleDye() { try { LogManager.Log("Sample dye command pressed..."); - PrintingManager.PrintSample(Job, _db); + await PrintingManager.PrintSample(Job, _db); - NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); + await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); } catch (Exception ex) { LogManager.Log(ex, $"Error executing sample dye for job {Job.Name}."); - NotificationProvider.ShowError("An error occurred while trying to execute the sample dye."); + await NotificationProvider.ShowError("An error occurred while trying to execute the sample dye."); } } @@ -940,7 +946,7 @@ namespace Tango.PPC.Jobs.ViewModels /// <summary> /// Starts the fine tuning. /// </summary> - private void StartFineTuning() + private async void StartFineTuning() { try { @@ -948,14 +954,14 @@ namespace Tango.PPC.Jobs.ViewModels _jobs_fine_tune_items[Job.Guid] = FineTuneItems.ToList(); - PrintingManager.PrintFineTuning(Job, _db, FineTuneItems); + await PrintingManager.PrintFineTuning(Job, _db, FineTuneItems); - NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); + await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); } catch (Exception ex) { LogManager.Log(ex, "Error executing fine tuning job."); - NotificationProvider.ShowError("An error occurred while trying to start the fine tuning job."); + await NotificationProvider.ShowError("An error occurred while trying to start the fine tuning job."); } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index aef6dd549..86c53440e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -272,15 +272,20 @@ namespace Tango.PPC.Jobs.ViewModels { LogManager.Log($"Job '{job.Name}' selected."); + RaiseMessage(new JobSelectedMessage() { Job = job, Context = _db }); + if (!directlyToEdit && MachineProvider.MachineOperator.Status == Integration.Operation.MachineStatuses.ReadyToDye) { - await NavigationManager.NavigateTo<JobsModule>(nameof(JobSummeryView)); + await NavigationManager.NavigateWithObject<JobsModule, JobSummeryView, JobSummeryNavigationObject>(new JobSummeryNavigationObject() + { + Context = _db, + Job = job, + }); } else { await NavigationManager.NavigateTo<JobsModule>(nameof(JobView)); } - RaiseMessage(new JobSelectedMessage() { Job = job, Context = _db }); } /// <summary> @@ -307,7 +312,7 @@ namespace Tango.PPC.Jobs.ViewModels Jobs = jobs; DraftJobsCollectionView = new ListCollectionView(Jobs); DraftJobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - DraftJobsCollectionView.Filter = new Predicate<object>(x => + DraftJobsCollectionView.Filter = new Predicate<object>(x => { var job = x as Job; @@ -324,7 +329,7 @@ namespace Tango.PPC.Jobs.ViewModels HistoryJobsCollectionView = new ListCollectionView(Jobs); HistoryJobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); - HistoryJobsCollectionView.Filter = new Predicate<object>(x => + HistoryJobsCollectionView.Filter = new Predicate<object>(x => { var job = x as Job; @@ -427,7 +432,7 @@ namespace Tango.PPC.Jobs.ViewModels job.RmlGuid = machine.DefaultRml != null ? machine.DefaultRmlGuid : Adapter.Rmls.FirstOrDefault().Guid; job.WindingMethodGuid = Adapter.WindingMethods.FirstOrDefault().Guid; job.SpoolTypeGuid = machine.DefaultSpoolType != null ? machine.DefaultSpoolTypeGuid : Adapter.SpoolTypes.FirstOrDefault().Guid; - + if (Jobs.Count > 0) { job.JobIndex = Jobs.Max(x => x.JobIndex) + 1; diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs index 7026a6ebc..d72f4544a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Builders; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Integration.Operation; @@ -28,6 +30,38 @@ namespace Tango.PPC.Jobs.ViewModels { MachineProvider.MachineOperator.PrintingCompleted += MachineOperator_PrintingCompleted; MachineProvider.MachineOperator.PrintingFailed += MachineOperator_PrintingFailed; + MachineProvider.MachineOperator.ResumingJob += MachineOperator_ResumingJob; + } + + private async void MachineOperator_ResumingJob(object sender, ResumingJobEventArgs e) + { + LogManager.Log($"Trying to resume job '{e.JobGuid}'..."); + + try + { + var job = await new JobBuilder(ObservablesContext.CreateDefault()).Set(e.JobGuid) + .WithConfiguration() + .WithRML() + .WithUser() + .WithSegments() + .WithBrushStops() + .BuildAsync(); + + e.Approve(job); + + InvokeUI(() => + { + NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "An error occurred while trying to resume the job."); + InvokeUI(() => + { + NotificationProvider.ShowError("An error occurred while trying to resume a job in progress."); + }); + } } /// <summary> |
