diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-19 01:50:58 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-19 01:50:58 +0200 |
| commit | 9736b8c8ede6a0d121dea8381f0abb561fad5631 (patch) | |
| tree | 1c38f3f5be82b923ffae40fae00a25487179ab54 /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs | |
| parent | be3343cc0268179c7a6f628fa5e68f323a3335e5 (diff) | |
| download | Tango-9736b8c8ede6a0d121dea8381f0abb561fad5631.tar.gz Tango-9736b8c8ede6a0d121dea8381f0abb561fad5631.zip | |
Implemented auto generated web clients for PPC and machine studio.
Improved interactions with web clients across solutions.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs | 43 |
1 files changed, 15 insertions, 28 deletions
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 8661168b0..8b9aede87 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -29,6 +29,7 @@ namespace Tango.PPC.Common.MachineUpdate { private IPPCApplicationManager _app_manager; private IMachineProvider _machineProvider; + private PPCWebClient _client; #region Events @@ -61,8 +62,9 @@ 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; } @@ -71,18 +73,15 @@ namespace Tango.PPC.Common.MachineUpdate #region Private Methods - private Task<String> Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew<String>(() => + return Task.Factory.StartNew(() => { - using (var client = new PPCWebService()) + return _client.Login(new LoginRequest() { - return client.Login(new LoginRequest() - { - Mode = LoginMode.Machine, - SerialNumber = serialNumber, - }).Result.AccessToken; - } + Mode = LoginMode.Machine, + SerialNumber = serialNumber, + }).Result; }); } @@ -128,17 +127,13 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - String accessToken = await Login(serialNumber); + await Login(serialNumber); DownloadUpdateRequest request = new DownloadUpdateRequest(); - request.AccessToken = accessToken; DownloadUpdateResponse update_response = null; - using (var client = new PPCWebService()) - { - update_response = await client.MachineUpdate(request); - } + update_response = await _client.MachineUpdate(request); LogManager.Log($"Machine update response received: {Environment.NewLine}{update_response.ToJsonString()}"); @@ -298,20 +293,16 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - String accessToken = Login(serialNumber).Result; + Login(serialNumber).Wait(); LogManager.Log($"Checking if updates available..."); CheckForUpdateRequest request = new CheckForUpdateRequest(); - request.AccessToken = accessToken; request.Version = _app_manager.Version.ToString(); CheckForUpdateResponse update_response = null; - using (var client = new PPCWebService()) - { - update_response = client.CheckForUpdate(request).Result; - } + update_response = _client.CheckForUpdate(request).Result; LogManager.Log($"Check for update response received: {Environment.NewLine}{update_response.ToJsonString()}"); @@ -414,17 +405,13 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - String accessToken = Login(serialNumber).Result; + Login(serialNumber).Wait(); UpdateDBRequest request = new UpdateDBRequest(); - request.AccessToken = accessToken; UpdateDBResponse update_response = null; - using (var client = new PPCWebService()) - { - update_response = client.UpdateDB(request).Result; - } + update_response = _client.UpdateDB(request).Result; LogManager.Log($"Update DB response received: {Environment.NewLine}{update_response.ToJsonString()}"); |
