From 473d878e3ae795201223b160fcbc1147e901b038 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 18 Feb 2019 16:58:37 +0200 Subject: Working on PPC versioning services... --- .../MachineUpdate/CheckForUpdateRequest.cs | 15 ------ .../MachineUpdate/CheckForUpdateResponse.cs | 15 ------ .../MachineUpdate/DbCompareResult.cs | 1 + .../MachineUpdate/DownloadUpdateRequest.cs | 14 ----- .../MachineUpdate/DownloadUpdateResponse.cs | 19 ------- .../MachineUpdate/IMachineUpdateManager.cs | 12 ++--- .../MachineUpdate/MachineUpdateManager.cs | 62 +++++++++++++++++----- .../MachineUpdate/UpdateDBRequest.cs | 14 ----- .../MachineUpdate/UpdateDBResponse.cs | 15 ------ 9 files changed, 55 insertions(+), 112 deletions(-) delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateRequest.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/CheckForUpdateResponse.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateRequest.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/DownloadUpdateResponse.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBRequest.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/UpdateDBResponse.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate') 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. /// /// The serial number. - /// The machine service address. /// - Task Update(String serialNumber, String machineServiceAddress); + Task Update(String serialNumber); /// /// Performs a machine update using the specified software update package path. /// /// Name of the file. /// - Task Update(String fileName); + Task UpdateFromTUP(String fileName); /// /// Checks if any update are available for the specified machine serial number. /// /// The serial number. - /// The machine service address. /// - Task CheckForUpdate(String serialNumber, String machineServiceAddress); + Task CheckForUpdate(String serialNumber); /// /// Checks whether it is necessary to updates all the "overwrite-able" database tables. /// /// The serial number. - /// The machine service address. /// - Task UpdateDBCheck(String serialNumber, String machineServiceAddress); + Task UpdateDBCheck(String serialNumber); /// /// 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 /// @@ -76,12 +99,14 @@ namespace Tango.PPC.Common.MachineUpdate /// The serial number. /// The machine service address. /// - public async Task Update(string serialNumber, string machineServiceAddress) + public async Task Update(string serialNumber) { TaskCompletionSource result = new TaskCompletionSource(); try { + var machineServiceAddress = SettingsManager.Default.GetOrCreate().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(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 /// The serial number. /// The machine service address. /// - public Task CheckForUpdate(string serialNumber, string machineServiceAddress) + public Task CheckForUpdate(string serialNumber) { return Task.Factory.StartNew(() => { + var machineServiceAddress = SettingsManager.Default.GetOrCreate().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(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 /// The serial number. /// The machine service address. /// - public Task UpdateDBCheck(string serialNumber, string machineServiceAddress) + public Task UpdateDBCheck(string serialNumber) { return Task.Factory.StartNew(() => { + var machineServiceAddress = SettingsManager.Default.GetOrCreate().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(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 /// /// Name of the file. /// - public Task Update(string fileName) + public Task UpdateFromTUP(string fileName) { return Task.Factory.StartNew(() => { 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; } - } -} -- cgit v1.3.1