aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common
diff options
context:
space:
mode:
authorRoy <Roy.mail.net@gmail.com>2023-09-03 17:35:54 +0300
committerRoy <Roy.mail.net@gmail.com>2023-09-03 17:35:54 +0300
commit78ba28666b686329661f4a8fded423af94bbfb84 (patch)
treedea73edeffb65d5005bee12e09726c33e44992f8 /Software/Visual_Studio/PPC/Tango.PPC.Common
parentc66acc359b311ecc940f3c4e74bd9e21dc0bfd51 (diff)
downloadTango-78ba28666b686329661f4a8fded423af94bbfb84.tar.gz
Tango-78ba28666b686329661f4a8fded423af94bbfb84.zip
Job Resume Manager.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs4
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs103
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/IJobResumeManager.cs20
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeDB.cs83
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeDroppedEventArgs.cs13
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeModel.cs21
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeUpdatedEventArgs.cs15
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj10
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config1
9 files changed, 270 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
index b54289813..7064a48e1 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCViewModel.cs
@@ -20,6 +20,7 @@ using Tango.PPC.Common.Printing;
using Tango.PPC.Common.RemoteAssistance;
using Tango.PPC.Common.RemoteDesktop;
using Tango.PPC.Common.RemoteJobUpload;
+using Tango.PPC.Common.Resume;
using Tango.PPC.Common.Storage;
using Tango.PPC.Common.Synchronization;
using Tango.PPC.Common.ThreadLoading;
@@ -145,6 +146,9 @@ namespace Tango.PPC.Common
[TangoInject]
public IBuildProvider BuildProvider { get; set; }
+ [TangoInject]
+ public IJobResumeManager JobResumeManager { get; set; }
+
private PPCSettings _settings;
/// <summary>
/// Gets the main PPC settings.
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs
new file mode 100644
index 000000000..5f819d34d
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/DefaultJobResumeManager.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.Core.DI;
+using Tango.Integration.Operation;
+using Tango.PPC.Common.Build;
+using Tango.PPC.Common.Connection;
+
+namespace Tango.PPC.Common.Resume
+{
+ public class DefaultJobResumeManager : ExtendedObject, IJobResumeManager
+ {
+ private IMachineProvider _machineProvider;
+ private IBuildProvider _buildProvider;
+
+ public event EventHandler<JobResumeUpdatedEventArgs> JobResumeUpdated;
+ public event EventHandler<JobResumeDroppedEventArgs> JobResumeDropped;
+
+ [TangoInject]
+ public DefaultJobResumeManager(IMachineProvider machineProvider,IBuildProvider buildProvider)
+ {
+ _machineProvider = machineProvider;
+ _buildProvider = buildProvider;
+ machineProvider.MachineOperator.PrintingEnded += MachineOperator_PrintingEnded;
+ }
+
+ private void MachineOperator_PrintingEnded(object sender, PrintingEventArgs e)
+ {
+ if (_buildProvider.IsEureka)
+ {
+ UpdateJobResume(e);
+ }
+ }
+
+ private void UpdateJobResume(PrintingEventArgs e)
+ {
+ try
+ {
+ 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);
+ }
+
+ JobResumeUpdated?.Invoke(this, new JobResumeUpdatedEventArgs()
+ {
+ JobGuid = e.Job.Guid,
+ ResumeModel = model
+ });
+ }
+ else
+ {
+ JobResumeDB.Default.Delete(e.Job.Guid);
+
+ JobResumeUpdated?.Invoke(this, new JobResumeUpdatedEventArgs()
+ {
+ JobGuid = e.Job.Guid,
+ ResumeModel = null
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error inserting/updating job resume info on db.");
+ }
+ }
+
+ public JobResumeModel GetJobResumeModel(string jobGuid)
+ {
+ return JobResumeDB.Default.Get(jobGuid);
+ }
+
+ public void DropResume(string jobGuid)
+ {
+ JobResumeDB.Default.Delete(jobGuid);
+
+ JobResumeDropped?.Invoke(this, new JobResumeDroppedEventArgs() { JobGuid = jobGuid });
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/IJobResumeManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/IJobResumeManager.cs
new file mode 100644
index 000000000..002563fc4
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/IJobResumeManager.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Integration.Operation;
+
+namespace Tango.PPC.Common.Resume
+{
+ public interface IJobResumeManager
+ {
+ event EventHandler<JobResumeUpdatedEventArgs> JobResumeUpdated;
+
+ event EventHandler<JobResumeDroppedEventArgs> JobResumeDropped;
+
+ void DropResume(String jobGuid);
+
+ JobResumeModel GetJobResumeModel(String jobGuid);
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeDB.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeDB.cs
new file mode 100644
index 000000000..904e37b2e
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeDB.cs
@@ -0,0 +1,83 @@
+using LiteDB;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Common.Resume
+{
+ public class JobResumeDB : IDisposable
+ {
+ private LiteDatabase _db;
+ private ILiteCollection<JobResumeModel> _collection;
+
+ private static Lazy<JobResumeDB> _default = new Lazy<JobResumeDB>(() => 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<JobResumeModel>("JobResume");
+ }
+
+ public void Update(JobResumeModel model)
+ {
+ _collection.Update(model);
+ }
+
+ public void Add(JobResumeModel model)
+ {
+ _collection.Insert(model);
+ }
+
+ public List<JobResumeModel> 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/Tango.PPC.Common/Resume/JobResumeDroppedEventArgs.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeDroppedEventArgs.cs
new file mode 100644
index 000000000..674087063
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeDroppedEventArgs.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Common.Resume
+{
+ public class JobResumeDroppedEventArgs : EventArgs
+ {
+ public String JobGuid { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeModel.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeModel.cs
new file mode 100644
index 000000000..40386566e
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeModel.cs
@@ -0,0 +1,21 @@
+using LiteDB;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Common.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/Tango.PPC.Common/Resume/JobResumeUpdatedEventArgs.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeUpdatedEventArgs.cs
new file mode 100644
index 000000000..037654370
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resume/JobResumeUpdatedEventArgs.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Common.Resume
+{
+ public class JobResumeUpdatedEventArgs : EventArgs
+ {
+ public JobResumeModel ResumeModel { get; set; }
+
+ public String JobGuid { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj
index e598c6fe4..28cbfa6bc 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj
@@ -88,6 +88,9 @@
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath>
</Reference>
+ <Reference Include="LiteDB, Version=5.0.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
+ <HintPath>..\..\packages\LiteDB.5.0.4\lib\net45\LiteDB.dll</HintPath>
+ </Reference>
<Reference Include="Microsoft.Azure.Common.NetFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.SqlServer.AzureStorageEnum, Version=14.100.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL" />
@@ -121,6 +124,7 @@
</Reference>
<Reference Include="System.Management" />
<Reference Include="System.Numerics" />
+ <Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Web" />
@@ -221,6 +225,12 @@
<Compile Include="RemoteActions\IRemoteActionsService.cs" />
<Compile Include="RemoteNotifications\DefaultRemoteNotificationsService.cs" />
<Compile Include="RemoteNotifications\IRemoteNotificationsService.cs" />
+ <Compile Include="Resume\DefaultJobResumeManager.cs" />
+ <Compile Include="Resume\IJobResumeManager.cs" />
+ <Compile Include="Resume\JobResumeDB.cs" />
+ <Compile Include="Resume\JobResumeDroppedEventArgs.cs" />
+ <Compile Include="Resume\JobResumeModel.cs" />
+ <Compile Include="Resume\JobResumeUpdatedEventArgs.cs" />
<Compile Include="SQL\DefaultRemoteSqlService.cs" />
<Compile Include="SQL\IRemoteSqlService.cs" />
<Compile Include="Statistics\DefaultStatisticsService.cs" />
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config b/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config
index adc33d349..cba40d441 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/packages.config
@@ -6,6 +6,7 @@
<package id="FontAwesome.WPF" version="4.7.0.9" targetFramework="net46" />
<package id="Google.Protobuf" version="3.4.1" targetFramework="net46" />
<package id="Ionic.Zip" version="1.9.1.8" targetFramework="net461" />
+ <package id="LiteDB" version="5.0.4" targetFramework="net461" />
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
<package id="System.Data.SQLite" version="1.0.108.0" targetFramework="net46" />