aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-02-18 16:58:37 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-02-18 16:58:37 +0200
commit473d878e3ae795201223b160fcbc1147e901b038 (patch)
treefaedd2a3fa181deb297ec2232a171289161738f7 /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate
parentccc6add5ea66565453283d7df0f6fbf2324b9264 (diff)
downloadTango-473d878e3ae795201223b160fcbc1147e901b038.tar.gz
Tango-473d878e3ae795201223b160fcbc1147e901b038.zip
Working on PPC versioning services...
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.cs62
-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, 55 insertions, 112 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..c19208724 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 String _accessToken;
#region Events
@@ -68,6 +70,27 @@ namespace Tango.PPC.Common.MachineUpdate
#endregion
+ #region Private Methods
+
+ private Task Login(String serialNumber)
+ {
+ return Task.Factory.StartNew(() =>
+ {
+ using (var client = new PPCWebService())
+ {
+ var response = client.Login(new LoginRequest()
+ {
+ Mode = LoginMode.Machine,
+ SerialNumber = serialNumber,
+ }).Result;
+
+ _accessToken = response.AccessToken;
+ }
+ });
+ }
+
+ #endregion
+
#region Public Methods
/// <summary>
@@ -76,12 +99,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,14 +131,16 @@ namespace Tango.PPC.Common.MachineUpdate
LogManager.Log($"Connecting to machine service on {machineServiceAddress}...");
+ await Login(serialNumber);
+
DownloadUpdateRequest request = new DownloadUpdateRequest();
- request.SerialNumber = serialNumber;
+ request.AccessToken = _accessToken;
DownloadUpdateResponse update_response = null;
- using (var http = new WebTransportClient())
+ using (var client = new PPCWebService())
{
- 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,22 +293,27 @@ 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.AccessToken = _accessToken;
request.Version = _app_manager.Version.ToString();
CheckForUpdateResponse update_response = null;
- using (var http = new WebTransportClient())
+ using (var client = new PPCWebService())
{
- 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 +393,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,14 +417,16 @@ namespace Tango.PPC.Common.MachineUpdate
LogManager.Log($"Connecting to machine service on {machineServiceAddress}...");
+ Login(serialNumber).Wait();
+
UpdateDBRequest request = new UpdateDBRequest();
- request.SerialNumber = serialNumber;
+ request.AccessToken = _accessToken;
UpdateDBResponse update_response = null;
- using (var http = new WebTransportClient())
+ using (var client = new PPCWebService())
{
- 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 +488,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; }
- }
-}