diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs | 66 |
1 files changed, 15 insertions, 51 deletions
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 579e1e2f7..ed1e28f55 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 @@ -11,7 +11,6 @@ using Tango.Integration.Operation; using Tango.PPC.Common; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Notifications.NotificationItems; -using Tango.PPC.Jobs.AppBarItems; using Tango.PPC.Jobs.Messages; using Tango.PPC.Jobs.NavigationObjects; using Tango.PPC.Jobs.Views; @@ -25,9 +24,6 @@ namespace Tango.PPC.Jobs.ViewModels public class MainViewVM : PPCViewModel { private NotificationItem _last_failed_job_notification; - private JobHandler _handler; - private bool resuming; - private JobProgressAppBarItem _appBarItem; /// <summary> /// Called when the application has been started. @@ -37,42 +33,23 @@ namespace Tango.PPC.Jobs.ViewModels MachineProvider.MachineOperator.PrintingCompleted += MachineOperator_PrintingCompleted; MachineProvider.MachineOperator.PrintingFailed += MachineOperator_PrintingFailed; MachineProvider.MachineOperator.ResumingJob += MachineOperator_ResumingJob; - MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; - MachineProvider.MachineOperator.PrintingEnded += MachineOperator_PrintingEnded; - NavigationManager.CurrentVMChanged += NavigationManager_CurrentVMChanged; } - private void MachineOperator_PrintingEnded(object sender, PrintingEventArgs e) + private async void MachineOperator_ResumingJob(object sender, ResumingJobEventArgs e) { - _appBarItem?.Close(); - _appBarItem = null; - } + LogManager.Log($"Trying to resume job '{e.JobGuid}'..."); - private void NavigationManager_CurrentVMChanged(object sender, PPCViewModel vm) - { - if (vm.GetType() == typeof(JobProgressViewVM)) - { - _appBarItem?.Close(); - _appBarItem = null; - } - else if (vm.GetType() != typeof(JobSummeryViewVM) && _appBarItem == null && MachineProvider.MachineOperator.IsPrinting && _handler != null && !_handler.IsCanceled) + try { - _appBarItem = NotificationProvider.PushAppBarItem<JobProgressAppBarItem>(); - _appBarItem.Pressed += (_, __) => - { - _appBarItem?.Close(); - NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView)); - }; - } - } + var job = await new JobBuilder(ObservablesContext.CreateDefault()).Set(e.JobGuid) + .WithConfiguration() + .WithRML() + .WithUser() + .WithSegments() + .WithBrushStops() + .BuildAsync(); - private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e) - { - _handler = e.JobHandler; - - if (resuming) - { - resuming = false; + e.Approve(job); InvokeUI(() => { @@ -85,17 +62,6 @@ namespace Tango.PPC.Jobs.ViewModels } }); } - } - - private void MachineOperator_ResumingJob(object sender, ResumingJobEventArgs e) - { - LogManager.Log($"Job resume request '{e.JobGuid}' approving..."); - - try - { - e.Approve(); - resuming = true; - } catch (Exception ex) { LogManager.Log(ex, "An error occurred while trying to resume the job."); @@ -113,15 +79,13 @@ namespace Tango.PPC.Jobs.ViewModels /// <param name="e">The <see cref="Integration.Operation.PrintingFailedEventArgs"/> instance containing the event data.</param> private void MachineOperator_PrintingFailed(object sender, PrintingFailedEventArgs e) { - String message = $"{e.Exception.FlattenMessage()}"; - _last_failed_job_notification = NotificationProvider.PushNotification(new MessageNotificationItem( - $"'{e.Job.Name}' failed at position {e.JobHandler.Status.ProgressMinusSettingUp.ToString("0.0")} out of {e.JobHandler.Status.TotalProgressMinusSettingUp.ToString("0.0")} meters.", - message, MessageNotificationItem.MessageNotificationItemTypes.Error, () => + String.Format("'{0}' failed.", e.Job.Name), + String.Format("The job '{1}' has failed due to unexpected error.{0}{2}{0}{0}Tap to view this job details.", Environment.NewLine, e.Job.Name, e.Exception), MessageNotificationItem.MessageNotificationItemTypes.Error, () => { NavigationManager.NavigateWithObject<JobsModule, JobView, Job>(e.Job); NavigationManager.ClearHistoryExcept<JobsView>(); - }, NotificationItem.NotificationPriority.VeryHigh)); + })); } /// <summary> @@ -155,7 +119,7 @@ namespace Tango.PPC.Jobs.ViewModels { NavigationManager.NavigateWithObject<JobsModule, JobView, JobNavigationObject>(new JobNavigationObject() { Job = e.Job }); NavigationManager.ClearHistoryExcept<JobsView>(); - }, NotificationItem.NotificationPriority.VeryHigh)); + })); } } |
