From 78ba28666b686329661f4a8fded423af94bbfb84 Mon Sep 17 00:00:00 2001 From: Roy Date: Sun, 3 Sep 2023 17:35:54 +0300 Subject: Job Resume Manager. --- .../Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs | 83 ---------------------- .../Tango.PPC.JobsV2/Resume/JobResumeModel.cs | 21 ------ .../Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj | 4 +- .../Tango.PPC.JobsV2/ViewModels/JobViewVM.cs | 68 ++++-------------- 4 files changed, 16 insertions(+), 160 deletions(-) delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeModel.cs (limited to 'Software/Visual_Studio/PPC/Modules') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs deleted file mode 100644 index 28184eee1..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeDB.cs +++ /dev/null @@ -1,83 +0,0 @@ -using LiteDB; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.PPC.Jobs.Resume -{ - public class JobResumeDB : IDisposable - { - private LiteDatabase _db; - private ILiteCollection _collection; - - private static Lazy _default = new Lazy(() => new JobResumeDB()); - - public static JobResumeDB Default - { - get - { - return _default.Value; - } - } - - private JobResumeDB() - { - Init(); - } - - private void Init() - { - String dbFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Job Resume v2"); - Directory.CreateDirectory(dbFolder); - _db = new LiteDatabase($"Filename={Path.Combine(dbFolder, "job_resume.db")};connection=shared"); - _collection = _db.GetCollection("JobResume"); - } - - public void Update(JobResumeModel model) - { - _collection.Update(model); - } - - public void Add(JobResumeModel model) - { - _collection.Insert(model); - } - - public List GetAll() - { - return _collection.FindAll().ToList(); - } - - public JobResumeModel Get(String jobGuild) - { - return _collection.FindOne(x => x.JobGuid == jobGuild); - } - - public void Delete(JobResumeModel model) - { - _collection.Delete(model.JobGuid); - } - - public void Delete(String jobGuid) - { - _collection.Delete(jobGuid); - } - - ~JobResumeDB() - { - Dispose(); - } - - public void Dispose() - { - try - { - _db?.Dispose(); - } - catch { } - } - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeModel.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeModel.cs deleted file mode 100644 index 4ded7e313..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Resume/JobResumeModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using LiteDB; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.PPC.Jobs.Resume -{ - public class JobResumeModel - { - [BsonId] - public String JobGuid { get; set; } - - public int RemainingUnits { get; set; } - - public double GlobalStartPosition { get; set; } - - public double FirstUnitStartPosition { get; set; } - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj index 5ec7c3f39..96083d842 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Tango.PPC.JobsV2.csproj @@ -352,8 +352,6 @@ ColorCorrectionReport.xaml - - @@ -757,7 +755,7 @@ - + \ No newline at end of file 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 9d8ae1555..123151fcf 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 @@ -46,8 +46,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Tango.PPC.Jobs.ColorCorrectionTool; using Tango.PPC.Common.Printing; -using Tango.PPC.Jobs.Resume; using Tango.Core.ExtensionMethods; +using Tango.PPC.Common.Resume; namespace Tango.PPC.Jobs.ViewModels { @@ -509,7 +509,7 @@ namespace Tango.PPC.Jobs.ViewModels try { - ResumeModel = JobResumeDB.Default.Get(Job.Guid); + ResumeModel = JobResumeManager.GetJobResumeModel(Job.Guid); if (ResumeModel != null) { @@ -1326,6 +1326,9 @@ namespace Tango.PPC.Jobs.ViewModels MachineProvider.MachineOperator.PrintingEnded += MachineOperator_PrintingEnded; MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; + + JobResumeManager.JobResumeUpdated += JobResumeManager_JobResumeUpdated; + JobResumeManager.JobResumeDropped += JobResumeManager_JobResumeDropped; } /// @@ -1793,11 +1796,6 @@ namespace Tango.PPC.Jobs.ViewModels } RaisePropertyChanged(nameof(CanEdit)); - - if (BuildProvider.IsEureka) - { - UpdateJobResume(e); - } } @@ -1805,54 +1803,19 @@ namespace Tango.PPC.Jobs.ViewModels #region Resume - private void UpdateJobResume(PrintingEventArgs e) + private void JobResumeManager_JobResumeUpdated(object sender, Common.Resume.JobResumeUpdatedEventArgs e) { - try + if (Job.Guid == e.JobGuid) { - if (!e.JobHandler.Status.IsCompleted) - { - if (e.JobHandler.JobStatus.Progress <= e.JobHandler.ProcessParameters.DryerBufferLengthMeters) return; - - var model = JobResumeDB.Default.Get(e.Job.Guid); - bool insert = false; - if (model == null) - { - model = new JobResumeModel(); - insert = true; - } - - model.JobGuid = e.Job.Guid; - model.FirstUnitStartPosition = e.JobHandler.Status.CurrentUnitProgress; - model.RemainingUnits = e.JobHandler.Status.RemainingUnits; - model.GlobalStartPosition = e.JobHandler.JobStatus.Progress; - - if (insert) - { - JobResumeDB.Default.Add(model); - } - else - { - JobResumeDB.Default.Update(model); - } - - if (Job.Guid == e.Job.Guid) - { - ResumeModel = model; - } - } - else - { - JobResumeDB.Default.Delete(e.Job.Guid); - - if (Job.Guid == e.Job.Guid) - { - ResumeModel = null; - } - } + ResumeModel = e.ResumeModel; } - catch (Exception ex) + } + + private void JobResumeManager_JobResumeDropped(object sender, Common.Resume.JobResumeDroppedEventArgs e) + { + if (Job.Guid == e.JobGuid) { - LogManager.Log(ex, "Error inserting/updating job resume info on db."); + ResumeModel = null; } } @@ -1862,8 +1825,7 @@ namespace Tango.PPC.Jobs.ViewModels { if (await NotificationProvider.ShowQuestion("Drop resume information and enable job editing?")) { - JobResumeDB.Default.Delete(Job.Guid); - ResumeModel = null; + JobResumeManager.DropResume(Job.Guid); } } } -- cgit v1.3.1