aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs186
1 files changed, 52 insertions, 134 deletions
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 64931cbe3..a7b06f6eb 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
@@ -36,9 +36,6 @@ using System.Windows.Media.Imaging;
using Tango.Touch.Components;
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
{
@@ -49,10 +46,7 @@ namespace Tango.PPC.Jobs.ViewModels
public class JobsViewVM : PPCViewModel<IJobsView>
{
private ObservablesContext _db; //Holds the db context for the job list.
- 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;
+ private ObservableCollection<ColorCatalog> _catalogs; //Holds the available color catalogs.
public enum JobsCategory
{
@@ -324,7 +318,7 @@ namespace Tango.PPC.Jobs.ViewModels
RaiseMessage(new JobSelectedMessage() { Job = job, Context = _db });
- if (!directlyToEdit && MachineProvider.MachineOperator.CanPrint)
+ if (!directlyToEdit && MachineProvider.MachineOperator.Status == Integration.Operation.MachineStatuses.ReadyToDye)
{
await NavigationManager.NavigateWithObject<JobsModule, JobSummeryView, JobSummeryNavigationObject>(new JobSummeryNavigationObject()
{
@@ -355,8 +349,6 @@ namespace Tango.PPC.Jobs.ViewModels
_db = ObservablesContext.CreateDefault();
- _colorSpaces = _db.ColorSpaces.ToList();
-
var jobs = new JobsCollectionBuilder(_db).Set(x => x.MachineGuid == MachineProvider.Machine.Guid).WithSegments().WithBrushStops().WithCustomer().WithColorSpace().Build();
InvokeUI(() =>
@@ -415,15 +407,10 @@ namespace Tango.PPC.Jobs.ViewModels
var machine = MachineProvider.Machine;
JobCreationViewVM vm = new JobCreationViewVM(
- Settings.SupportedJobTypes.Count > 0 ? Settings.SupportedJobTypes : Enum.GetValues(typeof(JobTypes)).Cast<JobTypes>().ToList(),
- Settings.SupportedColorSpaces.Count > 0 ? Settings.SupportedColorSpaces : Enum.GetValues(typeof(ColorSpaces)).Cast<ColorSpaces>().Where(x => x.IsUserSpace() || (ApplicationManager.IsInTechnicianMode && x == ColorSpaces.Volume)).ToList()
+ 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() || (ApplicationManager.IsInTechnicianMode && x == ColorSpaces.Volume)).ToList()
);
- if (_catalogs.Count == 0)
- {
- vm.SupportedColorSpaces.Remove(ColorSpaces.Catalog);
- }
-
CatalogSelectionViewVM catalogVM = new CatalogSelectionViewVM(_catalogs.ToList(), _catalogs.ToList().SingleOrDefault(x => x.Guid == settings.LastSelectedCatalogGuid));
if (settings.LastJobType != null)
@@ -432,7 +419,7 @@ namespace Tango.PPC.Jobs.ViewModels
}
else
{
- vm.SelectedJobType = Settings.SupportedJobTypes.FirstOrDefault();
+ vm.SelectedJobType = machine.SupportedJobTypes.FirstOrDefault();
}
if (settings.LastJobColorSpace != null)
@@ -441,7 +428,7 @@ namespace Tango.PPC.Jobs.ViewModels
}
else
{
- var space = Settings.SupportedColorSpaces.FirstOrDefault();
+ var space = machine.SupportedColorSpaces.FirstOrDefault();
vm.SelectedColorSpace = space.IsUserSpace() ? space : ColorSpaces.Catalog;
}
@@ -459,7 +446,7 @@ namespace Tango.PPC.Jobs.ViewModels
if (twnFile == null)
{
- if (Settings.SupportedJobTypes.Count != 1 || Settings.SupportedColorSpaces.Count != 1)
+ if (machine.SupportedJobTypes.Count != 1 || machine.SupportedColorSpaces.Count != 1)
{
vm = await NotificationProvider.ShowDialog<JobCreationViewVM>(vm);
if (!vm.DialogResult) return;
@@ -489,14 +476,14 @@ namespace Tango.PPC.Jobs.ViewModels
}
else
{
- vm.SelectedJobType = Settings.SupportedJobTypes.First();
- vm.SelectedColorSpace = Settings.SupportedColorSpaces.First();
+ vm.SelectedJobType = machine.SupportedJobTypes.First();
+ vm.SelectedColorSpace = machine.SupportedColorSpaces.First();
}
}
settings.LastJobType = vm.SelectedJobType;
settings.LastJobColorSpace = vm.SelectedColorSpace;
-
+
if (vm.SelectedColorSpace == ColorSpaces.Catalog)
{
settings.LastSelectedCatalogGuid = catalogVM.SelectedCatalog.Guid;
@@ -505,8 +492,6 @@ namespace Tango.PPC.Jobs.ViewModels
settings.Save();
Job job = new Job();
- job.LastUpdated = DateTime.UtcNow;
- job.JobSource = JobSource.Local;
job.Name = "untitled";
job.NumberOfHeads = 1;
job.NumberOfUnits = 1;
@@ -516,12 +501,11 @@ namespace Tango.PPC.Jobs.ViewModels
job.JobType = vm.SelectedJobType;
job.EnableLubrication = true;
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 = null;
- job.RmlGuid = (Settings.DefaultRmlGuid != null && _rmls.Select(x => x.Guid).Contains(Settings.DefaultRmlGuid)) ? Settings.DefaultRmlGuid : _rmls.FirstOrDefault().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 = Settings.DefaultSpoolTypeGuid != null ? Settings.DefaultSpoolTypeGuid : Adapter.SpoolTypes.FirstOrDefault().Guid;
+ job.SpoolTypeGuid = machine.DefaultSpoolType != null ? machine.DefaultSpoolTypeGuid : Adapter.SpoolTypes.FirstOrDefault().Guid;
if (vm.SelectedColorSpace == ColorSpaces.Catalog)
{
@@ -535,11 +519,11 @@ namespace Tango.PPC.Jobs.ViewModels
if (colorProfile == null)
{
- job.AddSolidSegment(Settings.DefaultSegmentLength > 0 ? Settings.DefaultSegmentLength : 100);
+ job.AddSolidSegment(machine.DefaultSegmentLength > 0 ? machine.DefaultSegmentLength : 100);
}
else
{
- job.AddSolidSegment(colorProfile.Value, Settings.DefaultSegmentLength > 0 ? Settings.DefaultSegmentLength : 100);
+ job.AddSolidSegment(colorProfile.Value, machine.DefaultSegmentLength > 0 ? machine.DefaultSegmentLength : 100);
job.Name = $"SnapMatch {colorProfile.Value.R}, {colorProfile.Value.G}, {colorProfile.Value.B}";
}
@@ -740,13 +724,10 @@ namespace Tango.PPC.Jobs.ViewModels
StorageProvider.RegisterFileHandler(ExplorerFileDefinition.Pulse.Extension, HandlePulseFileLoaded);
//Load catalogs.
- using (ObservablesContext db = ObservablesContext.CreateDefault())
+ using (ObservablesContext c = ObservablesContext.CreateDefault())
{
- _catalogs = await new CatalogsCollectionBuilder(db).SetAll().ForSite(MachineProvider.Machine.SiteGuid).BuildAsync();
- _rmls = await new RmlsCollectionBuilder(db).SetAll().ForHeadType(MachineProvider.Machine.MachineHeadType).ForSite(MachineProvider.Machine.SiteGuid).BuildAsync();
+ _catalogs = (await c.ColorCatalogs.ToListAsync()).ToObservableCollection();
}
-
- MachineDataSynchronizer.SynchronizationEnded += MachineDataSynchronizer_SynchronizationEnded;
}
public override void OnNavigatedTo()
@@ -764,64 +745,37 @@ 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,
- StorageNavigationRequest>(
- new StorageNavigationRequest()
+ Storage.Models.StorageNavigationRequest>(
+ new Storage.Models.StorageNavigationRequest()
{
- Intent = selectedJobs.Count == 1 ? StorageNavigationIntent.SaveFile : StorageNavigationIntent.SaveFiles,
+ Intent = Storage.Models.StorageNavigationIntent.SaveFile,
DefaultFileName = selected_job.Name,
Filter = ExplorerFileDefinition.Job.Extension,
- Title = selectedJobs.Count == 1 ? "Save Job File" : "Save Job Files",
+ Title = "Save Job File",
});
if (result != null)
{
- if (selectedJobs.Count == 1)
+ try
{
- try
- {
- var jobFile = await selected_job.ToJobFile();
+ var jobFile = await selected_job.ToJobFile();
- using (FileStream fs = new FileStream(result.Path + ExplorerFileDefinition.Job.Extension, FileMode.Create))
- {
- jobFile.WriteTo(fs);
- }
-
- await NotificationProvider.ShowSuccess("Job saved successfully.");
- }
- catch (Exception ex)
+ using (FileStream fs = new FileStream(result.Path + ExplorerFileDefinition.Job.Extension, FileMode.Create))
{
- 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}");
+ jobFile.WriteTo(fs);
}
+
+ await NotificationProvider.ShowSuccess("Job saved successfully.");
}
- else
+ catch (Exception ex)
{
- foreach (var job in selectedJobs)
- {
- try
- {
- var jobFile = await job.ToJobFile();
-
- using (FileStream fs = new FileStream(Path.Combine(result.Path, jobFile.Name.ToValidFileName()) + 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.");
+ 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}");
}
}
}
@@ -830,7 +784,7 @@ namespace Tango.PPC.Jobs.ViewModels
#region Handle Job File Loading From Storage
- private async void HandleJobFileLoaded(List<ExplorerFileItem> jobFiles)
+ private async void HandleJobFileLoaded(ExplorerFileItem jobFile)
{
var vm = await NotificationProvider.ShowDialog<ImportJobViewVM>();
@@ -838,35 +792,29 @@ namespace Tango.PPC.Jobs.ViewModels
{
using (ObservablesContext jobContext = ObservablesContext.CreateDefault())
{
- foreach (var jobFile in jobFiles)
+ try
{
- try
+ JobFile jFile = JobFile.Parser.ParseFrom(File.ReadAllBytes(jobFile.Path));
+ var job = await Job.FromJobFile(jFile, MachineProvider.Machine.Guid, AuthenticationProvider.CurrentUser.Guid);
+ jobContext.Jobs.Add(job);
+ await jobContext.SaveChangesAsync();
+ LoadJobs(() =>
{
- 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}");
- }
+ if (vm.ImportAndEdit)
+ {
+ var postJob = Jobs.SingleOrDefault(x => x.Guid == job.Guid);
+ if (postJob != null)
+ {
+ SelectJob(postJob, true);
+ }
+ }
+ });
}
-
- LoadJobs(() =>
+ catch (Exception ex)
{
- //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);
- // }
- //}
- });
+ 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}");
+ }
}
}
}
@@ -875,10 +823,8 @@ namespace Tango.PPC.Jobs.ViewModels
#region Handle TCC File Loading From Storage
- private async void HandleColorProfileFileLoaded(List<ExplorerFileItem> tccFiles)
+ private async void HandleColorProfileFileLoaded(ExplorerFileItem tccFile)
{
- var tccFile = tccFiles.FirstOrDefault();
-
try
{
DetectionColorFile tcc = DetectionColorFile.Parser.ParseFrom(File.ReadAllBytes(tccFile.Path));
@@ -907,10 +853,8 @@ namespace Tango.PPC.Jobs.ViewModels
#region Handle Pulse TWN Loading From Storage
- private async void HandlePulseFileLoaded(List<ExplorerFileItem> twnFiles)
+ private async void HandlePulseFileLoaded(ExplorerFileItem twnFile)
{
- var twnFile = twnFiles.FirstOrDefault();
-
TwnFile twn = TwnFile.FromFile(twnFile.Path);
BitmapSource preview = twn.Thumbnail.ToBitmapSource();
@@ -927,32 +871,6 @@ namespace Tango.PPC.Jobs.ViewModels
#endregion
- #region Handle New Synchronized Jobs
-
- private void MachineDataSynchronizer_SynchronizationEnded(object sender, SynchronizationEndedEventArgs e)
- {
- 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;
- };
- }
- }
-
- #endregion
-
#region Color Profile Request
private void ExternalBridgeService_ColorProfileRequest(object sender, ColorProfileRequestEventArgs e)