aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2022-05-29 18:00:42 +0300
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2022-05-29 18:00:42 +0300
commita5750ed1aa564bf8a9071dd08df3a2ec003aa540 (patch)
tree56eff36769a0ba4129e3c47c9f2f9e3f2f89b4fc /Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels
parent13dd96fc0e7cc40e6d1eb31f9e80ad5371a76b3d (diff)
downloadTango-a5750ed1aa564bf8a9071dd08df3a2ec003aa540.tar.gz
Tango-a5750ed1aa564bf8a9071dd08df3a2ec003aa540.zip
PPC. Saving job model to json string to compare changes.
Related Work Items: #6280
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels')
-rw-r--r--Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs63
1 files changed, 31 insertions, 32 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs
index 01b819284..f1a736180 100644
--- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs
+++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/ViewModels/JobViewVM.cs
@@ -42,6 +42,8 @@ using Tango.PPC.Common.Lubrication;
using Tango.PPC.Jobs.Models;
using Tango.Core;
using Tango.PPC.Jobs.UndoRedoCommands;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
namespace Tango.PPC.Jobs.ViewModels
{
@@ -65,6 +67,7 @@ namespace Tango.PPC.Jobs.ViewModels
private bool startingJob = false;
private List<ColorCatalog> _catalogs;
+ private string _jsonJobModelLoaded;
#region Properties
private Job _job;
@@ -581,6 +584,12 @@ namespace Tango.PPC.Jobs.ViewModels
SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(SegmentModel.SegmentIndex), ListSortDirection.Ascending));
UndoRedoManager.Instance.ClearAll();
ArrangeSegmentsIndixes();
+ JsonSerializerSettings settings = new JsonSerializerSettings()
+ {
+ ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
+ PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects
+ };
+ _jsonJobModelLoaded = JsonConvert.SerializeObject(JobModel , Formatting.Indented, settings);
}
/// <summary>
@@ -681,12 +690,7 @@ namespace Tango.PPC.Jobs.ViewModels
vm = await NotificationProvider.ShowDialog<JobCreationViewVM>(vm);
if (!vm.DialogResult) return;
-
- if(Job.Name != vm.JobName || Job.InterSegmentLength != vm.WhiteGap || Job.SpoolType != vm.SelectedSpoolType || SelectedRML != vm.SelectedRML)
- {
- JobModel.JobChanged = true;
- }
-
+
Job.Name = vm.JobName;
JobModel.Name = vm.JobName;
@@ -737,10 +741,6 @@ namespace Tango.PPC.Jobs.ViewModels
if (vm.DialogResult)
{
- if(JobModel.NumberOfUnits != vm.Repeats)
- {
- JobModel.JobChanged = true;
- }
JobModel.NumberOfUnits = vm.Repeats;
}
}
@@ -829,8 +829,7 @@ namespace Tango.PPC.Jobs.ViewModels
LogManager.Log("Adding new segment...");
UndoRedoManager.Instance.InsertAndExecuteCommand(new AddNewSegmentCommand(JobModel, segment, Settings.DefaultSegmentLength > 0 ? Settings.DefaultSegmentLength : 10));
- JobModel.JobChanged = true;
- ArrangeSegmentsIndixes();
+ ArrangeSegmentsIndixes();
DyeCommand.RaiseCanExecuteChanged();
}
catch (Exception ex)
@@ -852,8 +851,6 @@ namespace Tango.PPC.Jobs.ViewModels
if (vm.DialogResult)
{
- if(group.Repeats != vm.Repeats)
- JobModel.JobChanged = true;
group.Repeats = vm.Repeats;
}
}
@@ -870,7 +867,6 @@ namespace Tango.PPC.Jobs.ViewModels
if (await NotificationProvider.ShowQuestion("Are you sure you want to remove the selected segment?"))
{
UndoRedoManager.Instance.InsertAndExecuteCommand(new RemoveSegmentCommand(JobModel, segment));
- JobModel.JobChanged = true;
ArrangeSegmentsIndixes();
DyeCommand.RaiseCanExecuteChanged();
@@ -899,8 +895,7 @@ namespace Tango.PPC.Jobs.ViewModels
UndoRedoManager.Instance.InsertAndExecuteCommand(new DeleteSegmentsGroupCommand(JobModel, segmentsGroup));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
-
+
DyeCommand.RaiseCanExecuteChanged();
}
}
@@ -922,7 +917,7 @@ namespace Tango.PPC.Jobs.ViewModels
{
UndoRedoManager.Instance.InsertAndExecuteCommand(new DuplicateSegmentCommand(JobModel, segment));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
+
DyeCommand.RaiseCanExecuteChanged();
}
@@ -996,7 +991,7 @@ namespace Tango.PPC.Jobs.ViewModels
{
UndoRedoManager.Instance.InsertAndExecuteCommand(new EditBrushStopColorCommand(segment, brushStop, vm.SelectedBrushStop));
DyeCommand.RaiseCanExecuteChanged();
- JobModel.JobChanged = true;
+
}
}
@@ -1021,7 +1016,7 @@ namespace Tango.PPC.Jobs.ViewModels
}
UndoRedoManager.Instance.InsertAndExecuteCommand(new AddBrushStopCommand(JobModel, segment, newBrushStop));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
+
}
#endregion
@@ -1233,7 +1228,7 @@ namespace Tango.PPC.Jobs.ViewModels
UndoRedoManager.Instance.InsertAndExecuteCommand(new ReverseCommand(JobModel));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
+
}
private async void DeleteSegments()
@@ -1255,7 +1250,7 @@ namespace Tango.PPC.Jobs.ViewModels
UndoRedoManager.Instance.InsertAndExecuteCommand(new RemoveSegmentsCommand(JobModel));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
+
DyeCommand.RaiseCanExecuteChanged();
}
}
@@ -1277,28 +1272,24 @@ namespace Tango.PPC.Jobs.ViewModels
return;
UndoRedoManager.Instance.InsertAndExecuteCommand(new RepeatCommand(JobModel));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
}
private void UngroupSegments(SegmentsGroupModel segmentsGroup)
{
UndoRedoManager.Instance.InsertAndExecuteCommand(new UnGroupSegmentsCommand(JobModel, segmentsGroup));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
}
private void Paste()
{
UndoRedoManager.Instance.InsertAndExecuteCommand(new PasteSegmentsCommand(JobModel));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
}
private void Copy()
{
UndoRedoManager.Instance.InsertAndExecuteCommand(new CopySegmentCommand(JobModel));
ArrangeSegmentsIndixes();
- JobModel.JobChanged = true;
}
private void Undo()
@@ -1326,7 +1317,7 @@ namespace Tango.PPC.Jobs.ViewModels
UndoRedoManager.Instance.ClearAll();
var colorSpaces = await _db.ColorSpaces.ToListAsync();
-
+
Job.ColorSpace = colorSpaces.FirstOrDefault();
Job.Version = 2;
Job.NumberOfUnits = JobModel.NumberOfUnits;
@@ -1457,13 +1448,21 @@ namespace Tango.PPC.Jobs.ViewModels
}
Job.LastUpdated = DateTime.UtcNow;
Job.IsSynchronized = false;
- if(Job.JobStatus != JobStatuses.Draft && JobModel.JobChanged == true)
+
+ if(Job.JobStatus != JobStatuses.Draft )
{
- Job.JobStatus = BL.Enumerations.JobStatuses.Draft;
+ JsonSerializerSettings settings = new JsonSerializerSettings()
+ {
+ ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
+ PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects
+ };
+ string jsonJobModelSaved = JsonConvert.SerializeObject(JobModel, Formatting.Indented, settings);
+ var json1 = JObject.Parse(_jsonJobModelLoaded);
+ var json2 = JObject.Parse(jsonJobModelSaved);
+ if(false == JToken.DeepEquals(json1, json2))
+ Job.JobStatus = BL.Enumerations.JobStatuses.Draft;
}
- JobModel.JobChanged = false;
- //Job.JobStatus = BL.Enumerations.JobStatuses.Draft;
- //_current_job_string = Job.ToJobFileWhenLoaded().ToString();
+
RaiseMessage(new JobSavedMessage() { Job = Job });
await _db.SaveChangesAsync();