diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-19 01:50:58 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2019-02-19 01:50:58 +0200 |
| commit | 9736b8c8ede6a0d121dea8381f0abb561fad5631 (patch) | |
| tree | 1c38f3f5be82b923ffae40fae00a25487179ab54 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common | |
| parent | be3343cc0268179c7a6f628fa5e68f323a3335e5 (diff) | |
| download | Tango-9736b8c8ede6a0d121dea8381f0abb561fad5631.tar.gz Tango-9736b8c8ede6a0d121dea8381f0abb561fad5631.zip | |
Implemented auto generated web clients for PPC and machine studio.
Improved interactions with web clients across solutions.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common')
8 files changed, 123 insertions, 107 deletions
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 @@ -13,11 +13,6 @@ namespace Tango.MachineStudio.Common.Authentication public interface IAuthenticationProvider { /// <summary> - /// Gets the access token that was retrieved at the last login. - /// </summary> - String AccessToken { get; } - - /// <summary> /// Occurs when the current logged-in user has changed. /// </summary> event EventHandler<User> CurrentUserChanged; 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; /// <summary> /// Occurs on publish progress. @@ -40,7 +40,7 @@ namespace Tango.MachineStudio.Common.Publish /// </summary> 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. /// </summary> /// <returns></returns> - private Task<String> Login() + private Task Login() { - return Task.Factory.StartNew<String>(() => + 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 @@ <Compile Include="Web\DownloadLatestVersionRequest.cs" /> <Compile Include="Web\CheckForUpdatesResponse.cs" /> <Compile Include="Web\CheckForUpdatesRequest.cs" /> - <Compile Include="Web\IMachineStudioWebService.cs" /> <Compile Include="Web\LatestVersionRequest.cs" /> <Compile Include="Web\LatestVersionResponse.cs" /> - <Compile Include="Web\MachineStudioWebService.cs" /> + <Compile Include="Web\MachineStudioWebClient.cs" /> + <Compile Include="Web\MachineStudioWebClientBase.cs" /> <Compile Include="Web\UploadCompletedRequest.cs" /> <Compile Include="Web\UploadCompletedResponse.cs" /> <Compile Include="Web\UploadVersionRequest.cs" /> @@ -326,7 +326,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ 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<CheckForUpdatesResponse> CheckForUpdates(CheckForUpdatesRequest request); - - Task<DownloadLatestVersionResponse> DownloadLatestVersion(DownloadLatestVersionRequest request); - - Task<UploadVersionResponse> UploadVersion(UploadVersionRequest request); - - Task<UploadCompletedResponse> NotifyUploadCompleted(UploadCompletedRequest request); - - Task<LatestVersionResponse> GetLatestVersion(LatestVersionRequest request); - - Task<LoginResponse> 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<MachineStudioSettings>().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 +{ + /// <summary> + /// Represents a machine service MachineStudio web client. + /// </summary> + /// <seealso cref="Tango.Web.TangoWebClient" /> + public abstract class MachineStudioWebClientBase : TangoWebClient<Tango.MachineStudio.Common.Web.LoginRequest, Tango.MachineStudio.Common.Web.LoginResponse> + { + /// <summary> + /// Initializes a new instance of the <see cref="MachineStudioWebClientBase"/> class. + /// </summary> + /// <param name="environment">The environment.</param> + /// <param name="token">Existing token.</param> + public MachineStudioWebClientBase(DeploymentSlot environment, WebToken token) : base(environment, "MachineStudio", token) + { + + } + + /// <summary> + /// Initializes a new instance of the <see cref="MachineStudioWebClientBase"/> class. + /// </summary> + /// <param name="environment">The environment.</param> + public MachineStudioWebClientBase(DeploymentSlot environment) : this(environment, null) + { + + } + + /// <summary> + /// Executes the CheckForUpdates action and returns Tango.MachineStudio.Common.Web.CheckForUpdatesResponse. + /// </summary> + /// <returns></returns> + public Task<Tango.MachineStudio.Common.Web.CheckForUpdatesResponse> CheckForUpdates(Tango.MachineStudio.Common.Web.CheckForUpdatesRequest request) + { + return Post<Tango.MachineStudio.Common.Web.CheckForUpdatesRequest, Tango.MachineStudio.Common.Web.CheckForUpdatesResponse>("CheckForUpdates", request); + } + + /// <summary> + /// Executes the DownloadLatestVersion action and returns Tango.MachineStudio.Common.Web.DownloadLatestVersionResponse. + /// </summary> + /// <returns></returns> + public Task<Tango.MachineStudio.Common.Web.DownloadLatestVersionResponse> DownloadLatestVersion(Tango.MachineStudio.Common.Web.DownloadLatestVersionRequest request) + { + return Post<Tango.MachineStudio.Common.Web.DownloadLatestVersionRequest, Tango.MachineStudio.Common.Web.DownloadLatestVersionResponse>("DownloadLatestVersion", request); + } + + /// <summary> + /// Executes the UploadVersion action and returns Tango.MachineStudio.Common.Web.UploadVersionResponse. + /// </summary> + /// <returns></returns> + public Task<Tango.MachineStudio.Common.Web.UploadVersionResponse> UploadVersion(Tango.MachineStudio.Common.Web.UploadVersionRequest request) + { + return Post<Tango.MachineStudio.Common.Web.UploadVersionRequest, Tango.MachineStudio.Common.Web.UploadVersionResponse>("UploadVersion", request); + } + + /// <summary> + /// Executes the NotifyUploadCompleted action and returns Tango.MachineStudio.Common.Web.UploadCompletedResponse. + /// </summary> + /// <returns></returns> + public Task<Tango.MachineStudio.Common.Web.UploadCompletedResponse> NotifyUploadCompleted(Tango.MachineStudio.Common.Web.UploadCompletedRequest request) + { + return Post<Tango.MachineStudio.Common.Web.UploadCompletedRequest, Tango.MachineStudio.Common.Web.UploadCompletedResponse>("NotifyUploadCompleted", request); + } + + /// <summary> + /// Executes the GetLatestVersion action and returns Tango.MachineStudio.Common.Web.LatestVersionResponse. + /// </summary> + /// <returns></returns> + public Task<Tango.MachineStudio.Common.Web.LatestVersionResponse> GetLatestVersion(Tango.MachineStudio.Common.Web.LatestVersionRequest request) + { + return Post<Tango.MachineStudio.Common.Web.LatestVersionRequest, Tango.MachineStudio.Common.Web.LatestVersionResponse>("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<MachineStudioSettings>().DeploymentSlot; - _client = new WebTransportClient(); - } - - public Task<CheckForUpdatesResponse> CheckForUpdates(CheckForUpdatesRequest request) - { - return _client.PostJson<CheckForUpdatesRequest, CheckForUpdatesResponse>(GetAddress() + "CheckForUpdates", request); - } - - public Task<UploadVersionResponse> UploadVersion(UploadVersionRequest request) - { - return _client.PostJson<UploadVersionRequest, UploadVersionResponse>(GetAddress() + "UploadVersion", request); - } - - public Task<UploadCompletedResponse> NotifyUploadCompleted(UploadCompletedRequest request) - { - return _client.PostJson<UploadCompletedRequest, UploadCompletedResponse>(GetAddress() + "NotifyUploadCompleted", request); - } - - public Task<LatestVersionResponse> GetLatestVersion(LatestVersionRequest request) - { - return _client.PostJson<LatestVersionRequest, LatestVersionResponse>(GetAddress() + "GetLatestVersion", request); - } - - public Task<DownloadLatestVersionResponse> DownloadLatestVersion(DownloadLatestVersionRequest request) - { - return _client.PostJson<DownloadLatestVersionRequest, DownloadLatestVersionResponse>(GetAddress() + "DownloadLatestVersion", request); - } - - public Task<LoginResponse> Login(LoginRequest request) - { - return _client.PostJson<LoginRequest, LoginResponse>(GetAddress() + "Login", request); - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/MachineStudio/"; - } - } -} |
