aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2019-02-20 12:22:27 +0200
committerAvi Levkovich <avi@twine-s.com>2019-02-20 12:22:27 +0200
commita576283d2a9288938796491582dd9f575f3ff571 (patch)
treebba67d4b69f337fa209b5050fb69378e28e6f4eb /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate
parentb30e6dc276f95c9db3d500d267a273b6486e0dac (diff)
parent9646611a494ed9e1ef0673c881ffc66b997f7bb9 (diff)
downloadTango-a576283d2a9288938796491582dd9f575f3ff571.tar.gz
Tango-a576283d2a9288938796491582dd9f575f3ff571.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateRequest.cs15
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateResponse.cs15
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DbCompareResult.cs1
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateRequest.cs14
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateResponse.cs19
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs12
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs60
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBRequest.cs14
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBResponse.cs15
9 files changed, 46 insertions, 119 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateRequest.cs
deleted file mode 100644
index cd5789393..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateRequest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Transport.Web;
-
-namespace Tango.PPC.Common.MachineUpdate
-{
- public class CheckForUpdateRequest : WebRequestMessage
- {
- public String SerialNumber { get; set; }
- public String Version { get; set; }
- }
-}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateResponse.cs
deleted file mode 100644
index cbf6c8c64..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateResponse.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Transport.Web;
-
-namespace Tango.PPC.Common.MachineUpdate
-{
- public class CheckForUpdateResponse : WebResponseMessage
- {
- public bool IsUpdateAvailable { get; set; }
- public String Version { get; set; }
- }
-}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DbCompareResult.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DbCompareResult.cs
index fbfc2e08c..3b4f59c9e 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DbCompareResult.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DbCompareResult.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR.Synchronization;
+using Tango.PPC.Common.Web;
namespace Tango.PPC.Common.MachineUpdate
{
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateRequest.cs
deleted file mode 100644
index 9369a2a94..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateRequest.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Transport.Web;
-
-namespace Tango.PPC.Common.MachineUpdate
-{
- public class DownloadUpdateRequest : WebRequestMessage
- {
- public String SerialNumber { get; set; }
- }
-}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateResponse.cs
deleted file mode 100644
index de978ed66..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateResponse.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Core;
-using Tango.Transport.Web;
-
-namespace Tango.PPC.Common.MachineUpdate
-{
- public class DownloadUpdateResponse : WebResponseMessage
- {
- public String Version { get; set; }
-
- public String BlobAddress { get; set; }
-
- public DataSource DataSource { get; set; }
- }
-}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs
index 08124154b..ffe3f6b5c 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PMR.Synchronization;
+using Tango.PPC.Common.Web;
namespace Tango.PPC.Common.MachineUpdate
{
@@ -25,32 +26,29 @@ namespace Tango.PPC.Common.MachineUpdate
/// Performs a machine update using the specified serial number and machine service address.
/// </summary>
/// <param name="serialNumber">The serial number.</param>
- /// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
- Task<MachineUpdateResult> Update(String serialNumber, String machineServiceAddress);
+ Task<MachineUpdateResult> Update(String serialNumber);
/// <summary>
/// Performs a machine update using the specified software update package path.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <returns></returns>
- Task<MachineUpdateResult> Update(String fileName);
+ Task<MachineUpdateResult> UpdateFromTUP(String fileName);
/// <summary>
/// Checks if any update are available for the specified machine serial number.
/// </summary>
/// <param name="serialNumber">The serial number.</param>
- /// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
- Task<CheckForUpdateResponse> CheckForUpdate(String serialNumber, String machineServiceAddress);
+ Task<CheckForUpdateResponse> CheckForUpdate(String serialNumber);
/// <summary>
/// Checks whether it is necessary to updates all the "overwrite-able" database tables.
/// </summary>
/// <param name="serialNumber">The serial number.</param>
- /// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
- Task<DbCompareResult> UpdateDBCheck(String serialNumber, String machineServiceAddress);
+ Task<DbCompareResult> UpdateDBCheck(String serialNumber);
/// <summary>
/// Updates all the "overwrite-able" database tables.
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
index 69df627fb..8b9aede87 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
@@ -17,6 +17,7 @@ using Tango.Integration.Operation;
using Tango.PMR.Synchronization;
using Tango.PPC.Common.Application;
using Tango.PPC.Common.Connection;
+using Tango.PPC.Common.Web;
using Tango.Settings;
using Tango.SharedUI.Helpers;
using Tango.SQLExaminer;
@@ -28,6 +29,7 @@ namespace Tango.PPC.Common.MachineUpdate
{
private IPPCApplicationManager _app_manager;
private IMachineProvider _machineProvider;
+ private PPCWebClient _client;
#region Events
@@ -60,14 +62,31 @@ namespace Tango.PPC.Common.MachineUpdate
/// Initializes a new instance of the <see cref="MachineUpdateManager"/> class.
/// </summary>
/// <param name="applicationManager">The application manager.</param>
- public MachineUpdateManager(IPPCApplicationManager applicationManager, IMachineProvider machineProvider)
+ public MachineUpdateManager(PPCWebClient ppcWebClient, IPPCApplicationManager applicationManager, IMachineProvider machineProvider)
{
+ _client = ppcWebClient;
_machineProvider = machineProvider;
_app_manager = applicationManager;
}
#endregion
+ #region Private Methods
+
+ private Task Login(String serialNumber)
+ {
+ return Task.Factory.StartNew(() =>
+ {
+ return _client.Login(new LoginRequest()
+ {
+ Mode = LoginMode.Machine,
+ SerialNumber = serialNumber,
+ }).Result;
+ });
+ }
+
+ #endregion
+
#region Public Methods
/// <summary>
@@ -76,12 +95,14 @@ namespace Tango.PPC.Common.MachineUpdate
/// <param name="serialNumber">The serial number.</param>
/// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
- public async Task<MachineUpdateResult> Update(string serialNumber, string machineServiceAddress)
+ public async Task<MachineUpdateResult> Update(string serialNumber)
{
TaskCompletionSource<MachineUpdateResult> result = new TaskCompletionSource<MachineUpdateResult>();
try
{
+ var machineServiceAddress = SettingsManager.Default.GetOrCreate<PPCSettings>().GetMachineServiceAddress();
+
LogManager.Log($"Starting machine update for serial number {serialNumber}...");
//Connecting to machine...
@@ -106,15 +127,13 @@ namespace Tango.PPC.Common.MachineUpdate
LogManager.Log($"Connecting to machine service on {machineServiceAddress}...");
+ await Login(serialNumber);
+
DownloadUpdateRequest request = new DownloadUpdateRequest();
- request.SerialNumber = serialNumber;
DownloadUpdateResponse update_response = null;
- using (var http = new WebTransportClient())
- {
- update_response = await http.PostJson<DownloadUpdateRequest, DownloadUpdateResponse>(machineServiceAddress + "/api/PPC/MachineUpdate", request);
- }
+ update_response = await _client.MachineUpdate(request);
LogManager.Log($"Machine update response received: {Environment.NewLine}{update_response.ToJsonString()}");
@@ -266,23 +285,24 @@ namespace Tango.PPC.Common.MachineUpdate
/// <param name="serialNumber">The serial number.</param>
/// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
- public Task<CheckForUpdateResponse> CheckForUpdate(string serialNumber, string machineServiceAddress)
+ public Task<CheckForUpdateResponse> CheckForUpdate(string serialNumber)
{
return Task.Factory.StartNew<CheckForUpdateResponse>(() =>
{
+ var machineServiceAddress = SettingsManager.Default.GetOrCreate<PPCSettings>().GetMachineServiceAddress();
+
LogManager.Log($"Connecting to machine service on {machineServiceAddress}...");
+
+ Login(serialNumber).Wait();
+
LogManager.Log($"Checking if updates available...");
CheckForUpdateRequest request = new CheckForUpdateRequest();
- request.SerialNumber = serialNumber;
request.Version = _app_manager.Version.ToString();
CheckForUpdateResponse update_response = null;
- using (var http = new WebTransportClient())
- {
- update_response = http.PostJson<CheckForUpdateRequest, CheckForUpdateResponse>(machineServiceAddress + "/api/PPC/CheckForUpdate", request).Result;
- }
+ update_response = _client.CheckForUpdate(request).Result;
LogManager.Log($"Check for update response received: {Environment.NewLine}{update_response.ToJsonString()}");
@@ -361,10 +381,12 @@ namespace Tango.PPC.Common.MachineUpdate
/// <param name="serialNumber">The serial number.</param>
/// <param name="machineServiceAddress">The machine service address.</param>
/// <returns></returns>
- public Task<DbCompareResult> UpdateDBCheck(string serialNumber, string machineServiceAddress)
+ public Task<DbCompareResult> UpdateDBCheck(string serialNumber)
{
return Task.Factory.StartNew<DbCompareResult>(() =>
{
+ var machineServiceAddress = SettingsManager.Default.GetOrCreate<PPCSettings>().GetMachineServiceAddress();
+
LogManager.Log($"Checking if database update is required for serial number {serialNumber}...");
LogManager.Log("Looking for OverrideData script on application path...");
@@ -383,15 +405,13 @@ namespace Tango.PPC.Common.MachineUpdate
LogManager.Log($"Connecting to machine service on {machineServiceAddress}...");
+ Login(serialNumber).Wait();
+
UpdateDBRequest request = new UpdateDBRequest();
- request.SerialNumber = serialNumber;
UpdateDBResponse update_response = null;
- using (var http = new WebTransportClient())
- {
- update_response = http.PostJson<UpdateDBRequest, UpdateDBResponse>(machineServiceAddress + "/api/PPC/UpdateDB", request).Result;
- }
+ update_response = _client.UpdateDB(request).Result;
LogManager.Log($"Update DB response received: {Environment.NewLine}{update_response.ToJsonString()}");
@@ -452,7 +472,7 @@ namespace Tango.PPC.Common.MachineUpdate
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <returns></returns>
- public Task<MachineUpdateResult> Update(string fileName)
+ public Task<MachineUpdateResult> UpdateFromTUP(string fileName)
{
return Task.Factory.StartNew<MachineUpdateResult>(() =>
{
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBRequest.cs
deleted file mode 100644
index 1d0caa5a9..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBRequest.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Transport.Web;
-
-namespace Tango.PPC.Common.MachineUpdate
-{
- public class UpdateDBRequest : WebRequestMessage
- {
- public String SerialNumber { get; set; }
- }
-}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBResponse.cs
deleted file mode 100644
index 36be14750..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBResponse.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Tango.Core;
-using Tango.Transport.Web;
-
-namespace Tango.PPC.Common.MachineUpdate
-{
- public class UpdateDBResponse : WebResponseMessage
- {
- public DataSource DataSource { get; set; }
- }
-}