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... --- .../PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 1 + .../PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels') 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 48aae2b8f..514a517ff 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -215,6 +215,7 @@ namespace Tango.PPC.UI.ViewModels NavigateTo(MachineSetupView.SetupWelcomeView); Settings.DeploymentSlot = DeploymentSlot; HostAddress = Settings.GetMachineServiceAddress(); + Settings.Save(); }); _operationSystemManager = operationSystemManager; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index 2f6199ecb..6046f0300 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -136,7 +136,7 @@ namespace Tango.PPC.UI.ViewModels { IsDbUpdate = false; - var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber, Settings.GetMachineServiceAddress()); + var response = await MachineUpdateManager.CheckForUpdate(MachineProvider.Machine.SerialNumber); if (response.IsUpdateAvailable) { @@ -145,7 +145,7 @@ namespace Tango.PPC.UI.ViewModels } else { - _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber, Settings.GetMachineServiceAddress()); + _db_compare_result = await MachineUpdateManager.UpdateDBCheck(MachineProvider.Machine.SerialNumber); if (_db_compare_result.RequiresUpdate) { @@ -176,7 +176,7 @@ namespace Tango.PPC.UI.ViewModels try { - _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber, Settings.GetMachineServiceAddress()); + _update_result = await MachineUpdateManager.Update(MachineProvider.Machine.SerialNumber); LogManager.Log("Machine update completed."); await NavigateTo(MachineUpdateView.UpdateCompletedView); } @@ -299,7 +299,7 @@ namespace Tango.PPC.UI.ViewModels try { - _update_result = await MachineUpdateManager.Update(fileItem.Path); + _update_result = await MachineUpdateManager.UpdateFromTUP(fileItem.Path); LogManager.Log("Machine update from package completed."); await NavigateTo(MachineUpdateView.UpdateCompletedView); } -- 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/PPC/Tango.PPC.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 @@ + - +