aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-10-29 15:55:21 +0200
committerShlomo Hecht <shlomo@twine-s.com>2020-10-29 15:55:21 +0200
commit4b789f33eadfc5cc1d937a80ce03ea8425955ffe (patch)
tree7dbbd0529a24f9ca064cab688a0d6d2b8b762ea1 /Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels
parent8f3baa0d9097aa6ed800863a4680608e867c809a (diff)
parent11fb700fcbc4627162a9c3f84b03b5016248bd97 (diff)
downloadTango-4b789f33eadfc5cc1d937a80ce03ea8425955ffe.tar.gz
Tango-4b789f33eadfc5cc1d937a80ce03ea8425955ffe.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
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.cs17
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs11
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs29
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs123
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/MainViewVM.cs33
5 files changed, 141 insertions, 72 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 03cd5bfff..b4a30cb39 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
@@ -9,6 +9,7 @@ using Tango.Integration.Operation;
using Tango.PMR.Printing;
using Tango.PPC.Common;
using Tango.PPC.Common.Navigation;
+using Tango.PPC.Common.Notifications;
using Tango.PPC.Jobs.AppBarItems;
using Tango.PPC.Jobs.AppButtons;
using Tango.PPC.Jobs.Dialogs;
@@ -25,6 +26,7 @@ namespace Tango.PPC.Jobs.ViewModels
{
private StopPrintingButton _stop_job_btn;
private JobHandler _handler;
+ private JobProgressAppBarItem _appBarItem;
#region Properties
@@ -142,9 +144,10 @@ namespace Tango.PPC.Jobs.ViewModels
if (MachineProvider.MachineOperator.IsPrinting && _handler != null && !_handler.IsCanceled)
{
- NotificationProvider.PushAppBarItem<JobProgressAppBarItem>().Pressed += (_, __) =>
+ _appBarItem = NotificationProvider.PushAppBarItem<JobProgressAppBarItem>();
+ _appBarItem.Pressed += (_, __) =>
{
- NotificationProvider.CurrentAppBarItem.Close();
+ _appBarItem?.Close();
NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView));
};
}
@@ -159,10 +162,7 @@ namespace Tango.PPC.Jobs.ViewModels
IsDisplayJobOutline = false;
- if (NotificationProvider.HasAppBarItem && NotificationProvider.CurrentAppBarItem is JobProgressAppBarItem)
- {
- NotificationProvider.CurrentAppBarItem.Close();
- }
+ _appBarItem?.Close();
if (_handler != null && !_handler.Status.IsFailed)
{
@@ -232,10 +232,7 @@ namespace Tango.PPC.Jobs.ViewModels
_stop_job_btn.Pop();
}
- if (NotificationProvider.HasAppBarItem && NotificationProvider.CurrentAppBarItem is JobProgressAppBarItem)
- {
- NotificationProvider.CurrentAppBarItem.Close();
- }
+ _appBarItem?.Close();
if (_handler != null)
{
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 365075d4a..67389c759 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
@@ -26,6 +26,7 @@ namespace Tango.PPC.Jobs.ViewModels
{
private ObservablesContext _context;
private bool _canStartJob;
+ private bool _startingJob;
private bool _isPreparingJob;
/// <summary>
@@ -59,7 +60,6 @@ namespace Tango.PPC.Jobs.ViewModels
set { _estimatedDuration = value; RaisePropertyChangedAuto(); }
}
-
/// <summary>
/// Gets or sets the dye command.
/// </summary>
@@ -96,12 +96,17 @@ namespace Tango.PPC.Jobs.ViewModels
/// </summary>
private async void StartJob()
{
+ if (_startingJob) return;
+
+ _startingJob = true;
+
try
{
LogManager.Log("Start job command pressed. Starting job and navigating to job progress view...");
await PrintingManager.Print(Job, _context);
await NavigationManager.NavigateTo<JobsModule>(false, nameof(JobProgressView));
+ _startingJob = false;
}
catch (InsufficientLiquidQuantityException)
{
@@ -112,6 +117,10 @@ namespace Tango.PPC.Jobs.ViewModels
LogManager.Log(ex, "Could not start the current job.");
await NotificationProvider.ShowError($"{ex.Message}");
}
+ finally
+ {
+ _startingJob = false;
+ }
}
/// <summary>
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 efaf98966..5e90d3b5b 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
@@ -56,6 +56,7 @@ namespace Tango.PPC.Jobs.ViewModels
private ActionTimer _volumeConversionTimer;
private IColorConverter _converter;
private string _current_job_string;
+ private bool startingJob = false;
#region Properties
@@ -545,18 +546,15 @@ namespace Tango.PPC.Jobs.ViewModels
}
catch (Exception ex)
{
- LogManager.Log(ex, $"Error loading job '{_job_to_load.Name}'");
+ IsFree = true;
+ LogManager.Log(ex, $"Error loading job '{(_job_to_load != null ? _job_to_load.Name : "null")}'");
await NotificationProvider.ShowError("An error occurred while trying to load the selected job.");
_can_navigate_back = true;
await NavigationManager.NavigateBack();
}
finally
{
- InvokeUI(() =>
- {
- IsFree = true;
- //NotificationProvider.ReleaseGlobalBusyMessage();
- });
+ IsFree = true;
}
}
@@ -647,11 +645,16 @@ namespace Tango.PPC.Jobs.ViewModels
/// </summary>
private async void StartJob()
{
+ if (startingJob) return;
+
try
{
+ Debug.WriteLine("Job Starting...");
+ startingJob = true;
LogManager.Log("Start job command pressed. Starting job and navigating to job progress view...");
var handler = await PrintingManager.Print(Job, _db);
await NavigationManager.NavigateTo<JobsModule>(nameof(JobProgressView));
+ startingJob = false;
}
catch (InsufficientLiquidQuantityException)
{
@@ -662,6 +665,10 @@ namespace Tango.PPC.Jobs.ViewModels
LogManager.Log(ex, "Could not start the current job.");
await NotificationProvider.ShowError($"{ex.Message}.");
}
+ finally
+ {
+ startingJob = false;
+ }
}
/// <summary>
@@ -670,8 +677,7 @@ namespace Tango.PPC.Jobs.ViewModels
private bool CanStartJob()
{
return
- Job != null && Job.Validate(_db) &&
- !Job.Segments.SelectMany(x => x.BrushStops).Where(x => !x.IsTransparent && !x.IsWhite).ToList().Exists(x => x.IsOutOfGamut);
+ Job != null && Job.Validate(_db) && !Job.Segments.SelectMany(x => x.BrushStops).Where(x => !x.IsTransparent && !x.IsWhite).ToList().Exists(x => x.IsOutOfGamut || x.IsLiquidVolumesOutOfRange);
}
#endregion
@@ -997,6 +1003,11 @@ namespace Tango.PPC.Jobs.ViewModels
stop.Blue = output.SingleCoordinates.Blue;
stop.Corrected = true;
stop.IsOutOfGamut = false;
+
+ InvokeUI(() =>
+ {
+ DyeCommand.RaiseCanExecuteChanged();
+ });
}
catch (Exception ex)
{
@@ -1417,6 +1428,8 @@ namespace Tango.PPC.Jobs.ViewModels
{
bool result = true;
+ if (!IsFree) return false;
+
if (!_can_navigate_back)
{
bool jobChainged = false;
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 af576ac93..a6ccad7de 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
@@ -38,6 +38,7 @@ using Tango.PPC.Jobs.ViewContracts;
using Tango.Core.ExtensionMethods;
using Tango.PPC.Common.Synchronization;
using Tango.PPC.Jobs.NotificationItems;
+using Tango.PPC.Storage.Models;
namespace Tango.PPC.Jobs.ViewModels
{
@@ -51,6 +52,7 @@ namespace Tango.PPC.Jobs.ViewModels
private ObservableCollection<ColorCatalog> _catalogs; //Holds the available color catalogs for the site.
private ObservableCollection<Rml> _rmls; //Holds the available RML for the site.
private List<ColorSpace> _colorSpaces; //Holds the available color spaces.
+ private bool _isJobsSynchronizationNotificationActive;
public enum JobsCategory
{
@@ -516,8 +518,8 @@ namespace Tango.PPC.Jobs.ViewModels
job.ColorSpaceGuid = Adapter.ColorSpaces.FirstOrDefault(x => x.Code == vm.SelectedColorSpace.ToInt32()).Guid;
job.ColorSpace = _colorSpaces.SingleOrDefault(x => x.Guid == job.ColorSpaceGuid);
job.MachineGuid = MachineProvider.Machine.Guid;
- job.UserGuid = AuthenticationProvider.CurrentUser.Guid;
- job.RmlGuid = Settings.DefaultRmlGuid != null ? Settings.DefaultRmlGuid : _rmls.FirstOrDefault().Guid;
+ job.UserGuid = null;
+ job.RmlGuid = (Settings.DefaultRmlGuid != null && _rmls.Select(x => x.Guid).Contains(Settings.DefaultRmlGuid)) ? Settings.DefaultRmlGuid : _rmls.FirstOrDefault().Guid;
job.WindingMethodGuid = Adapter.WindingMethods.FirstOrDefault().Guid;
job.SpoolTypeGuid = Settings.DefaultSpoolTypeGuid != null ? Settings.DefaultSpoolTypeGuid : Adapter.SpoolTypes.FirstOrDefault().Guid;
@@ -762,37 +764,64 @@ namespace Tango.PPC.Jobs.ViewModels
var selected_job = SelectedJobs.FirstOrDefault();
if (selected_job == null) return;
+ var selectedJobs = SelectedJobs.ToList();
+
ClearSelection();
var result = await NavigationManager.
NavigateForResult<StorageModule,
Storage.Views.MainView, ExplorerFileItem,
- Storage.Models.StorageNavigationRequest>(
- new Storage.Models.StorageNavigationRequest()
+ StorageNavigationRequest>(
+ new StorageNavigationRequest()
{
- Intent = Storage.Models.StorageNavigationIntent.SaveFile,
+ Intent = selectedJobs.Count == 1 ? StorageNavigationIntent.SaveFile : StorageNavigationIntent.SaveFiles,
DefaultFileName = selected_job.Name,
Filter = ExplorerFileDefinition.Job.Extension,
- Title = "Save Job File",
+ Title = selectedJobs.Count == 1 ? "Save Job File" : "Save Job Files",
});
if (result != null)
{
- try
+ if (selectedJobs.Count == 1)
{
- var jobFile = await selected_job.ToJobFile();
+ try
+ {
+ var jobFile = await selected_job.ToJobFile();
+
+ using (FileStream fs = new FileStream(result.Path + ExplorerFileDefinition.Job.Extension, FileMode.Create))
+ {
+ jobFile.WriteTo(fs);
+ }
- using (FileStream fs = new FileStream(result.Path + ExplorerFileDefinition.Job.Extension, FileMode.Create))
+ await NotificationProvider.ShowSuccess("Job saved successfully.");
+ }
+ catch (Exception ex)
{
- jobFile.WriteTo(fs);
+ LogManager.Log(ex, $"Error saving job {selected_job.Name} to file.");
+ await NotificationProvider.ShowError($"An error occurred while trying to save the job.\n{ex.Message}");
}
-
- await NotificationProvider.ShowSuccess("Job saved successfully.");
}
- catch (Exception ex)
+ else
{
- LogManager.Log(ex, $"Error saving job {selected_job.Name} to file.");
- await NotificationProvider.ShowError($"An error occurred while trying to save the job.\n{ex.Message}");
+ foreach (var job in selectedJobs)
+ {
+ try
+ {
+ var jobFile = await job.ToJobFile();
+
+ using (FileStream fs = new FileStream(Path.Combine(result.Path, jobFile.Name) + ExplorerFileDefinition.Job.Extension, FileMode.Create))
+ {
+ jobFile.WriteTo(fs);
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error saving job {job.Name} to file.");
+ await NotificationProvider.ShowError($"An error occurred while trying to save the job.\n{ex.Message}");
+ }
+ }
+
+ await NotificationProvider.ShowSuccess("Jobs saved successfully.");
}
}
}
@@ -801,7 +830,7 @@ namespace Tango.PPC.Jobs.ViewModels
#region Handle Job File Loading From Storage
- private async void HandleJobFileLoaded(ExplorerFileItem jobFile)
+ private async void HandleJobFileLoaded(List<ExplorerFileItem> jobFiles)
{
var vm = await NotificationProvider.ShowDialog<ImportJobViewVM>();
@@ -809,30 +838,35 @@ namespace Tango.PPC.Jobs.ViewModels
{
using (ObservablesContext jobContext = ObservablesContext.CreateDefault())
{
- try
+ foreach (var jobFile in jobFiles)
{
- JobFile jFile = JobFile.Parser.ParseFrom(File.ReadAllBytes(jobFile.Path));
- var job = await Job.FromJobFile(jFile, MachineProvider.Machine.Guid, AuthenticationProvider.CurrentUser.Guid);
- job.JobSource = JobSource.Local;
- jobContext.Jobs.Add(job);
- await jobContext.SaveChangesAsync();
- LoadJobs(() =>
+ try
{
- if (vm.ImportAndEdit)
- {
- var postJob = Jobs.SingleOrDefault(x => x.Guid == job.Guid);
- if (postJob != null)
- {
- SelectJob(postJob, true);
- }
- }
- });
+ JobFile jFile = JobFile.Parser.ParseFrom(File.ReadAllBytes(jobFile.Path));
+ var job = await Job.FromJobFile(jFile, MachineProvider.Machine.Guid, null);
+ job.JobSource = JobSource.Local;
+ jobContext.Jobs.Add(job);
+ await jobContext.SaveChangesAsync();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, $"Error occurred while trying to import job from file {jobFile.Path}.");
+ await NotificationProvider.ShowError($"An error occurred while trying to import the selected job file.\n{ex.Message}");
+ }
}
- catch (Exception ex)
+
+ LoadJobs(() =>
{
- LogManager.Log(ex, $"Error occurred while trying to import job from file {jobFile.Path}.");
- await NotificationProvider.ShowError($"An error occurred while trying to import the selected job file.\n{ex.Message}");
- }
+ //Editing of a job is currently deprecated due to enabling multiple job imports.
+ //if (vm.ImportAndEdit)
+ //{
+ // var postJob = Jobs.SingleOrDefault(x => x.Guid == job.Guid);
+ // if (postJob != null)
+ // {
+ // SelectJob(postJob, true);
+ // }
+ //}
+ });
}
}
}
@@ -841,8 +875,10 @@ namespace Tango.PPC.Jobs.ViewModels
#region Handle TCC File Loading From Storage
- private async void HandleColorProfileFileLoaded(ExplorerFileItem tccFile)
+ private async void HandleColorProfileFileLoaded(List<ExplorerFileItem> tccFiles)
{
+ var tccFile = tccFiles.FirstOrDefault();
+
try
{
DetectionColorFile tcc = DetectionColorFile.Parser.ParseFrom(File.ReadAllBytes(tccFile.Path));
@@ -871,8 +907,10 @@ namespace Tango.PPC.Jobs.ViewModels
#region Handle Pulse TWN Loading From Storage
- private async void HandlePulseFileLoaded(ExplorerFileItem twnFile)
+ private async void HandlePulseFileLoaded(List<ExplorerFileItem> twnFiles)
{
+ var twnFile = twnFiles.FirstOrDefault();
+
TwnFile twn = TwnFile.FromFile(twnFile.Path);
BitmapSource preview = twn.Thumbnail.ToBitmapSource();
@@ -893,16 +931,23 @@ namespace Tango.PPC.Jobs.ViewModels
private void MachineDataSynchronizer_SynchronizationEnded(object sender, SynchronizationEndedEventArgs e)
{
- if (e.NewChangedJobs > 0)
+ if (e.NewChangedJobs > 0 && !_isJobsSynchronizationNotificationActive)
{
+ _isJobsSynchronizationNotificationActive = true;
+
var item = NotificationProvider.PushNotification<NewSynchronizardJobsNotificationItem>();
item.Pressed += (_, __) =>
{
+ _isJobsSynchronizationNotificationActive = false;
LoadJobs(() =>
{
NotificationProvider.ShowSuccess("Your job list is now synchronized.");
});
};
+ item.Closed += (_, __) =>
+ {
+ _isJobsSynchronizationNotificationActive = false;
+ };
}
}
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 48e7a55ec..daf27e62e 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
@@ -24,6 +24,7 @@ namespace Tango.PPC.Jobs.ViewModels
public class MainViewVM : PPCViewModel
{
private NotificationItem _last_failed_job_notification;
+ private bool resuming;
/// <summary>
/// Called when the application has been started.
@@ -33,23 +34,14 @@ 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;
}
- private async void MachineOperator_ResumingJob(object sender, ResumingJobEventArgs e)
+ private void MachineOperator_PrintingStarted(object sender, PrintingEventArgs e)
{
- LogManager.Log($"Trying to resume job '{e.JobGuid}'...");
-
- try
+ if (resuming)
{
- var job = await new JobBuilder(ObservablesContext.CreateDefault()).Set(e.JobGuid)
- .WithConfiguration()
- .WithRML()
- .WithUser()
- .WithSegments()
- .WithBrushStops()
- .BuildAsync();
-
- e.Approve(job);
+ resuming = false;
InvokeUI(() =>
{
@@ -62,6 +54,17 @@ 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.");
@@ -79,9 +82,11 @@ 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()}\nTap to view this job details.";
+
_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.",
- 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, () =>
+ message, MessageNotificationItem.MessageNotificationItemTypes.Error, () =>
{
NavigationManager.NavigateWithObject<JobsModule, JobView, Job>(e.Job);
NavigationManager.ClearHistoryExcept<JobsView>();