From ccc6add5ea66565453283d7df0f6fbf2324b9264 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 18 Feb 2019 13:21:20 +0200 Subject: Refactored machine studio service. --- .../Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs | 2 +- .../MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs | 4 ++-- .../Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 283ea3637..e55d0534e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -17,7 +17,7 @@ using Tango.MachineStudio.Common.EventLogging; using Tango.BL.Enumerations; using Tango.MachineStudio.UI.TFS; using Tango.MachineStudio.Common; -using Tango.MachineStudio.Common.Update; +using Tango.MachineStudio.Common.Web; using Tango.Core.DI; using Tango.Settings; using Tango.Core; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 1d03dd389..64043e556 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -27,7 +27,7 @@ using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.Speech; using Tango.MachineStudio.Common.StudioApplication; -using Tango.MachineStudio.Common.Update; +using Tango.MachineStudio.Common.Web; using Tango.MachineStudio.UI.StudioApplication; using Tango.MachineStudio.UI.SupervisingController; using Tango.MachineStudio.UI.TFS; @@ -357,7 +357,7 @@ namespace Tango.MachineStudio.UI.ViewModels { if (_authenticationProvider.CurrentUser != null) { - var client = new MachineStudioUpdateService(); + var client = new MachineStudioService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 63cff2242..8d4553e32 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -19,12 +19,13 @@ using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; -using Tango.MachineStudio.Common.Update; +using Tango.MachineStudio.Common.Web; using Tango.SharedUI; using Tango.MachineStudio.UI.Messages; using Tango.Settings; using Tango.MachineStudio.Common; using Tango.Transport.Web; +using Tango.MachineStudio.Common.Web; namespace Tango.MachineStudio.UI.ViewModels { @@ -168,7 +169,7 @@ namespace Tango.MachineStudio.UI.ViewModels Status = UpdateStatus.CheckingForUpdate; - var client = new MachineStudioUpdateService(); + var client = new MachineStudioService(); DownloadLatestVersionResponse response = await client.DownloadLatestVersion(new DownloadLatestVersionRequest() { @@ -215,7 +216,7 @@ namespace Tango.MachineStudio.UI.ViewModels { Thread.Sleep(2000); - var client = new MachineStudioUpdateService(); + var client = new MachineStudioService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { -- cgit v1.3.1 From 45829a9fb6f4b0d4443e22c972cf8543be533d4e Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 18 Feb 2019 18:16:24 +0200 Subject: Working on Tokens Manager. --- .../Publish/MachineStudioPublisher.cs | 4 +- .../Tango.MachineStudio.Common.csproj | 4 +- .../Web/IMachineStudioService.cs | 28 --------- .../Web/IMachineStudioWebService.cs | 28 +++++++++ .../Web/MachineStudioService.cs | 60 -------------------- .../Web/MachineStudioWebService.cs | 60 ++++++++++++++++++++ .../DefaultAuthenticationProvider.cs | 2 +- .../ViewModels/MainViewVM.cs | 2 +- .../ViewModels/UpdateViewVM.cs | 4 +- .../MachineSetup/MachineSetupManager.cs | 15 ++--- .../MachineUpdate/MachineUpdateManager.cs | 23 ++++---- .../Tango.UnitTesting/MachineService_TST.cs | 64 +++++++++++++++++++++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 7 ++- .../Tango.Web/Authentication/TokensManager.cs | 66 +++++++++++++++++++--- .../Controllers/MachineStudioController.cs | 2 +- .../Controllers/PPCController.cs | 11 +++- 16 files changed, 249 insertions(+), 131 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs create mode 100644 Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs index 19f186525..b9a50ec73 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs @@ -18,7 +18,7 @@ namespace Tango.MachineStudio.Common.Publish { public class MachineStudioPublisher : ExtendedObject { - private IMachineStudioService _client; + private IMachineStudioWebService _client; /// /// Occurs on publish progress. @@ -40,7 +40,7 @@ namespace Tango.MachineStudio.Common.Publish /// public MachineStudioPublisher() { - _client = new MachineStudioService(); + _client = new MachineStudioWebService(); Options = new PublishOptions(); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 40d7da460..d5e62f4e1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -134,10 +134,10 @@ - + - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs deleted file mode 100644 index 748df4644..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.ServiceModel; -using System.Text; -using System.Threading.Tasks; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public interface IMachineStudioService - { - DeploymentSlot Environment { get; set; } - - Task CheckForUpdates(CheckForUpdatesRequest request); - - Task DownloadLatestVersion(DownloadLatestVersionRequest request); - - Task UploadVersion(UploadVersionRequest request); - - Task NotifyUploadCompleted(UploadCompletedRequest request); - - Task GetLatestVersion(LatestVersionRequest request); - - Task Login(LoginRequest request); - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs new file mode 100644 index 000000000..5a89f688f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.ServiceModel; +using System.Text; +using System.Threading.Tasks; +using Tango.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public interface IMachineStudioWebService + { + DeploymentSlot Environment { get; set; } + + Task CheckForUpdates(CheckForUpdatesRequest request); + + Task DownloadLatestVersion(DownloadLatestVersionRequest request); + + Task UploadVersion(UploadVersionRequest request); + + Task NotifyUploadCompleted(UploadCompletedRequest request); + + Task GetLatestVersion(LatestVersionRequest request); + + Task Login(LoginRequest request); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs deleted file mode 100644 index 8b43146e1..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.MachineStudio.Common.Authentication; -using Tango.Settings; -using Tango.Transport.Web; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public class MachineStudioService : IMachineStudioService - { - private WebTransportClient _client; - - public DeploymentSlot Environment { get; set; } - - public MachineStudioService() - { - Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; - _client = new WebTransportClient(); - } - - public Task CheckForUpdates(CheckForUpdatesRequest request) - { - return _client.PostJson(GetAddress() + "CheckForUpdates", request); - } - - public Task UploadVersion(UploadVersionRequest request) - { - return _client.PostJson(GetAddress() + "UploadVersion", request); - } - - public Task NotifyUploadCompleted(UploadCompletedRequest request) - { - return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); - } - - public Task GetLatestVersion(LatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "GetLatestVersion", request); - } - - public Task DownloadLatestVersion(DownloadLatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "DownloadLatestVersion", request); - } - - public Task Login(LoginRequest request) - { - return _client.PostJson(GetAddress() + "Login", request); - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/MachineStudio/"; - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs new file mode 100644 index 000000000..d0aa8a5bf --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.MachineStudio.Common.Authentication; +using Tango.Settings; +using Tango.Transport.Web; +using Tango.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class MachineStudioWebService : IMachineStudioWebService + { + private WebTransportClient _client; + + public DeploymentSlot Environment { get; set; } + + public MachineStudioWebService() + { + Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; + _client = new WebTransportClient(); + } + + public Task CheckForUpdates(CheckForUpdatesRequest request) + { + return _client.PostJson(GetAddress() + "CheckForUpdates", request); + } + + public Task UploadVersion(UploadVersionRequest request) + { + return _client.PostJson(GetAddress() + "UploadVersion", request); + } + + public Task NotifyUploadCompleted(UploadCompletedRequest request) + { + return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); + } + + public Task GetLatestVersion(LatestVersionRequest request) + { + return _client.PostJson(GetAddress() + "GetLatestVersion", request); + } + + public Task DownloadLatestVersion(DownloadLatestVersionRequest request) + { + return _client.PostJson(GetAddress() + "DownloadLatestVersion", request); + } + + public Task Login(LoginRequest request) + { + return _client.PostJson(GetAddress() + "Login", request); + } + + private String GetAddress() + { + return Environment.ToAddress() + "/api/MachineStudio/"; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index 1f9aee937..d81f0d561 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -57,7 +57,7 @@ namespace Tango.MachineStudio.UI.Authentication { var settings = SettingsManager.Default.GetOrCreate(); - IMachineStudioService service = new MachineStudioService(); + IMachineStudioWebService service = new MachineStudioWebService(); var response = service.Login(new LoginRequest() { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 64043e556..56ebb1e00 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -357,7 +357,7 @@ namespace Tango.MachineStudio.UI.ViewModels { if (_authenticationProvider.CurrentUser != null) { - var client = new MachineStudioService(); + var client = new MachineStudioWebService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 8d4553e32..57043df0e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -169,7 +169,7 @@ namespace Tango.MachineStudio.UI.ViewModels Status = UpdateStatus.CheckingForUpdate; - var client = new MachineStudioService(); + var client = new MachineStudioWebService(); DownloadLatestVersionResponse response = await client.DownloadLatestVersion(new DownloadLatestVersionRequest() { @@ -216,7 +216,7 @@ namespace Tango.MachineStudio.UI.ViewModels { Thread.Sleep(2000); - var client = new MachineStudioService(); + var client = new MachineStudioWebService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index b5140e336..256804f67 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -40,7 +40,6 @@ namespace Tango.PPC.Common.MachineSetup private IRemoteAssistanceProvider _remoteAssistance; private IUnifiedWriteFilterManager _uwf; private IOperationSystemManager _windows_manager; - private String _accessToken; #region Events @@ -84,19 +83,17 @@ namespace Tango.PPC.Common.MachineSetup #region Private Methods - private Task Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { using (var client = new PPCWebService()) { - var response = client.Login(new LoginRequest() + return client.Login(new LoginRequest() { Mode = LoginMode.Machine, SerialNumber = serialNumber, - }).Result; - - _accessToken = response.AccessToken; + }).Result.AccessToken; } }); } @@ -128,10 +125,10 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - await Login(serialNumber); + var accessToken = await Login(serialNumber); MachineSetupRequest request = new MachineSetupRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; MachineSetupResponse setup_response = null; 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 c19208724..8661168b0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -29,7 +29,6 @@ namespace Tango.PPC.Common.MachineUpdate { private IPPCApplicationManager _app_manager; private IMachineProvider _machineProvider; - private String _accessToken; #region Events @@ -72,19 +71,17 @@ namespace Tango.PPC.Common.MachineUpdate #region Private Methods - private Task Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { using (var client = new PPCWebService()) { - var response = client.Login(new LoginRequest() + return client.Login(new LoginRequest() { Mode = LoginMode.Machine, SerialNumber = serialNumber, - }).Result; - - _accessToken = response.AccessToken; + }).Result.AccessToken; } }); } @@ -131,10 +128,10 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - await Login(serialNumber); + String accessToken = await Login(serialNumber); DownloadUpdateRequest request = new DownloadUpdateRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; DownloadUpdateResponse update_response = null; @@ -301,12 +298,12 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - Login(serialNumber).Wait(); + String accessToken = Login(serialNumber).Result; LogManager.Log($"Checking if updates available..."); CheckForUpdateRequest request = new CheckForUpdateRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; request.Version = _app_manager.Version.ToString(); CheckForUpdateResponse update_response = null; @@ -417,10 +414,10 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - Login(serialNumber).Wait(); + String accessToken = Login(serialNumber).Result; UpdateDBRequest request = new UpdateDBRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; UpdateDBResponse update_response = null; diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs new file mode 100644 index 000000000..ca1653e3e --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs @@ -0,0 +1,64 @@ +using System; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.Web.Authentication; + +namespace Tango.UnitTesting +{ + [TestClass] + [TestCategory("Machine Service")] + public class MachineService_TST + { + private class TokenObject : IEquatable + { + public String Value { get; set; } + + public bool Equals(TokenObject other) + { + return Value == other.Value; + } + } + + [TestMethod] + public void Test_Tokens_Manager() + { + TokensManager tokensManager = new TokensManager(); + + TokenObject t1 = new TokenObject(); + t1.Value = "Roy"; + + TokenObject t2 = new TokenObject(); + t2.Value = "Sagi"; + + String token1 = tokensManager.GetOrCreate(t1); + String token2 = tokensManager.GetOrCreate(t2); + + Assert.AreEqual(tokensManager.GetTokenObject(token1), t1); + Assert.AreEqual(tokensManager.GetTokenObject(token2), t2); + + TokenObject t3 = new TokenObject(); + t3.Value = "Roy"; + + String token3 = tokensManager.GetOrCreate(t3); + Assert.AreEqual(token3, token1); + Assert.AreEqual(tokensManager.GetTokenObject(token1), tokensManager.GetTokenObject(token3)); + + TokenObject tOld = new TokenObject() + { + Value = "Expired Token" + }; + + tokensManager.ExpirationTime = TimeSpan.FromSeconds(2); + + Thread.Sleep(2000); + + String recent_token = tokensManager.GetOrCreate(tOld); + + Thread.Sleep(1000); + + Assert.IsTrue(tokensManager.Exists(recent_token)); + + Assert.IsFalse(tokensManager.Exists(token1)); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index fa4652899..9ebc45dfc 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -107,6 +107,7 @@ + @@ -193,6 +194,10 @@ {74e700b0-1156-4126-be40-ee450d3c3026} Tango.Transport + + {5001990f-977b-48ff-b217-0236a5022ad8} + Tango.Web + {ebb7cb9f-6af2-456b-a5dd-1b136b605d90} Tango.DBObservablesGenerator.CLI @@ -212,7 +217,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs index 701a87a3c..8e0eb4288 100644 --- a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs +++ b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs @@ -7,35 +7,85 @@ using System.Threading.Tasks; namespace Tango.Web.Authentication { - public class TokensManager + public class TokensManager where T : IEquatable { - private Dictionary _tokens; + private Dictionary _tokens; + + private class TokenWrapper : IEquatable + { + public DateTime Date { get; set; } + + public T Value { get; set; } + + public bool Equals(TokenWrapper other) + { + return Value.Equals(other.Value); + } + } public TokensManager() { - _tokens = new Dictionary(); + _tokens = new Dictionary(); + ExpirationTime = TimeSpan.FromHours(1); } - public String CreateNew(T userID) + public TimeSpan ExpirationTime { get; set; } + + public String GetOrCreate(T tokenObject) { - String token = Guid.NewGuid().ToString(); - _tokens.Add(token, userID); - return token; + var existing_token = _tokens.FirstOrDefault(x => x.Value.Value.Equals(tokenObject)); + + if (existing_token.Key != null) + { + return existing_token.Key; + } + else + { + String token = Guid.NewGuid().ToString(); + _tokens.Add(token, new TokenWrapper() + { + Value = tokenObject, + Date = DateTime.Now, + }); + return token; + } } public bool Exists(String token) { + RemoveOrRenewExpired(token); + return _tokens.ContainsKey(token); } public T GetTokenObject(String token) { + RemoveOrRenewExpired(token); + if (!_tokens.ContainsKey(token)) { throw new AuthenticationException("Invalid token."); } - return _tokens[token]; + return _tokens[token].Value; + } + + private void RemoveOrRenewExpired(String token) + { + DateTime now = DateTime.Now; + + if (_tokens.ContainsKey(token)) + { + _tokens[token].Date = now; + } + + foreach (var t in _tokens.ToList()) + { + if (now > t.Value.Date.Add(ExpirationTime)) + { + _tokens.Remove(t.Key); + } + } } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 142980fdd..98ea8d827 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -347,7 +347,7 @@ namespace Tango.MachineService.Controllers Password = request.Password, }, - AccessToken = TokensManager.CreateNew(user.Guid), + AccessToken = TokensManager.GetOrCreate(user.Guid), VersionChangeRequired = versionChangeRequired, RequiredVersion = requiredVersion, }; diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index af861923c..064a44fdb 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -31,11 +31,16 @@ namespace Tango.MachineService.Controllers private static List _pendingUploads; private ActiveDirectoryManager _ad_manager; - public class TokenObject + public class TokenObject : IEquatable { public LoginMode Mode { get; set; } public String UserGuid { get; set; } public String MachineGuid { get; set; } + + public bool Equals(TokenObject other) + { + return UserGuid == other.UserGuid || MachineGuid == MachineGuid; + } } public static TokensManager TokensManager { get; set; } @@ -434,7 +439,7 @@ namespace Tango.MachineService.Controllers throw new AuthenticationException("Domain user found but the database entry validation failed."); } - response.AccessToken = TokensManager.CreateNew(new TokenObject() + response.AccessToken = TokensManager.GetOrCreate(new TokenObject() { Mode = LoginMode.User, UserGuid = user.Guid, @@ -449,7 +454,7 @@ namespace Tango.MachineService.Controllers throw new AuthenticationException("Invalid serial number."); } - response.AccessToken = TokensManager.CreateNew(new TokenObject() + response.AccessToken = TokensManager.GetOrCreate(new TokenObject() { Mode = LoginMode.Machine, UserGuid = machine.Guid, -- cgit v1.3.1 From 9736b8c8ede6a0d121dea8381f0abb561fad5631 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 19 Feb 2019 01:50:58 +0200 Subject: Implemented auto generated web clients for PPC and machine studio. Improved interactions with web clients across solutions. --- .../Build/Shortcuts/Machine Emulator.lnk | Bin 1445 -> 1530 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1581 bytes .../Build/Shortcuts/Proto Compiler GUI.lnk | Bin 1444 -> 1529 bytes .../Build/Shortcuts/Stubs Execution GUI.lnk | Bin 1462 -> 1547 bytes .../Build/Shortcuts/Transport Router.lnk | Bin 1493 -> 1578 bytes .../Authentication/IAuthenticationProvider.cs | 5 - .../Publish/MachineStudioPublisher.cs | 15 +-- .../Tango.MachineStudio.Common.csproj | 6 +- .../Web/IMachineStudioWebService.cs | 28 ---- .../Web/LoginResponse.cs | 4 +- .../Web/MachineStudioWebClient.cs | 33 +++++ .../Web/MachineStudioWebClientBase.cs | 79 ++++++++++++ .../Web/MachineStudioWebService.cs | 60 --------- .../DefaultAuthenticationProvider.cs | 23 ++-- .../Tango.MachineStudio.UI/ViewModelLocator.cs | 3 + .../ViewModels/LoginViewVM.cs | 5 +- .../ViewModels/MainViewVM.cs | 10 +- .../ViewModels/UpdateViewVM.cs | 20 ++- .../MachineSetup/IMachineSetupManager.cs | 3 +- .../MachineSetup/MachineSetupManager.cs | 32 +++-- .../MachineUpdate/MachineUpdateManager.cs | 43 +++---- .../PPC/Tango.PPC.Common/Publish/PPCPublisher.cs | 15 +-- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 6 +- .../PPC/Tango.PPC.Common/Web/IPPCWebService.cs | 85 ------------- .../PPC/Tango.PPC.Common/Web/LoginResponse.cs | 5 +- .../PPC/Tango.PPC.Common/Web/PPCWebClient.cs | 30 +++++ .../PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs | 106 ++++++++++++++++ .../PPC/Tango.PPC.Common/Web/PPCWebService.cs | 79 ------------ .../PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs | 6 +- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 3 + .../Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 10 +- .../Tango.CodeGeneration.csproj | 4 +- .../Tango.CodeGeneration/TangoWebClientCodeFile.cs | 30 +++++ .../Templates/TangoWebClientCodeFile.cshtml | 51 ++++++++ .../Visual_Studio/Tango.Core/Helpers/PathHelper.cs | 16 +++ .../Tango.Transport/Tango.Transport.csproj | 3 +- .../Tango.Transport/Web/SessionExpiredException.cs | 16 +++ .../Tango.Transport/Web/WebTransportClient.cs | 9 +- .../Tango.UnitTesting/MachineService_TST.cs | 13 +- .../Tango.Web/Authentication/TokensManager.cs | 49 +++---- .../Tango.Web/Authentication/WebToken.cs | 14 ++ .../Tango.Web/Authentication/WebTokenResponse.cs | 14 ++ Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 7 + Software/Visual_Studio/Tango.Web/TangoWebClient.cs | 141 +++++++++++++++++++++ Software/Visual_Studio/Tango.sln | 55 +++++++- .../Utilities/Tango.WebClientGenerator/App.config | 78 ++++++++++++ .../Utilities/Tango.WebClientGenerator/Program.cs | 49 +++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../Tango.WebClientGenerator.csproj | 86 +++++++++++++ .../Tango.WebClientGenerator/packages.config | 4 + .../Controllers/MachineStudioController.cs | 2 +- .../Controllers/PPCController.cs | 4 +- .../Filters/MachineStudioLoginFilter.cs | 8 +- .../Tango.MachineService/Filters/PPCLoginFilter.cs | 8 +- 54 files changed, 994 insertions(+), 417 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/TangoWebClientCodeFile.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/TangoWebClientCodeFile.cshtml create mode 100644 Software/Visual_Studio/Tango.Transport/Web/SessionExpiredException.cs create mode 100644 Software/Visual_Studio/Tango.Web/Authentication/WebToken.cs create mode 100644 Software/Visual_Studio/Tango.Web/Authentication/WebTokenResponse.cs create mode 100644 Software/Visual_Studio/Tango.Web/TangoWebClient.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/App.config create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Tango.WebClientGenerator.csproj create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/packages.config (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 43aace6b5..d95642721 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 4d317d343..1550b6e18 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk index 1be399f50..72ad667d8 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk index db7f7c338..5258be2c6 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk b/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk index 6f0433af2..73b23b4ce 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk and b/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs index 7cc2b5b51..4958cb0f4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs @@ -12,11 +12,6 @@ namespace Tango.MachineStudio.Common.Authentication /// public interface IAuthenticationProvider { - /// - /// Gets the access token that was retrieved at the last login. - /// - String AccessToken { get; } - /// /// Occurs when the current logged-in user has changed. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs index b9a50ec73..dfbe0adc6 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs @@ -18,7 +18,7 @@ namespace Tango.MachineStudio.Common.Publish { public class MachineStudioPublisher : ExtendedObject { - private IMachineStudioWebService _client; + private MachineStudioWebClient _client; /// /// Occurs on publish progress. @@ -40,7 +40,7 @@ namespace Tango.MachineStudio.Common.Publish /// public MachineStudioPublisher() { - _client = new MachineStudioWebService(); + _client = new MachineStudioWebClient(); Options = new PublishOptions(); } @@ -98,16 +98,16 @@ namespace Tango.MachineStudio.Common.Publish /// Login to machine service and returns an access token. /// /// - private Task Login() + private Task Login() { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { return _client.Login(new LoginRequest() { Email = Options.Email, Password = Options.Password, Version = GetLocalVersion(), - }).Result.AccessToken; + }).Result; }); } @@ -121,7 +121,6 @@ namespace Tango.MachineStudio.Common.Publish String appPath = GetMachineStudioExecutablePath(); String folder = Options.GetApplicationPath(); - String accessToken = String.Empty; if (!File.Exists(appPath)) { @@ -135,7 +134,7 @@ namespace Tango.MachineStudio.Common.Publish try { OnPublishProgress(0, 100, $"Logging in to machine service at {Options.Environment.ToAddress()}..."); - accessToken = Login().Result; + Login().Wait(); OnPublishProgress(0, 100, $"Fetching remote version from {Options.Environment.ToAddress()}..."); @@ -154,7 +153,6 @@ namespace Tango.MachineStudio.Common.Publish var response = _client.UploadVersion(new UploadVersionRequest() { - AccessToken = accessToken, Version = local_version, Comments = Options.Comments, }).Result; @@ -200,7 +198,6 @@ namespace Tango.MachineStudio.Common.Publish _client.NotifyUploadCompleted(new UploadCompletedRequest() { - AccessToken = accessToken, Token = response.Token, }).Wait(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index d5e62f4e1..48c78e865 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -134,10 +134,10 @@ - - + + @@ -326,7 +326,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs deleted file mode 100644 index 5a89f688f..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.ServiceModel; -using System.Text; -using System.Threading.Tasks; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public interface IMachineStudioWebService - { - DeploymentSlot Environment { get; set; } - - Task CheckForUpdates(CheckForUpdatesRequest request); - - Task DownloadLatestVersion(DownloadLatestVersionRequest request); - - Task UploadVersion(UploadVersionRequest request); - - Task NotifyUploadCompleted(UploadCompletedRequest request); - - Task GetLatestVersion(LatestVersionRequest request); - - Task Login(LoginRequest request); - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs index 643e3930d..78c7bc560 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs @@ -5,13 +5,13 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Transport.Web; +using Tango.Web.Authentication; namespace Tango.MachineStudio.Common.Web { - public class LoginResponse : WebResponseMessage + public class LoginResponse : WebTokenResponse { public DataSource DataSource { get; set; } - public String AccessToken { get; set; } public bool VersionChangeRequired { get; set; } public String RequiredVersion { get; set; } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs new file mode 100644 index 000000000..02276d641 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.MachineStudio.Common.Web +{ + public class MachineStudioWebClient : MachineStudioWebClientBase + { + public MachineStudioWebClient(DeploymentSlot environment) : base(environment) + { + } + + public MachineStudioWebClient(DeploymentSlot environment, WebToken token) : base(environment, token) + { + + } + + public MachineStudioWebClient(WebToken token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) + { + + } + + public MachineStudioWebClient() : this(null) + { + + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs new file mode 100644 index 000000000..dc5a14856 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs @@ -0,0 +1,79 @@ + +using System.Threading.Tasks; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.MachineStudio.Common.Web +{ + /// + /// Represents a machine service MachineStudio web client. + /// + /// + public abstract class MachineStudioWebClientBase : TangoWebClient + { + /// + /// Initializes a new instance of the class. + /// + /// The environment. + /// Existing token. + public MachineStudioWebClientBase(DeploymentSlot environment, WebToken token) : base(environment, "MachineStudio", token) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The environment. + public MachineStudioWebClientBase(DeploymentSlot environment) : this(environment, null) + { + + } + + /// + /// Executes the CheckForUpdates action and returns Tango.MachineStudio.Common.Web.CheckForUpdatesResponse. + /// + /// + public Task CheckForUpdates(Tango.MachineStudio.Common.Web.CheckForUpdatesRequest request) + { + return Post("CheckForUpdates", request); + } + + /// + /// Executes the DownloadLatestVersion action and returns Tango.MachineStudio.Common.Web.DownloadLatestVersionResponse. + /// + /// + public Task DownloadLatestVersion(Tango.MachineStudio.Common.Web.DownloadLatestVersionRequest request) + { + return Post("DownloadLatestVersion", request); + } + + /// + /// Executes the UploadVersion action and returns Tango.MachineStudio.Common.Web.UploadVersionResponse. + /// + /// + public Task UploadVersion(Tango.MachineStudio.Common.Web.UploadVersionRequest request) + { + return Post("UploadVersion", request); + } + + /// + /// Executes the NotifyUploadCompleted action and returns Tango.MachineStudio.Common.Web.UploadCompletedResponse. + /// + /// + public Task NotifyUploadCompleted(Tango.MachineStudio.Common.Web.UploadCompletedRequest request) + { + return Post("NotifyUploadCompleted", request); + } + + /// + /// Executes the GetLatestVersion action and returns Tango.MachineStudio.Common.Web.LatestVersionResponse. + /// + /// + public Task GetLatestVersion(Tango.MachineStudio.Common.Web.LatestVersionRequest request) + { + return Post("GetLatestVersion", request); + } + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs deleted file mode 100644 index d0aa8a5bf..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.MachineStudio.Common.Authentication; -using Tango.Settings; -using Tango.Transport.Web; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public class MachineStudioWebService : IMachineStudioWebService - { - private WebTransportClient _client; - - public DeploymentSlot Environment { get; set; } - - public MachineStudioWebService() - { - Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; - _client = new WebTransportClient(); - } - - public Task CheckForUpdates(CheckForUpdatesRequest request) - { - return _client.PostJson(GetAddress() + "CheckForUpdates", request); - } - - public Task UploadVersion(UploadVersionRequest request) - { - return _client.PostJson(GetAddress() + "UploadVersion", request); - } - - public Task NotifyUploadCompleted(UploadCompletedRequest request) - { - return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); - } - - public Task GetLatestVersion(LatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "GetLatestVersion", request); - } - - public Task DownloadLatestVersion(DownloadLatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "DownloadLatestVersion", request); - } - - public Task Login(LoginRequest request) - { - return _client.PostJson(GetAddress() + "Login", request); - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/MachineStudio/"; - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index d81f0d561..e07952f29 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -26,6 +26,8 @@ namespace Tango.MachineStudio.UI.Authentication /// public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider { + private MachineStudioWebClient _client; + private User _currentUser; /// /// Gets the current logged-in user. @@ -46,6 +48,15 @@ namespace Tango.MachineStudio.UI.Authentication /// public event EventHandler CurrentUserChanged; + /// + /// Initializes a new instance of the class. + /// + /// The machine studio web client. + public DefaultAuthenticationProvider(MachineStudioWebClient machineStudioWebClient) + { + _client = machineStudioWebClient; + } + /// /// Performs a user login by the specified email and password. /// @@ -57,9 +68,8 @@ namespace Tango.MachineStudio.UI.Authentication { var settings = SettingsManager.Default.GetOrCreate(); - IMachineStudioWebService service = new MachineStudioWebService(); - - var response = service.Login(new LoginRequest() + _client.Environment = settings.DeploymentSlot; + var response = _client.Login(new LoginRequest() { Email = email, @@ -68,8 +78,6 @@ namespace Tango.MachineStudio.UI.Authentication }).Result; - AccessToken = response.AccessToken; - if (settings.Environment == MachineStudioSettings.WorkingEnvironment.Remote) { ObservablesContext.OverrideSettingsDataSource(response.DataSource); @@ -114,10 +122,5 @@ namespace Tango.MachineStudio.UI.Authentication { CurrentUser = null; } - - /// - /// Gets the access token that was retrieved at the last login. - /// - public string AccessToken { get; private set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index b0a3a8c11..7fbb0008c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -14,6 +14,7 @@ using Tango.MachineStudio.Common.Speech; using Tango.MachineStudio.Common.StudioApplication; using Tango.MachineStudio.Common.Threading; using Tango.MachineStudio.Common.Video; +using Tango.MachineStudio.Common.Web; using Tango.MachineStudio.UI.Authentication; using Tango.MachineStudio.UI.Console; using Tango.MachineStudio.UI.FirmwareUpgrade; @@ -68,8 +69,10 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); + TangoIOC.Default.Register(new MachineStudioWebClient()); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index 8b3747584..1165c0920 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -16,6 +16,7 @@ using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.Common.Web; using Tango.MachineStudio.UI.Messages; using Tango.Settings; using Tango.SharedUI; @@ -35,6 +36,7 @@ namespace Tango.MachineStudio.UI.ViewModels private IEventLogger _eventLogger; private Rfc2898Cryptographer cryptographer; private MachineStudioSettings _settings; + private MachineStudioWebClient _machineStudioWebClient; private String _email; /// @@ -111,10 +113,11 @@ namespace Tango.MachineStudio.UI.ViewModels /// The authentication provider. /// The navigation manager. /// The notification provider. - public LoginViewVM(IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger) + public LoginViewVM(MachineStudioWebClient machineStudioWebClient, IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger) { EnableSlotSelection = true; + _machineStudioWebClient = machineStudioWebClient; _settings = SettingsManager.Default.GetOrCreate(); _notificationProvider = notificationProvider; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 56ebb1e00..986bf483f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -55,6 +55,7 @@ namespace Tango.MachineStudio.UI.ViewModels private Thread _updateCheckThread; private IEventLogger _eventLogger; private MachineStudioSettings _settings; + private MachineStudioWebClient _machineStudioWebClient; /// /// Gets or sets the current loaded module. @@ -281,8 +282,10 @@ namespace Tango.MachineStudio.UI.ViewModels IEventLogger eventLogger, IDiagnosticsFrameProvider frameProvider, ISpeechProvider speechProvider, - TeamFoundationServiceExtendedClient tfs) : base() + TeamFoundationServiceExtendedClient tfs, + MachineStudioWebClient machineStudioWebClient) : base() { + _machineStudioWebClient = machineStudioWebClient; TFSClient = tfs; _eventLogger = eventLogger; _navigation = navigationManager; @@ -357,11 +360,8 @@ namespace Tango.MachineStudio.UI.ViewModels { if (_authenticationProvider.CurrentUser != null) { - var client = new MachineStudioWebService(); - - CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() + CheckForUpdatesResponse response = _machineStudioWebClient.CheckForUpdates(new CheckForUpdatesRequest() { - AccessToken = _authenticationProvider.AccessToken, Version = _applicationManager.Version.ToString(), }).Result; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 57043df0e..17edf1dfd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -25,7 +25,6 @@ using Tango.MachineStudio.UI.Messages; using Tango.Settings; using Tango.MachineStudio.Common; using Tango.Transport.Web; -using Tango.MachineStudio.Common.Web; namespace Tango.MachineStudio.UI.ViewModels { @@ -56,6 +55,7 @@ namespace Tango.MachineStudio.UI.ViewModels private CheckForUpdatesResponse _updateInfo; private TemporaryFolder _newPackageTempFolder; private TemporaryFolder _previousPackageTempFolder; + private MachineStudioWebClient _machineStudioWebClient; private bool _forcedUpdate; public bool ForcedUpdate @@ -140,8 +140,9 @@ namespace Tango.MachineStudio.UI.ViewModels public RelayCommand TryRollbackAgainCommand { get; set; } - public UpdateViewVM(INotificationProvider notification, IAuthenticationProvider authentication, INavigationManager navigation, IStudioApplicationManager application) + public UpdateViewVM(MachineStudioWebClient machineStudioWebClient, INotificationProvider notification, IAuthenticationProvider authentication, INavigationManager navigation, IStudioApplicationManager application) { + _machineStudioWebClient = machineStudioWebClient; _notification = notification; _navigation = navigation; _application = application; @@ -169,11 +170,9 @@ namespace Tango.MachineStudio.UI.ViewModels Status = UpdateStatus.CheckingForUpdate; - var client = new MachineStudioWebService(); - - DownloadLatestVersionResponse response = await client.DownloadLatestVersion(new DownloadLatestVersionRequest() + DownloadLatestVersionResponse response = await _machineStudioWebClient.DownloadLatestVersion(new DownloadLatestVersionRequest() { - AccessToken = _authentication.AccessToken, + }); _updateInfo = new CheckForUpdatesResponse(); @@ -210,17 +209,14 @@ namespace Tango.MachineStudio.UI.ViewModels var settings = SettingsManager.Default.GetOrCreate(); - Task.Factory.StartNew(() => + Task.Factory.StartNew((Action)(() => { try { Thread.Sleep(2000); - var client = new MachineStudioWebService(); - - CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() + CheckForUpdatesResponse response = _machineStudioWebClient.CheckForUpdates(new CheckForUpdatesRequest() { - AccessToken = _authentication.AccessToken, Version = _application.Version.ToString(), }).Result; @@ -241,7 +237,7 @@ namespace Tango.MachineStudio.UI.ViewModels logManager.Log(ex, "Error while checking for version update!"); Status = UpdateStatus.Error; } - }); + })); } private void BackToApplication() diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs index 896c7b921..4808252d0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs @@ -27,8 +27,7 @@ namespace Tango.PPC.Common.MachineSetup /// Performs a machine setup using the specified serial number and machine service address. /// /// The serial number. - /// The machine service address. /// - Task Setup(String serialNumber, String machineServiceAddress); + Task Setup(String serialNumber); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index 256804f67..369248c7b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -40,6 +40,7 @@ namespace Tango.PPC.Common.MachineSetup private IRemoteAssistanceProvider _remoteAssistance; private IUnifiedWriteFilterManager _uwf; private IOperationSystemManager _windows_manager; + private PPCWebClient _client; #region Events @@ -72,8 +73,9 @@ namespace Tango.PPC.Common.MachineSetup /// Initializes a new instance of the class. /// /// The remote assistance. - public MachineSetupManager(IRemoteAssistanceProvider remoteAssistance, IUnifiedWriteFilterManager unifiedWriterFilterManager, IOperationSystemManager operationSystemManager) + public MachineSetupManager(PPCWebClient ppcWebClient, IRemoteAssistanceProvider remoteAssistance, IUnifiedWriteFilterManager unifiedWriterFilterManager, IOperationSystemManager operationSystemManager) { + _client = ppcWebClient; _remoteAssistance = remoteAssistance; _uwf = unifiedWriterFilterManager; _windows_manager = operationSystemManager; @@ -83,18 +85,16 @@ namespace Tango.PPC.Common.MachineSetup #region Private Methods - private Task Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + 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; + }); } @@ -108,7 +108,7 @@ namespace Tango.PPC.Common.MachineSetup /// The serial number. /// The machine service address. /// - public async Task Setup(string serialNumber, string machineServiceAddress) + public async Task Setup(string serialNumber) { TaskCompletionSource result = new TaskCompletionSource(); @@ -116,6 +116,8 @@ namespace Tango.PPC.Common.MachineSetup { LogManager.Log($"Starting machine setup for serial number {serialNumber}..."); + var machineServiceAddress = SettingsManager.Default.GetOrCreate().GetMachineServiceAddress(); + IMachineOperator op = null; var settings = SettingsManager.Default.GetOrCreate(); @@ -125,19 +127,15 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - var accessToken = await Login(serialNumber); + Login(serialNumber).Wait(); MachineSetupRequest request = new MachineSetupRequest(); - request.AccessToken = accessToken; MachineSetupResponse setup_response = null; try { - using (var client = new PPCWebService()) - { - setup_response = await client.MachineSetup(request); - } + setup_response = await _client.MachineSetup(request); } catch (Exception ex) { 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 class. /// /// The application manager. - 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 Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + 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()}"); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs index 1c69f0934..dfb544177 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs @@ -17,7 +17,7 @@ namespace Tango.PPC.Common.Publish { public class PPCPublisher : ExtendedObject { - private IPPCWebService _client; + private PPCWebClient _client; /// /// Occurs on publish progress. @@ -39,7 +39,7 @@ namespace Tango.PPC.Common.Publish /// public PPCPublisher() { - _client = new PPCWebService(); + _client = new PPCWebClient(); Options = new PublishOptions(); } @@ -100,16 +100,16 @@ namespace Tango.PPC.Common.Publish /// Login to machine service and returns an access token. /// /// - private Task Login() + private Task Login() { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { return _client.Login(new LoginRequest() { Mode = LoginMode.User, Email = Options.Email, Password = Options.Password, - }).Result.AccessToken; + }).Result; }); } @@ -123,7 +123,6 @@ namespace Tango.PPC.Common.Publish String appPath = GetPPCExecutablePath(); String folder = Options.GetApplicationPath(); - String accessToken = String.Empty; if (!File.Exists(appPath)) { @@ -137,7 +136,7 @@ namespace Tango.PPC.Common.Publish try { OnPublishProgress(0, 100, $"Logging in to machine service at {Options.Environment.ToAddress()}..."); - accessToken = Login().Result; + Login().Wait(); OnPublishProgress(0, 100, $"Fetching remote version from {Options.Environment.ToAddress()}..."); @@ -159,7 +158,6 @@ namespace Tango.PPC.Common.Publish Comments = Options.Comments, Version = local_version, MachineVersionGuid = Options.MachineVersionGuid, - AccessToken = accessToken, }).Result; CreateTupPackage(tempFile).Wait(); @@ -183,7 +181,6 @@ namespace Tango.PPC.Common.Publish _client.NotifyUploadCompleted(new UploadCompletedRequest() { - AccessToken = accessToken, Token = response.Token, }); 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 3b18a6217..e47437f4d 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 @@ -161,6 +161,8 @@ + + @@ -194,14 +196,12 @@ - - @@ -366,7 +366,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs deleted file mode 100644 index 6347836a9..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.ServiceModel; -using System.Text; -using System.Threading.Tasks; -using Tango.PPC.Common.Web; -using Tango.Web; - -namespace Tango.PPC.Common.Web -{ - /// - /// Represents an PPC update service for uploading PPC software packages. - /// - public interface IPPCWebService : IDisposable - { - /// - /// Gets or sets the environment. - /// - DeploymentSlot Environment { get; set; } - - /// - /// Uploads the version. - /// - /// The request. - /// - Task UploadVersion(UploadVersionRequest request); - - /// - /// Notifies the upload completed. - /// - /// The request. - Task NotifyUploadCompleted(UploadCompletedRequest request); - - /// - /// Gets the latest version. - /// - /// The machine version unique identifier. - /// - Task GetLatestVersion(LatestVersionRequest request); - - /// - /// Gets the machine versions. - /// - /// The request. - /// - Task GetMachineVersions(); - - /// - /// Checks for available update. - /// - /// The request. - /// - Task CheckForUpdate(CheckForUpdateRequest request); - - /// - /// Gets the version download info for the specified version. - /// - /// The request. - /// - Task MachineUpdate(DownloadUpdateRequest request); - - /// - /// Gets the machine setup information. - /// - /// The request. - /// - Task MachineSetup(MachineSetupRequest request); - - /// - /// Gets the machine database update information. - /// - /// The request. - /// - Task UpdateDB(UpdateDBRequest request); - - /// - /// Logins to the PPC service. - /// - /// The request. - /// - Task Login(LoginRequest request); - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs index bf2a1e88e..5d97c6470 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs @@ -4,11 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Transport.Web; +using Tango.Web.Authentication; namespace Tango.PPC.Common.Web { - public class LoginResponse : WebResponseMessage + public class LoginResponse : WebTokenResponse { - public String AccessToken { get; set; } + } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs new file mode 100644 index 000000000..5900dd697 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.PPC.Common.Web +{ + public class PPCWebClient : PPCWebClientBase + { + public PPCWebClient(DeploymentSlot environment) : base(environment) + { + } + + public PPCWebClient(DeploymentSlot environment, WebToken token) : base(environment, token) + { + } + + public PPCWebClient(WebToken token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) + { + } + + public PPCWebClient() : this(null) + { + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs new file mode 100644 index 000000000..e5c1beb4a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs @@ -0,0 +1,106 @@ + +using System.Threading.Tasks; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.PPC.Common.Web +{ + /// + /// Represents a machine service PPC web client. + /// + /// + public abstract class PPCWebClientBase : TangoWebClient + { + /// + /// Initializes a new instance of the class. + /// + /// The environment. + /// Existing token. + public PPCWebClientBase(DeploymentSlot environment, WebToken token) : base(environment, "PPC", token) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The environment. + public PPCWebClientBase(DeploymentSlot environment) : this(environment, null) + { + + } + + /// + /// Executes the MachineSetup action and returns Tango.PPC.Common.Web.MachineSetupResponse. + /// + /// + public Task MachineSetup(Tango.PPC.Common.Web.MachineSetupRequest request) + { + return Post("MachineSetup", request); + } + + /// + /// Executes the MachineUpdate action and returns Tango.PPC.Common.Web.DownloadUpdateResponse. + /// + /// + public Task MachineUpdate(Tango.PPC.Common.Web.DownloadUpdateRequest request) + { + return Post("MachineUpdate", request); + } + + /// + /// Executes the CheckForUpdate action and returns Tango.PPC.Common.Web.CheckForUpdateResponse. + /// + /// + public Task CheckForUpdate(Tango.PPC.Common.Web.CheckForUpdateRequest request) + { + return Post("CheckForUpdate", request); + } + + /// + /// Executes the UpdateDB action and returns Tango.PPC.Common.Web.UpdateDBResponse. + /// + /// + public Task UpdateDB(Tango.PPC.Common.Web.UpdateDBRequest request) + { + return Post("UpdateDB", request); + } + + /// + /// Executes the GetLatestVersion action and returns Tango.PPC.Common.Web.LatestVersionResponse. + /// + /// + public Task GetLatestVersion(Tango.PPC.Common.Web.LatestVersionRequest request) + { + return Post("GetLatestVersion", request); + } + + /// + /// Executes the UploadVersion action and returns Tango.PPC.Common.Web.UploadVersionResponse. + /// + /// + public Task UploadVersion(Tango.PPC.Common.Web.UploadVersionRequest request) + { + return Post("UploadVersion", request); + } + + /// + /// Executes the NotifyUploadCompleted action and returns Tango.PPC.Common.Web.UploadCompletedResponse. + /// + /// + public Task NotifyUploadCompleted(Tango.PPC.Common.Web.UploadCompletedRequest request) + { + return Post("NotifyUploadCompleted", request); + } + + /// + /// Executes the GetMachineVersions action and returns Tango.PPC.Common.Web.MachineVersionsResponse. + /// + /// + public Task GetMachineVersions(Tango.PPC.Common.Web.MachineVersionsRequest request) + { + return Post("GetMachineVersions", request); + } + + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs deleted file mode 100644 index 02821e8d4..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Settings; -using Tango.Transport.Web; -using Tango.Web; - -namespace Tango.PPC.Common.Web -{ - public class PPCWebService : IPPCWebService - { - private WebTransportClient _client; - - public DeploymentSlot Environment { get; set; } - - public PPCWebService() - { - _client = new WebTransportClient(); - Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/PPC/"; - } - - public Task UploadVersion(UploadVersionRequest request) - { - return _client.PostJson(GetAddress() + "UploadVersion", request); - } - - public Task NotifyUploadCompleted(UploadCompletedRequest request) - { - return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); - } - - public Task GetLatestVersion(LatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "GetLatestVersion", request); - } - - public Task GetMachineVersions() - { - return _client.PostJson(GetAddress() + "GetMachineVersions", new MachineVersionsRequest()); - } - - public Task CheckForUpdate(CheckForUpdateRequest request) - { - return _client.PostJson(GetAddress() + "CheckForUpdate", request); - } - - public Task MachineUpdate(DownloadUpdateRequest request) - { - return _client.PostJson(GetAddress() + "MachineUpdate", request); - } - - public Task MachineSetup(MachineSetupRequest request) - { - return _client.PostJson(GetAddress() + "MachineSetup", request); - } - - public Task UpdateDB(UpdateDBRequest request) - { - return _client.PostJson(GetAddress() + "UpdateDB", request); - } - - public Task Login(LoginRequest request) - { - return _client.PostJson(GetAddress() + "Login", request); - } - - public void Dispose() - { - _client.Dispose(); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs index 6c7e1d005..1d77b152f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs @@ -35,7 +35,7 @@ namespace Tango.PPC.Publisher.UI { public class MainWindowVM : ViewModel { - private IPPCWebService _client; + private PPCWebClient _client; private PPCPublisher _publisher; private PublishOptions _options; @@ -102,7 +102,7 @@ namespace Tango.PPC.Publisher.UI public MainWindowVM() { - _client = new PPCWebService(); + _client = new PPCWebClient(); var settings = SettingsManager.Default.GetOrCreate(); Options = settings.Options; @@ -152,7 +152,7 @@ namespace Tango.PPC.Publisher.UI private async Task UpdateAvailableMachineVersions() { IsFree = false; - _machineVersions = (await _client.GetMachineVersions()).MachineVersions; + _machineVersions = (await _client.GetMachineVersions(new MachineVersionsRequest())).MachineVersions; _selectedMachineVersion = MachineVersions.OrderBy(x => x.Version).LastOrDefault(); RaisePropertyChanged(nameof(MachineVersions)); RaisePropertyChanged(nameof(SelectedMachineVersion)); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 4eb5475f0..018c9b223 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -22,6 +22,7 @@ using Tango.PPC.Common.RemoteAssistance; using Tango.PPC.Common.Storage; using Tango.PPC.Common.Threading; using Tango.PPC.Common.UWF; +using Tango.PPC.Common.Web; using Tango.PPC.UI.Authentication; using Tango.PPC.UI.Connectivity; using Tango.PPC.UI.Modules; @@ -69,7 +70,9 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); + TangoIOC.Default.Register(new PPCWebClient()); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index 514a517ff..1bd1e1eea 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -18,6 +18,7 @@ using Tango.PPC.Common.Connection; using Tango.PPC.Common.MachineSetup; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.OS; +using Tango.PPC.Common.Web; using Tango.PPC.UI.ViewsContracts; using Tango.Settings; using Tango.SharedUI.Helpers; @@ -60,6 +61,7 @@ namespace Tango.PPC.UI.ViewModels private MachineSetupResult _setup_result; private IOperationSystemManager _operationSystemManager; private IPPCApplicationManager _appManager; + private PPCWebClient _ppcWebClient; #region Properties @@ -192,8 +194,9 @@ namespace Tango.PPC.UI.ViewModels /// /// The application manager. /// The machine setup manager. - public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager, IOperationSystemManager operationSystemManager) + public MachineSetupViewVM(PPCWebClient ppcWebClient, IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager, IOperationSystemManager operationSystemManager) { + _ppcWebClient = ppcWebClient; _appManager = applicationManager; MachineSetupManager = machineSetupManager; @@ -210,7 +213,7 @@ namespace Tango.PPC.UI.ViewModels InstallCommand = new RelayCommand(Install); RestartCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.WelcomeView); }); TimeZoneSelectedCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.EnvironmentView); }); - EnvironmentSelectedCommand = new RelayCommand(() => + EnvironmentSelectedCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.SetupWelcomeView); Settings.DeploymentSlot = DeploymentSlot; @@ -348,8 +351,9 @@ namespace Tango.PPC.UI.ViewModels try { + _ppcWebClient.Environment = DeploymentSlot; await _operationSystemManager.ChangeTimeZone(SelectedTimeZone); - _setup_result = await MachineSetupManager.Setup(SerialNumber, HostAddress); + _setup_result = await MachineSetupManager.Setup(SerialNumber); State = MachineSetupStates.Completed; LogManager.Log("Machine setup completed."); await NavigateTo(MachineSetupView.SetupCompletedView); diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj index 436bfae33..98c063a86 100644 --- a/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj +++ b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj @@ -87,6 +87,7 @@ + @@ -118,11 +119,12 @@ + - +