aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs26
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs61
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs106
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs46
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs51
5 files changed, 226 insertions, 64 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..103a10b28 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>
@@ -78,7 +100,7 @@ namespace Tango.PPC.Jobs.ViewModels
{
base.OnNavigatedFrom();
- if (MachineProvider.MachineOperator.IsPrinting)
+ if (MachineProvider.MachineOperator.IsPrinting && _handler != null && !_handler.IsCanceled)
{
NotificationProvider.PushAppBarItem<JobProgressAppBarItem>().Pressed += (_, __) =>
{
@@ -119,6 +141,8 @@ namespace Tango.PPC.Jobs.ViewModels
e.JobHandler.StatusChanged += JobHandler_StatusChanged;
e.JobHandler.SpoolChangeRequired += JobHandler_SpoolChangeRequired;
e.JobHandler.Stopped += JobHandler_Stopped;
+
+ _stop_job_btn.Push();
}
/// <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 46c6d7ffd..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;
@@ -32,6 +34,18 @@ namespace Tango.PPC.Jobs.ViewModels
set { _job = value; RaisePropertyChangedAuto(); }
}
+ private TimeSpan _estimatedDuration;
+ /// <summary>
+ /// Gets or sets the duration of the estimated.
+ /// </summary>
+
+ public TimeSpan EstimatedDuration
+ {
+ get { return _estimatedDuration; }
+ set { _estimatedDuration = value; RaisePropertyChangedAuto(); }
+ }
+
+
/// <summary>
/// Gets or sets the dye command.
/// </summary>
@@ -47,23 +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 void HandleJobSelectedMessage(JobSelectedMessage message)
- {
- _context = message.Context;
- Job = message.Job;
- }
-
- /// <summary>
/// Edits the job.
/// </summary>
private void EditJob()
@@ -81,16 +83,8 @@ namespace Tango.PPC.Jobs.ViewModels
{
LogManager.Log("Start job command pressed. Starting job and navigating to job progress view...");
- Job = await new JobBuilder(_context).Set(Job.Guid)
- .WithConfiguration()
- .WithRML()
- .WithUser()
- .WithSegments()
- .WithBrushStops()
- .BuildAsync();
-
- PrintingManager.Print(Job, _context);
- await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView));
+ await PrintingManager.Print(Job, _context);
+ await NavigationManager.NavigateTo<JobsModule>(false, nameof(JobProgressView));
}
catch (Exception ex)
{
@@ -106,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..713dfce42 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
@@ -31,6 +31,9 @@ using Tango.Logging;
using Tango.PPC.Common.Messages;
using Tango.BL.Builders;
using Tango.PPC.Jobs.AppButtons;
+using Tango.Core.Threading;
+using System.Diagnostics;
+using System.Runtime.ExceptionServices;
namespace Tango.PPC.Jobs.ViewModels
{
@@ -47,6 +50,7 @@ namespace Tango.PPC.Jobs.ViewModels
private JobNavigationIntent _job_to_load_intent;
private static Dictionary<String, List<FineTuneItem>> _jobs_fine_tune_items;
private StartPrintingButton _start_printing_btn;
+ private ActionTimer _volumeConversionTimer;
#region Properties
@@ -319,6 +323,8 @@ namespace Tango.PPC.Jobs.ViewModels
/// </summary>
public JobViewVM()
{
+ _volumeConversionTimer = new ActionTimer(TimeSpan.FromMilliseconds(50));
+
RegisterForMessage<JobSelectedMessage>(HandleJobSelectedMessage);
FineTuneItems = new ObservableCollection<FineTuneItem>();
@@ -396,7 +402,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;
@@ -425,6 +432,11 @@ namespace Tango.PPC.Jobs.ViewModels
Customers = await _db.Customers.Where(x => x.OrganizationGuid == MachineProvider.Machine.OrganizationGuid).ToListAsync();
TwineCatalogItems = await _db.ColorCatalogs.Where(x => x.RmlGuid == Job.Rml.Guid && x.ColorSpace.Code == (int)BL.Enumerations.ColorSpaces.Twine).OrderBy(x => x.Name).ToListAsync();
+ foreach (var segment in Job.Segments)
+ {
+ SetSegmentLiquidVolumesIfVolume(segment);
+ }
+
if (!_check_gamut_thread.IsAlive)
{
_check_gamut_thread.Start();
@@ -433,10 +445,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 +479,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 +559,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}.");
}
}
@@ -598,7 +612,9 @@ namespace Tango.PPC.Jobs.ViewModels
try
{
LogManager.Log("Adding new solid segment...");
- return Job.AddSolidSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10);
+ var s = Job.AddSolidSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10);
+ SetSegmentLiquidVolumesIfVolume(s);
+ return s;
}
catch (Exception ex)
{
@@ -616,7 +632,9 @@ namespace Tango.PPC.Jobs.ViewModels
try
{
LogManager.Log("Adding new gradient segment...");
- return Job.AddGradientSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10);
+ var s = Job.AddGradientSegment(MachineProvider.Machine.DefaultSegmentLength > 0 ? MachineProvider.Machine.DefaultSegmentLength : 10);
+ SetSegmentLiquidVolumesIfVolume(s);
+ return s;
}
catch (Exception ex)
{
@@ -680,6 +698,18 @@ namespace Tango.PPC.Jobs.ViewModels
}
}
+ /// <summary>
+ /// Sets the segment liquid volumes.
+ /// </summary>
+ /// <param name="segment">The segment.</param>
+ private void SetSegmentLiquidVolumesIfVolume(Segment segment)
+ {
+ if (Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.Volume.ToInt32())
+ {
+ segment.BrushStops.ToList().ForEach(x => x.SetLiquidVolumes(Job.Machine.Configuration, Job.Rml, Job.Rml.GetActiveProcessGroup().ProcessParametersTables.FirstOrDefault()));
+ }
+ }
+
#endregion
#region Brush Stops Management
@@ -692,6 +722,7 @@ namespace Tango.PPC.Jobs.ViewModels
{
LogManager.Log($"Adding new brush stop to segment {segment.SegmentIndex}.");
segment.AddBrushStop();
+ SetSegmentLiquidVolumesIfVolume(segment);
}
/// <summary>
@@ -761,11 +792,36 @@ namespace Tango.PPC.Jobs.ViewModels
/// <summary>
/// Called when the brush stop field value has been changed (This called from the view!).
/// </summary>
- /// <param name="brushStop">The brush stop.</param>
- public void OnBrushStopFieldValueChanged(BrushStop brushStop)
+ /// <param name="stop">The brush stop.</param>
+ [HandleProcessCorruptedStateExceptions]
+ public void OnBrushStopFieldValueChanged(BrushStop stop)
{
- brushStop.Corrected = false;
- brushStop.OutOfGamutChecked = false;
+ if (stop != null)
+ {
+ stop.Corrected = false;
+ stop.OutOfGamutChecked = false;
+
+ if (stop.BrushColorSpace == BL.Enumerations.ColorSpaces.Volume)
+ {
+ _volumeConversionTimer.ResetReplace(() =>
+ {
+ try
+ {
+ var output = TangoColorConverter.GetSuggestions(stop);
+
+ stop.Red = output.SingleCoordinates.Red;
+ stop.Green = output.SingleCoordinates.Green;
+ stop.Blue = output.SingleCoordinates.Blue;
+ stop.Corrected = true;
+ stop.IsOutOfGamut = false;
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "An error occurred while trying to get volume => RGB from conversion engine.");
+ }
+ });
+ }
+ }
}
/// <summary>
@@ -802,20 +858,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 +996,7 @@ namespace Tango.PPC.Jobs.ViewModels
/// <summary>
/// Starts the fine tuning.
/// </summary>
- private void StartFineTuning()
+ private async void StartFineTuning()
{
try
{
@@ -948,14 +1004,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 d29323412..bd6f95d44 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
@@ -225,6 +225,7 @@ namespace Tango.PPC.Jobs.ViewModels
RegisterForMessage<JobRemovedMessage>(HandleJobRemovedMessage);
RegisterForMessage<JobSavedMessage>(HandleJobSavedMessage);
+ RegisterForMessage<NavigatedToJobsModuleMessage>((x) => Filter = null);
}
#endregion
@@ -271,15 +272,20 @@ namespace Tango.PPC.Jobs.ViewModels
{
LogManager.Log($"Job '{job.Name}' selected.");
- if (!directlyToEdit)
+ 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>
@@ -306,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;
@@ -323,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;
@@ -372,7 +378,7 @@ namespace Tango.PPC.Jobs.ViewModels
JobCreationViewVM vm = new JobCreationViewVM(
machine.SupportedJobTypes.Count > 0 ? machine.SupportedJobTypes : Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().ToList(),
- machine.SupportedColorSpaces.Count > 0 ? machine.SupportedColorSpaces : Enum.GetValues(typeof(ColorSpaces)).Cast<ColorSpaces>().Where(x => x.IsUserSpace()).ToList()
+ machine.SupportedColorSpaces.Count > 0 ? machine.SupportedColorSpaces : Enum.GetValues(typeof(ColorSpaces)).Cast<ColorSpaces>().Where(x => x.IsUserSpace() || (ApplicationManager.IsInTechnicianMode && x == ColorSpaces.Volume)).ToList()
);
var settings = SettingsManager.Default.GetOrCreate<JobsModuleSettings>();
@@ -419,13 +425,14 @@ namespace Tango.PPC.Jobs.ViewModels
job.CreationDate = DateTime.UtcNow;
job.JobStatus = JobStatuses.Draft;
job.JobType = vm.SelectedJobType;
+ job.EnableLubrication = true;
job.ColorSpaceGuid = Adapter.ColorSpaces.FirstOrDefault(x => x.Code == vm.SelectedColorSpace.ToInt32()).Guid;
job.MachineGuid = MachineProvider.Machine.Guid;
job.UserGuid = AuthenticationProvider.CurrentUser.Guid;
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;
@@ -529,13 +536,16 @@ namespace Tango.PPC.Jobs.ViewModels
/// </summary>
private void OnFilterChanged()
{
- if (SelectedCategory == JobsCategory.Draft)
- {
- DraftJobsCollectionView.Refresh();
- }
- else if (SelectedCategory == JobsCategory.History)
+ if (DraftJobsCollectionView != null && HistoryJobsCollectionView != null)
{
- HistoryJobsCollectionView.Refresh();
+ if (SelectedCategory == JobsCategory.Draft)
+ {
+ DraftJobsCollectionView.Refresh();
+ }
+ else if (SelectedCategory == JobsCategory.History)
+ {
+ HistoryJobsCollectionView.Refresh();
+ }
}
}
@@ -590,13 +600,21 @@ namespace Tango.PPC.Jobs.ViewModels
StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Job.Extension, HandleJobFileLoaded);
}
+ public override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+ Filter = null;
+ }
+
#endregion
#region Job Export
private async void ExportJob()
{
- var selected_job = SelectedJobs.First();
+ var selected_job = SelectedJobs.FirstOrDefault();
+ if (selected_job == null) return;
+
ClearSelection();
var result = await NavigationManager.
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 5b4a3e403..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
@@ -3,12 +3,15 @@ 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;
using Tango.PPC.Common;
using Tango.PPC.Common.Notifications;
using Tango.PPC.Common.Notifications.NotificationItems;
+using Tango.PPC.Jobs.Messages;
using Tango.PPC.Jobs.NavigationObjects;
using Tango.PPC.Jobs.Views;
@@ -20,6 +23,8 @@ namespace Tango.PPC.Jobs.ViewModels
/// <seealso cref="Tango.PPC.Common.PPCViewModel" />
public class MainViewVM : PPCViewModel
{
+ private NotificationItem _last_failed_job_notification;
+
/// <summary>
/// Called when the application has been started.
/// </summary>
@@ -27,6 +32,44 @@ 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));
+
+ if (_last_failed_job_notification != null)
+ {
+ _last_failed_job_notification.Close();
+ _last_failed_job_notification = null;
+ }
+ });
+ }
+ 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>
@@ -36,7 +79,7 @@ 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)
{
- NotificationProvider.PushNotification(new MessageNotificationItem(
+ _last_failed_job_notification = NotificationProvider.PushNotification(new MessageNotificationItem(
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, () =>
{
@@ -79,5 +122,11 @@ namespace Tango.PPC.Jobs.ViewModels
}));
}
}
+
+ public override void OnNavigatedTo()
+ {
+ base.OnNavigatedTo();
+ RaiseMessage<NavigatedToJobsModuleMessage>();
+ }
}
}