aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-05 00:35:57 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-05 00:35:57 +0300
commitdd81a94133e1c5117e06e84cbddf45ffec30acfc (patch)
tree13640f05cae1caf4d893d94e73bb0b7a2705110a /Software/Visual_Studio/PPC
parenta64398732031132ddedd6584c1990a5caa1ae049 (diff)
downloadTango-dd81a94133e1c5117e06e84cbddf45ffec30acfc.tar.gz
Tango-dd81a94133e1c5117e06e84cbddf45ffec30acfc.zip
Dashboard completed ?
Remote job tracking.
Diffstat (limited to 'Software/Visual_Studio/PPC')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/DefaultRemoteJobService.cs153
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/IRemoteJobService.cs14
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj4
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobProgress.cs21
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobStage.cs18
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateRequest.cs13
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateResponse.cs22
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj8
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs3
9 files changed, 255 insertions, 1 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/DefaultRemoteJobService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/DefaultRemoteJobService.cs
new file mode 100644
index 000000000..33e002950
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/DefaultRemoteJobService.cs
@@ -0,0 +1,153 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.DTO;
+using Tango.Core;
+using Tango.Core.DI;
+using Tango.Integration.ExternalBridge;
+using Tango.Integration.Operation;
+using Tango.PPC.Common.Connection;
+using Tango.PPC.Common.ExternalBridge;
+using Tango.PPC.Shared.Jobs;
+
+namespace Tango.PPC.Common.RemoteJob
+{
+ [TangoCreateWhenRegistered]
+ public class DefaultRemoteJobService : IRemoteJobService, IExternalBridgeRequestHandler
+ {
+ private class RunningJobUpdateClient
+ {
+ public String Token { get; set; }
+ public ExternalBridgeReceiver Receiver { get; set; }
+ public bool JobSent { get; set; }
+ }
+
+ private List<RunningJobUpdateClient> _clients;
+ private JobHandler _handler;
+
+ public bool Enabled { get; set; } = true;
+
+ private IMachineProvider MachineProvider { get; set; }
+
+ public DefaultRemoteJobService(IPPCExternalBridgeService externalBridge, IMachineProvider machineProvider)
+ {
+ externalBridge.RegisterRequestHandler(this);
+
+ MachineProvider = machineProvider;
+
+ _clients = new List<RunningJobUpdateClient>();
+ MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted;
+ }
+
+ private async void MachineOperator_PrintingStarted(object sender, Integration.Operation.PrintingEventArgs e)
+ {
+ _handler = e.JobHandler;
+
+ e.JobHandler.StatusChanged += JobHandler_StatusChanged;
+ e.JobHandler.Stopped += JobHandler_Stopped;
+
+ var jobDTO = JobDTO.FromObservable(e.Job);
+ var processParametersDTO = ProcessParametersTableDTO.FromObservable(_handler.ProcessParameters);
+
+ foreach (var client in _clients.ToList())
+ {
+ try
+ {
+ RemoteJobProgress progress = new RemoteJobProgress();
+ progress.Stage = RemoteJobStage.Started;
+ progress.JobStatus = _handler.JobStatus;
+
+ await client.Receiver.SendGenericResponse(new RemoteJobUpdateResponse()
+ {
+ Job = jobDTO,
+ ProcessParameters = processParametersDTO,
+ Progress = progress
+ }, client.Token);
+
+ client.JobSent = true;
+ }
+ catch { }
+ }
+ }
+
+ private async void JobHandler_StatusChanged(object sender, RunningJobStatus e)
+ {
+ foreach (var client in _clients.ToList().Where(x => x.JobSent))
+ {
+ try
+ {
+ await client.Receiver.SendGenericResponse(new RemoteJobUpdateResponse()
+ {
+ Progress = GetJobProgress(_handler)
+ }, client.Token);
+ }
+ catch { }
+ }
+ }
+
+ private async void JobHandler_Stopped(object sender, EventArgs e)
+ {
+ foreach (var client in _clients.ToList().Where(x => x.JobSent))
+ {
+ try
+ {
+ await client.Receiver.SendGenericResponse(new RemoteJobUpdateResponse()
+ {
+ Progress = GetJobProgress(_handler),
+ }, client.Token);
+
+ client.JobSent = false;
+ }
+ catch { }
+ }
+ }
+
+ private RemoteJobProgress GetJobProgress(JobHandler handler)
+ {
+ RemoteJobStage stage = RemoteJobStage.Running;
+
+ if (_handler.Status.IsCanceled)
+ {
+ stage = RemoteJobStage.Aborted;
+ }
+ else if (_handler.Status.IsCompleted)
+ {
+ stage = RemoteJobStage.Completed;
+ }
+ else if (_handler.Status.IsFailed)
+ {
+ stage = RemoteJobStage.Failed;
+ }
+
+ return new RemoteJobProgress()
+ {
+ Stage = stage,
+ JobStatus = handler.JobStatus,
+ };
+ }
+
+ [ExternalBridgeRequestHandlerMethod(typeof(RemoteJobUpdateRequest), RequestHandlerLoggingMode.LogRequestName)]
+ public async Task OnRunningJobUpdateRequest(RemoteJobUpdateRequest request, String token, ExternalBridgeReceiver receiver)
+ {
+ this.ThrowIfDisabled();
+
+ if (!_clients.ToList().Exists(x => x.Receiver == receiver))
+ {
+ _clients.Add(new RunningJobUpdateClient()
+ {
+ Receiver = receiver,
+ Token = token
+ });
+ }
+
+ await receiver.SendGenericResponse(new RemoteJobUpdateResponse(), token);
+ }
+
+ public void OnReceiverDisconnected(ExternalBridgeReceiver receiver)
+ {
+ _clients.RemoveAll(x => x.Receiver == receiver);
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/IRemoteJobService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/IRemoteJobService.cs
new file mode 100644
index 000000000..e7bfdbec1
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteJob/IRemoteJobService.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Integration.ExternalBridge;
+
+namespace Tango.PPC.Common.RemoteJob
+{
+ public interface IRemoteJobService : IPPCService
+ {
+
+ }
+}
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 e97fd9d32..9bdba2c63 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
@@ -173,6 +173,8 @@
<Compile Include="RemoteDesktop\DefaultRemoteDesktopService.cs" />
<Compile Include="RemoteDesktop\IRemoteDesktopService.cs" />
<Compile Include="RemoteDesktop\RemoteDesktopClient.cs" />
+ <Compile Include="RemoteJob\DefaultRemoteJobService.cs" />
+ <Compile Include="RemoteJob\IRemoteJobService.cs" />
<Compile Include="Synchronization\DefaultMachineDataSynchronizer.cs" />
<Compile Include="Synchronization\IMachineDataSynchronizer.cs" />
<Compile Include="Synchronization\SynchronizationEndedEventArgs.cs" />
@@ -460,7 +462,7 @@
</Target>
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobProgress.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobProgress.cs
new file mode 100644
index 000000000..d91d612d1
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobProgress.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.PMR.Printing;
+
+namespace Tango.PPC.Shared.Jobs
+{
+ public class RemoteJobProgress
+ {
+ public RemoteJobStage Stage { get; set; }
+ public JobStatus JobStatus { get; set; }
+
+ public RemoteJobProgress()
+ {
+ JobStatus = new JobStatus();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobStage.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobStage.cs
new file mode 100644
index 000000000..5235b995b
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobStage.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Shared.Jobs
+{
+ public enum RemoteJobStage
+ {
+ None,
+ Started,
+ Running,
+ Failed,
+ Aborted,
+ Completed
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateRequest.cs
new file mode 100644
index 000000000..1322031ac
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateRequest.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Shared.Jobs
+{
+ public class RemoteJobUpdateRequest
+ {
+
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateResponse.cs
new file mode 100644
index 000000000..0bb32d266
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Jobs/RemoteJobUpdateResponse.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL.DTO;
+using Tango.Core;
+
+namespace Tango.PPC.Shared.Jobs
+{
+ public class RemoteJobUpdateResponse
+ {
+ public JobDTO Job { get; set; }
+ public ProcessParametersTableDTO ProcessParameters { get; set; }
+ public RemoteJobProgress Progress { get; set; }
+
+ public RemoteJobUpdateResponse()
+ {
+ Progress = new RemoteJobProgress();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj
index 153352c20..221cea81e 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj
@@ -60,6 +60,10 @@
<Compile Include="Information\GetMachineInformationRequest.cs" />
<Compile Include="Information\GetMachineInformationResponse.cs" />
<Compile Include="Information\InformationPackage.cs" />
+ <Compile Include="Jobs\RemoteJobProgress.cs" />
+ <Compile Include="Jobs\RemoteJobStage.cs" />
+ <Compile Include="Jobs\RemoteJobUpdateRequest.cs" />
+ <Compile Include="Jobs\RemoteJobUpdateResponse.cs" />
<Compile Include="Logs\GetLogFilesRequest.cs" />
<Compile Include="Logs\GetLogFilesResponse.cs" />
<Compile Include="Logs\RemoteLogFile.cs" />
@@ -107,6 +111,10 @@
<Project>{A34EE0F0-649D-41C8-8489-B6F1CC6924EE}</Project>
<Name>Tango.Core</Name>
</ProjectReference>
+ <ProjectReference Include="..\..\Tango.PMR\Tango.PMR.csproj">
+ <Project>{E4927038-348D-4295-AAF4-861C58CB3943}</Project>
+ <Name>Tango.PMR</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\Tango.SystemInfo\Tango.SystemInfo.csproj">
<Project>{997a961c-beda-4b56-aa0f-c39e532f7ffa}</Project>
<Name>Tango.SystemInfo</Name>
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs
index c146de51b..8b75b4517 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs
@@ -25,6 +25,7 @@ using Tango.PPC.Common.Performance;
using Tango.PPC.Common.Printing;
using Tango.PPC.Common.RemoteAssistance;
using Tango.PPC.Common.RemoteDesktop;
+using Tango.PPC.Common.RemoteJob;
using Tango.PPC.Common.Storage;
using Tango.PPC.Common.Synchronization;
using Tango.PPC.Common.SystemInfo;
@@ -88,6 +89,7 @@ namespace Tango.PPC.UI
TangoIOC.Default.Unregister<IPerformanceService>();
TangoIOC.Default.Unregister<ISystemInfoService>();
TangoIOC.Default.Unregister<IFileSystemService>();
+ TangoIOC.Default.Unregister<IRemoteJobService>();
if (App.StartupArgs.Contains("-webDebug"))
{
@@ -126,6 +128,7 @@ namespace Tango.PPC.UI
TangoIOC.Default.Register<ISystemInfoService, DefaultSystemInfoService>();
TangoIOC.Default.Register<IFileSystemService, DefaultFileSystemService>();
TangoIOC.Default.Register<IRemoteDesktopService, DefaultRemoteDesktopService>();
+ TangoIOC.Default.Register<IRemoteJobService, DefaultRemoteJobService>();
TangoIOC.Default.Register<LoadingViewVM>();
TangoIOC.Default.Register<MainViewVM>();