From 8c203b26d50818a1b16b2a7ec48eca7b082653f4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 18 Feb 2019 11:33:30 +0200 Subject: Implemented new Machine Studio Publish CLI and UI. --- .../Tango.MachineStudio.Common.csproj | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj') 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 aff4c056c..87ccd8249 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 @@ -31,6 +31,9 @@ 4 + + ..\..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll + ..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll @@ -40,6 +43,9 @@ ..\..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + ..\..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll + ..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll @@ -49,6 +55,8 @@ ..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + + @@ -110,6 +118,9 @@ + + + @@ -195,7 +206,9 @@ - + + Designer + SettingsSingleFileGenerator Settings.Designer.cs -- cgit v1.3.1 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. --- .../Authentication/AuthenticationLoginResult.cs | 1 + .../Authentication/LoginRequest.cs | 16 --- .../Authentication/LoginResponse.cs | 18 --- .../Tango.MachineStudio.Common.csproj | 31 +++-- .../Update/CheckForUpdatesRequest.cs | 15 --- .../Update/CheckForUpdatesResponse.cs | 21 ---- .../Update/DownloadLatestVersionRequest.cs | 14 --- .../Update/DownloadLatestVersionResponse.cs | 16 --- .../Update/IMachineStudioUpdateService.cs | 27 ----- .../Update/LatestVersionRequest.cs | 15 --- .../Update/LatestVersionResponse.cs | 15 --- .../Update/MachineStudioUpdateService.cs | 54 --------- .../Update/UpdateServiceHelper.cs | 29 ----- .../Update/UploadCompletedRequest.cs | 15 --- .../Update/UploadCompletedResponse.cs | 14 --- .../Update/UploadVersionRequest.cs | 21 ---- .../Update/UploadVersionResponse.cs | 17 --- .../Web/CheckForUpdatesRequest.cs | 15 +++ .../Web/CheckForUpdatesResponse.cs | 21 ++++ .../Web/DownloadLatestVersionRequest.cs | 14 +++ .../Web/DownloadLatestVersionResponse.cs | 16 +++ .../Web/IMachineStudioService.cs | 28 +++++ .../Web/LatestVersionRequest.cs | 15 +++ .../Web/LatestVersionResponse.cs | 15 +++ .../Tango.MachineStudio.Common/Web/LoginRequest.cs | 16 +++ .../Web/LoginResponse.cs | 18 +++ .../Web/MachineStudioService.cs | 60 ++++++++++ .../Web/UploadCompletedRequest.cs | 15 +++ .../Web/UploadCompletedResponse.cs | 14 +++ .../Web/UploadVersionRequest.cs | 17 +++ .../Web/UploadVersionResponse.cs | 17 +++ .../MainWindow.xaml | 2 +- .../MainWindowVM.cs | 4 +- .../DefaultAuthenticationProvider.cs | 5 +- .../Messages/ChangeVersionMessage.cs | 2 +- .../Messages/ForcedUpdateMessage.cs | 2 +- .../ViewModels/LoadingViewVM.cs | 2 +- .../ViewModels/MainViewVM.cs | 4 +- .../ViewModels/UpdateViewVM.cs | 7 +- .../Tango.MachineStudio.UI/Views/AboutView.xaml | 2 - .../Tango.Web/Authentication/TokensManager.cs | 23 +++- .../Controllers/MachineStudioController.cs | 133 +++++++++++++-------- .../Filters/MachineStudioLoginFilter.cs | 31 +++++ .../Tango.MachineService.csproj | 3 +- 44 files changed, 448 insertions(+), 392 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginRequest.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionRequest.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionResponse.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UpdateServiceHelper.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LatestVersionRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LatestVersionResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionResponse.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/AuthenticationLoginResult.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/AuthenticationLoginResult.cs index 78f5365a5..dd18d75b2 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/AuthenticationLoginResult.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/AuthenticationLoginResult.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL.Entities; +using Tango.MachineStudio.Common.Web; namespace Tango.MachineStudio.Common.Authentication { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginRequest.cs deleted file mode 100644 index 94fe7f5e2..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginRequest.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Authentication -{ - public class LoginRequest : WebRequestMessage - { - public String Version { get; set; } - public String Email { get; set; } - public String Password { get; set; } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs deleted file mode 100644 index e1d9c615a..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Authentication -{ - public class LoginResponse : WebResponseMessage - { - public DataSource DataSource { get; set; } - public String Token { get; set; } - public bool VersionChangeRequired { get; set; } - public String RequiredVersion { get; set; } - } -} 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 87ccd8249..40d7da460 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 @@ -84,8 +84,8 @@ GlobalVersionInfo.cs - - + + @@ -130,19 +130,18 @@ - - - - - - - - - - - - - + + + + + + + + + + + + @@ -327,7 +326,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs deleted file mode 100644 index e31a7f59e..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class CheckForUpdatesRequest : WebRequestSecureMessage - { - public String Version { get; set; } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs deleted file mode 100644 index 450236f79..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class CheckForUpdatesResponse : WebResponseMessage - { - public bool IsUpdateAvailable { get; set; } - - public String Version { get; set; } - - public String Comments { get; set; } - - public String BlobAddress { get; set; } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionRequest.cs deleted file mode 100644 index 98aa9f1a4..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionRequest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class DownloadLatestVersionRequest : WebRequestSecureMessage - { - - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionResponse.cs deleted file mode 100644 index f85999f3d..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/DownloadLatestVersionResponse.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class DownloadLatestVersionResponse : WebResponseMessage - { - public String Version { get; set; } - - public String BlobAddress { get; set; } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs deleted file mode 100644 index 375506b90..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs +++ /dev/null @@ -1,27 +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.MachineStudio.Common.Update; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public interface IMachineStudioUpdateService - { - DeploymentSlot Environment { get; set; } - - Task CheckForUpdates(CheckForUpdatesRequest request); - - Task DownloadLatestVersion(DownloadLatestVersionRequest request); - - Task UploadVersion(UploadVersionRequest request); - - Task NotifyUploadCompleted(UploadCompletedRequest request); - - Task GetLatestVersion(LatestVersionRequest request); - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs deleted file mode 100644 index b4e7bd975..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class LatestVersionRequest : WebRequestMessage - { - - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs deleted file mode 100644 index b90cbf370..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class LatestVersionResponse : WebResponseMessage - { - public String Version { get; set; } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs deleted file mode 100644 index 8fdd18abe..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs +++ /dev/null @@ -1,54 +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.MachineStudio.Common.Update -{ - public class MachineStudioUpdateService : IMachineStudioUpdateService - { - private WebTransportClient _client; - - public DeploymentSlot Environment { get; set; } - - public MachineStudioUpdateService() - { - 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); - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/MachineStudio/"; - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UpdateServiceHelper.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UpdateServiceHelper.cs deleted file mode 100644 index 067e4470d..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UpdateServiceHelper.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.ServiceModel; -using System.Text; -using System.Threading.Tasks; -using Tango.Settings; - -namespace Tango.MachineStudio.Common.Update -{ - public static class UpdateServiceHelper - { - public static ChannelFactory GetUpdateServiceChannel() - { - BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); - binding.ReceiveTimeout = TimeSpan.FromSeconds(60); - binding.SendTimeout = TimeSpan.FromSeconds(60); - binding.MaxBufferPoolSize = 6553600; - binding.MaxBufferSize = 6553600; - binding.MaxReceivedMessageSize = 6553600; - binding.ReaderQuotas.MaxDepth = 6553600; - binding.ReaderQuotas.MaxStringContentLength = 6553600; - binding.ReaderQuotas.MaxArrayLength = 6553600; - binding.ReaderQuotas.MaxBytesPerRead = 6553600; - - return new ChannelFactory(binding, SettingsManager.Default.GetOrCreate().UpdateServiceAddress); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs deleted file mode 100644 index d23d57351..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class UploadCompletedRequest : WebRequestSecureMessage - { - - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs deleted file mode 100644 index 89850e3e5..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class UploadCompletedResponse : WebResponseMessage - { - - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs deleted file mode 100644 index fedb586ba..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class UploadVersionRequest : WebRequestMessage - { - public String Email { get; set; } - - public String Password { get; set; } - - public String Version { get; set; } - - public String Comments { get; set; } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs deleted file mode 100644 index 4d13fc6ad..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; -using Tango.Transport.Web; - -namespace Tango.MachineStudio.Common.Update -{ - public class UploadVersionResponse : WebResponseMessage - { - public String Token { get; set; } - - public String BlobAddress { get; set; } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs new file mode 100644 index 000000000..4f9576f50 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class CheckForUpdatesRequest : WebRequestSecureMessage + { + public String Version { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs new file mode 100644 index 000000000..51608e6c4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/CheckForUpdatesResponse.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class CheckForUpdatesResponse : WebResponseMessage + { + public bool IsUpdateAvailable { get; set; } + + public String Version { get; set; } + + public String Comments { get; set; } + + public String BlobAddress { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs new file mode 100644 index 000000000..d63654726 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionRequest.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class DownloadLatestVersionRequest : WebRequestSecureMessage + { + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs new file mode 100644 index 000000000..3209b9a2f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/DownloadLatestVersionResponse.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class DownloadLatestVersionResponse : WebResponseMessage + { + public String Version { get; set; } + + public String BlobAddress { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs new file mode 100644 index 000000000..748df4644 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.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 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/LatestVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LatestVersionRequest.cs new file mode 100644 index 000000000..59bb71db4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LatestVersionRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class LatestVersionRequest : WebRequestMessage + { + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LatestVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LatestVersionResponse.cs new file mode 100644 index 000000000..7d43128f1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LatestVersionResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class LatestVersionResponse : WebResponseMessage + { + public String Version { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs new file mode 100644 index 000000000..577f5e208 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginRequest.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class LoginRequest : WebRequestMessage + { + public String Version { get; set; } + public String Email { get; set; } + public String Password { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs new file mode 100644 index 000000000..0379c458b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class LoginResponse : WebResponseMessage + { + public DataSource DataSource { get; set; } + public String Token { get; set; } + public bool VersionChangeRequired { get; set; } + public String RequiredVersion { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs new file mode 100644 index 000000000..8b43146e1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.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 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/UploadCompletedRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedRequest.cs new file mode 100644 index 000000000..48f5b2a6e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedRequest.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class UploadCompletedRequest : WebRequestSecureMessage + { + public String Token { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedResponse.cs new file mode 100644 index 000000000..a290cf642 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadCompletedResponse.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class UploadCompletedResponse : WebResponseMessage + { + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs new file mode 100644 index 000000000..33577deb2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionRequest.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class UploadVersionRequest : WebRequestSecureMessage + { + public String Version { get; set; } + + public String Comments { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionResponse.cs new file mode 100644 index 000000000..9fb3ab94d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/UploadVersionResponse.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class UploadVersionResponse : WebResponseMessage + { + public String Token { get; set; } + + public String BlobAddress { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindow.xaml index a263c76a2..b860994fd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindow.xaml @@ -80,7 +80,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs index f9f2af693..e62f29403 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher.UI/MainWindowVM.cs @@ -17,7 +17,7 @@ using Tango.Core.Helpers; using Tango.Core.IO; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Publish; -using Tango.MachineStudio.Common.Update; +using Tango.MachineStudio.Common.Web; using Tango.Settings; using Tango.SharedUI; using Tango.Transport.Web; @@ -106,7 +106,7 @@ namespace Tango.MachineStudio.Publisher.UI } catch (Exception ex) { - ShowError(ex.Message); + ShowError(ex.FlattenMessage()); } finally { 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 9be938fb7..452b706df 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -15,6 +15,7 @@ using Tango.Settings; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.StudioApplication; using Tango.Core.Helpers; +using Tango.MachineStudio.Common.Web; namespace Tango.MachineStudio.UI.Authentication { @@ -56,9 +57,9 @@ namespace Tango.MachineStudio.UI.Authentication { var settings = SettingsManager.Default.GetOrCreate(); + IMachineStudioService service = new MachineStudioService(); - IWebTransportClient service = new WebTransportClient(); - var response = service.PostJson(settings.GetMachineServiceAddress() + "/api/MachineStudio/Login", new LoginRequest() + var response = service.Login(new LoginRequest() { Email = email, diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ChangeVersionMessage.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ChangeVersionMessage.cs index fc616f359..a0fdec8ed 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ChangeVersionMessage.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ChangeVersionMessage.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.MachineStudio.Common.Authentication; -using Tango.MachineStudio.Common.Update; +using Tango.MachineStudio.Common.Web; namespace Tango.MachineStudio.UI.Messages { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ForcedUpdateMessage.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ForcedUpdateMessage.cs index 38bc82b6e..54b43c6d3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ForcedUpdateMessage.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Messages/ForcedUpdateMessage.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Tango.MachineStudio.Common.Update; +using Tango.MachineStudio.Common.Web; namespace Tango.MachineStudio.UI.Messages { 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() { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml index 696cc051f..d9cb20d03 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml @@ -60,8 +60,6 @@ () - Allow BETA Updates: - diff --git a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs index 20fc8ab50..4f23c9667 100644 --- a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs +++ b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs @@ -1,30 +1,41 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Authentication; using System.Text; using System.Threading.Tasks; namespace Tango.Web.Authentication { - public class TokensManager + public class TokensManager { - private List _tokens; + private Dictionary _tokens; public TokensManager() { - _tokens = new List(); + _tokens = new Dictionary(); } - public String CreateNew() + public String CreateNew(T userID) { String token = Guid.NewGuid().ToString(); - _tokens.Add(token); + _tokens.Add(token, userID); return token; } public bool Exists(String token) { - return _tokens.Contains(token); + return _tokens.ContainsKey(token); + } + + public T GetUserID(String token) + { + if (!_tokens.ContainsKey(token)) + { + throw new AuthenticationException("Invalid token."); + } + + return _tokens[token]; } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 660b98576..b2e3aa150 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -14,35 +14,53 @@ using Tango.Core.Cryptography; using Tango.MachineService.Models; using Tango.MachineStudio.Common.Authentication; using System.Data.Entity; -using Tango.MachineStudio.Common.Update; +using Tango.MachineStudio.Common.Web; using Tango.Web.Controllers; using Tango.Web.Helpers; using Tango.Web.Storage; using Tango.Web.Authentication; using Tango.Web.ActiveDirectory; +using Tango.MachineService.Filters; namespace Tango.MachineService.Controllers { public class MachineStudioController : JsonController { - private static TokensManager _tokens_manager; private static List _pendingUploads; private ActiveDirectoryManager _ad_manager; + public static TokensManager TokensManager { get; set; } + + #region Constructors + + /// + /// Initializes the class. + /// static MachineStudioController() { - _tokens_manager = new TokensManager(); + TokensManager = new TokensManager(); _pendingUploads = new List(); } + /// + /// Initializes a new instance of the class. + /// public MachineStudioController() : base() { _ad_manager = new ActiveDirectoryManager(); } - #region Update + #endregion + + #region Actions + /// + /// Checks for updates. + /// + /// The request. + /// [HttpPost] + [MachineStudioLoginFilter] public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request) { LogManager.Log("Request received..."); @@ -51,41 +69,40 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - if (_tokens_manager.Exists(request.AccessToken)) - { - var versions = db.MachineStudioVersions.ToList(); + var versions = db.MachineStudioVersions.ToList(); - MachineStudioVersion latestVersion = null; + MachineStudioVersion latestVersion = null; - latestVersion = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + latestVersion = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - Version currentVersion = Version.Parse(request.Version); + Version currentVersion = Version.Parse(request.Version); - String comments = String.Join(Environment.NewLine, versions.OrderBy(x => Version.Parse(x.Version)).Where(x => Version.Parse(x.Version) > currentVersion).Select(x => x.Comments)); + String comments = String.Join(Environment.NewLine, versions.OrderBy(x => Version.Parse(x.Version)).Where(x => Version.Parse(x.Version) > currentVersion).Select(x => x.Comments)); - if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion) - { - var manager = new StorageManager(); - var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); - var blob = container.GetBlockBlobReference(latestVersion.BlobName); + if (latestVersion != null && Version.Parse(latestVersion.Version) > currentVersion) + { + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); + var blob = container.GetBlockBlobReference(latestVersion.BlobName); - response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); - response.IsUpdateAvailable = true; - response.Version = latestVersion.Version; - response.Comments = latestVersion.Comments; - } - } - else - { - throw new AuthenticationException("Invalid token."); + response.IsUpdateAvailable = true; + response.Version = latestVersion.Version; + response.Comments = latestVersion.Comments; } } return response; } + /// + /// Downloads the latest version. + /// + /// The request. + /// [HttpPost] + [MachineStudioLoginFilter] public DownloadLatestVersionResponse DownloadLatestVersion(DownloadLatestVersionRequest request) { LogManager.Log("Request received..."); @@ -94,32 +111,33 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - if (_tokens_manager.Exists(request.AccessToken)) - { - var versions = db.MachineStudioVersions.ToList(); + var versions = db.MachineStudioVersions.ToList(); - MachineStudioVersion latestVersion = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + MachineStudioVersion latestVersion = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - if (latestVersion != null) - { - var manager = new StorageManager(); - var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); - var blob = container.GetBlockBlobReference(latestVersion.BlobName); - - response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); - response.Version = latestVersion.Version; - } - } - else + if (latestVersion != null) { - throw new AuthenticationException("Invalid token."); + var manager = new StorageManager(); + var container = manager.GetContainer(MachineServiceConfig.MACHINE_STUDIO_VERSIONS_CONTAINER); + var blob = container.GetBlockBlobReference(latestVersion.BlobName); + + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + response.Version = latestVersion.Version; } } return response; } + /// + /// Uploads a version. + /// + /// The request. + /// + /// New version must be greater than latest version. + /// Invalid user credentials. [HttpPost] + [MachineStudioLoginFilter] public UploadVersionResponse UploadVersion(UploadVersionRequest request) { UploadVersionResponse response = new UploadVersionResponse(); @@ -132,7 +150,9 @@ namespace Tango.MachineService.Controllers db.UsersRoles.ToList(); db.RolesPermissions.ToList(); - var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + String userID = TokensManager.GetUserID(request.AccessToken); + + var user = db.Users.SingleOrDefault(x => x.Guid == userID); if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersions)) { @@ -173,10 +193,17 @@ namespace Tango.MachineService.Controllers return response; } + /// + /// Notifies about a version upload completion. + /// + /// The request. + /// + /// Invalid Token. [HttpPost] + [MachineStudioLoginFilter] public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) { - MachineStudioPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.AccessToken); + MachineStudioPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); if (upload != null) { @@ -203,6 +230,11 @@ namespace Tango.MachineService.Controllers } } + /// + /// Gets the latest version. + /// + /// The request. + /// [HttpPost] public LatestVersionResponse GetLatestVersion(LatestVersionRequest request) { @@ -213,8 +245,12 @@ namespace Tango.MachineService.Controllers } } - #endregion - + /// + /// Login to the service. + /// + /// The request. + /// + /// [HttpPost] public LoginResponse Login(LoginRequest request) { @@ -235,6 +271,8 @@ namespace Tango.MachineService.Controllers bool versionChangeRequired = false; String requiredVersion = null; + User user = null; + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { db.Roles.ToList(); @@ -242,7 +280,7 @@ namespace Tango.MachineService.Controllers db.UsersRoles.ToList(); db.RolesPermissions.ToList(); - var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower()); + user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower()); IHashGenerator g = new BasicHashGenerator(); @@ -309,11 +347,12 @@ namespace Tango.MachineService.Controllers Password = request.Password, }, - Token = _tokens_manager.CreateNew(), + Token = TokensManager.CreateNew(user.Guid), VersionChangeRequired = versionChangeRequired, RequiredVersion = requiredVersion, }; } + #endregion } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs b/Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs new file mode 100644 index 000000000..3c5798e82 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Filters/MachineStudioLoginFilter.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; +using System.Web; +using System.Web.Http; +using System.Web.Http.Controllers; +using System.Web.Http.Filters; +using Tango.Transport.Web; + +namespace Tango.MachineService.Filters +{ + public class MachineStudioLoginFilter : ActionFilterAttribute + { + public override void OnActionExecuting(HttpActionContext actionContext) + { + var json = actionContext.Request.Content.ReadAsStringAsync().Result; + WebRequestSecureMessage msg = JsonConvert.DeserializeObject(json); + + if (!Controllers.MachineStudioController.TokensManager.Exists(msg.AccessToken)) + { + throw new HttpResponseException(actionContext.Request.CreateErrorResponse(HttpStatusCode.Unauthorized, new AuthenticationException("Invalid Token."))); + } + + base.OnActionExecuting(actionContext); + } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index 048e051c5..ab3215f6b 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -275,6 +275,7 @@ + @@ -377,7 +378,7 @@ False - + -- 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.Common/Tango.MachineStudio.Common.csproj') 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.Common/Tango.MachineStudio.Common.csproj') 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 @@ + - +