From 8270aa37dee33cda98603a995de823df393f7294 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 17 Dec 2018 10:20:36 +0200 Subject: Added support for azure authentication in data source. --- .../MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs') 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 4032c946c..cafd0328a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -69,6 +69,9 @@ namespace Tango.MachineStudio.UI.ViewModels _notificationProvider = notificationProvider; } + /// + /// Called when the application has been started + /// public override void OnApplicationStarted() { base.OnApplicationStarted(); -- cgit v1.3.1 From c3ed01b6c75c44cfeca650b43deb058b1551a9bb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 19 Dec 2018 14:52:54 +0200 Subject: Moved machine studio update azure !!! --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 20578304 -> 20578304 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1516 bytes .../MachineStudioSettings.cs | 3 + .../Tango.MachineStudio.Common.csproj | 6 +- .../Update/CheckForUpdatesRequest.cs | 8 +- .../Update/CheckForUpdatesResponse.cs | 23 +-- .../Update/IMachineStudioUpdateService.cs | 14 +- .../Update/LatestVersionRequest.cs | 15 ++ .../Update/LatestVersionResponse.cs | 15 ++ .../Update/MachineStudioUpdateService.cs | 42 +++++ .../Update/UploadCompletedRequest.cs | 5 +- .../Update/UploadCompletedResponse.cs | 14 ++ .../Update/UploadVersionRequest.cs | 10 +- .../Update/UploadVersionResponse.cs | 22 +-- .../Tango.MachineStudio.Publisher/MainWindowVM.cs | 40 ++--- .../Tango.MachineStudio.Publisher.csproj | 7 +- .../Tango.MachineStudio.UI.csproj | 3 +- .../ViewModels/LoadingViewVM.cs | 6 +- .../ViewModels/MainViewVM.cs | 5 +- .../ViewModels/UpdateViewVM.cs | 35 ++-- .../PPC/Tango.PPC.Publisher/MainWindowVM.cs | 25 ++- .../Tango.PPC.Publisher/Tango.PPC.Publisher.csproj | 4 + .../Tango.BL/Entities/MachineStudioVersion.cs | 20 +-- .../Tango.DAL.Remote/DB/MACHINE_STUDIO_VERSIONS.cs | 2 +- .../Tango.DAL.Remote/DB/RemoteADO.edmx | 6 +- .../Tango.DAL.Remote/DB/RemoteADO.edmx.diagram | 142 ++++++++-------- .../Tango.Transport/Tango.Transport.csproj | 4 + .../Tango.Transport/Web/StorageBlobDownloader.cs | 65 +++++++ .../Web/StorageBlobProgressEventArgs.cs | 14 ++ .../Tango.Transport/Web/StorageBlobUploader.cs | 61 +++++++ .../Controllers/MachineStudioController.cs | 186 +++++++++++++++++++++ .../Controllers/PPCController.cs | 8 +- .../Tango.MachineService/Helpers/StorageHelper.cs | 6 + .../Models/MachineStudioPendingUpload.cs | 26 +++ .../Models/PPCPendingUpload.cs | 22 +++ .../Tango.MachineService/Models/PendingUpload.cs | 22 --- .../Tango.MachineService.csproj | 8 +- 38 files changed, 651 insertions(+), 243 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionRequest.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/LatestVersionResponse.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs create mode 100644 Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Models/MachineStudioPendingUpload.cs create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpload.cs delete mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Models/PendingUpload.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 5b346239d..260afa6c7 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 1801b28f7..0c46ed4ec 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 09ae17244..adc17d481 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/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs index 67e052ecc..cab3d2bfc 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs @@ -43,6 +43,8 @@ namespace Tango.MachineStudio.Common /// public String UpdateServiceAddress { get; set; } + public String MachineServiceAddress { get; set; } + /// /// Gets or sets the allow beta release. /// @@ -96,6 +98,7 @@ namespace Tango.MachineStudio.Common LastBounds = new Rect(); LoggingCategories = new List(); UpdateServiceAddress = "http://twine01/MachineStudioUpdateService/MachineStudioUpdateService.svc"; + MachineServiceAddress = "http://machineservice.twine-srv.com/"; DefaultIssueReportTags = new List(); StudioModulesBounds = new List(); } 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 8cf65a13d..31d28def8 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 @@ -122,8 +122,12 @@ + + + + @@ -304,7 +308,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 index 0047e311b..11911dd7e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs @@ -4,22 +4,18 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class CheckForUpdatesRequest + public class CheckForUpdatesRequest : WebRequestMessage { - [DataMember] public String Email { get; set; } - [DataMember] public String Password { get; set; } - [DataMember] public String Version { get; set; } - [DataMember] public bool AcceptBetaRelease { 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 index f34f12d8f..b0577f40b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs @@ -4,37 +4,22 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class CheckForUpdatesResponse + public class CheckForUpdatesResponse : WebResponseMessage { - [DataMember] public bool IsUpdateAvailable { get; set; } - [DataMember] public bool IsStable { get; set; } - [DataMember] public String Version { get; set; } - [DataMember] public String Comments { get; set; } - [DataMember] - public String FtpHost { get; set; } - - [DataMember] - public String FilePath { get; set; } - - [DataMember] - public String UserName { get; set; } - - [DataMember] - public String Password { get; set; } - - [DataMember] public bool ForcedUpdate { 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 index 53e49e52c..4a7df7caa 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/IMachineStudioUpdateService.cs @@ -4,23 +4,19 @@ using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; +using System.Threading.Tasks; using Tango.MachineStudio.Common.Update; namespace Tango.MachineStudio.Common.Update { - [ServiceContract] public interface IMachineStudioUpdateService { - [OperationContract] - CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request); + Task CheckForUpdates(CheckForUpdatesRequest request); - [OperationContract] - UploadVersionResponse UploadVersion(UploadVersionRequest request); + Task UploadVersion(UploadVersionRequest request); - [OperationContract] - void NotifyUploadCompleted(UploadCompletedRequest request); + Task NotifyUploadCompleted(UploadCompletedRequest request); - [OperationContract] - String GetLatestVersion(); + 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 new file mode 100644 index 000000000..b4e7bd975 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/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.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 new file mode 100644 index 000000000..b90cbf370 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/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.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 new file mode 100644 index 000000000..aae1fe70d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/MachineStudioUpdateService.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; +using Tango.Transport.Web; + +namespace Tango.MachineStudio.Common.Update +{ + public class MachineStudioUpdateService : IMachineStudioUpdateService + { + private string address; + private WebTransportClient _client; + + public MachineStudioUpdateService() + { + address = SettingsManager.Default.GetOrCreate().MachineServiceAddress + "/api/MachineStudio/"; + _client = new WebTransportClient(); + } + + public Task CheckForUpdates(CheckForUpdatesRequest request) + { + return _client.PostJson(address + "CheckForUpdates", request); + } + + public Task UploadVersion(UploadVersionRequest request) + { + return _client.PostJson(address + "UploadVersion", request); + } + + public Task NotifyUploadCompleted(UploadCompletedRequest request) + { + return _client.PostJson(address + "NotifyUploadCompleted", request); + } + + public Task GetLatestVersion(LatestVersionRequest request) + { + return _client.PostJson(address + "GetLatestVersion", request); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs index ce6096792..fc478db50 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedRequest.cs @@ -4,13 +4,12 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class UploadCompletedRequest + public class UploadCompletedRequest : WebRequestMessage { - [DataMember] public String Token { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadCompletedResponse.cs new file mode 100644 index 000000000..89850e3e5 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/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.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 index 83739f615..c55cb9a22 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionRequest.cs @@ -4,28 +4,22 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class UploadVersionRequest + public class UploadVersionRequest : WebRequestMessage { - [DataMember] public String Email { get; set; } - [DataMember] public String Password { get; set; } - [DataMember] public String Version { get; set; } - [DataMember] public String Comments { get; set; } - [DataMember] public bool ForcedUpdate { get; set; } - [DataMember] public bool IsStable { 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 index 36dc3df30..4d13fc6ad 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/UploadVersionResponse.cs @@ -4,28 +4,14 @@ using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; +using Tango.Transport.Web; namespace Tango.MachineStudio.Common.Update { - [DataContract] - public class UploadVersionResponse + public class UploadVersionResponse : WebResponseMessage { - [DataMember] - public String FtpHost { get; set; } - - [DataMember] - public String FilePath { get; set; } - - [DataMember] - public String FileName { get; set; } - - [DataMember] - public String UserName { get; set; } - - [DataMember] - public String Password { get; set; } - - [DataMember] public String Token { get; set; } + + public String BlobAddress { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs index ffeefb820..73f3f5bed 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/MainWindowVM.cs @@ -19,6 +19,7 @@ using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Update; using Tango.Settings; using Tango.SharedUI; +using Tango.Transport.Web; namespace Tango.MachineStudio.Publisher { @@ -26,7 +27,6 @@ namespace Tango.MachineStudio.Publisher { private BasicHashGenerator _hashGenerator; private String _appPath = AppDomain.CurrentDomain.BaseDirectory + "..\\Release"; - private ChannelFactory _service; private IMachineStudioUpdateService _client; private String _email; @@ -114,14 +114,15 @@ namespace Tango.MachineStudio.Publisher public MainWindowVM() { + _client = new MachineStudioUpdateService(); + MaxProgress = 100; _hashGenerator = new BasicHashGenerator(); PublishCommand = new RelayCommand(Publish, () => Email != null && Password != null && Comments != null && CurrentVersion != null && LatestVersion != null && !IsUpdating && Version.Parse(CurrentVersion) > Version.Parse(LatestVersion)); - _service = UpdateServiceHelper.GetUpdateServiceChannel(); - _client = _service.CreateChannel(); + var client = new MachineStudioUpdateService(); UpdateVersions(); @@ -136,7 +137,7 @@ namespace Tango.MachineStudio.Publisher private void UpdateVersions() { CurrentVersion = FileVersionInfo.GetVersionInfo(_appPath + "\\Tango.MachineStudio.UI.exe").ProductVersion; - LatestVersion = _client.GetLatestVersion(); + LatestVersion = _client.GetLatestVersion(new LatestVersionRequest()).Result.Version; } private void Publish() @@ -152,7 +153,7 @@ namespace Tango.MachineStudio.Publisher Task.Factory.StartNew(() => { IsUpdating = true; - String tempFile = String.Empty; + String tempFile = TemporaryManager.CreateFile(); try { @@ -164,9 +165,7 @@ namespace Tango.MachineStudio.Publisher Comments = Comments, ForcedUpdate = ForcedUpdate, IsStable = IsStable, - }); - - tempFile = Path.Combine(Path.GetTempPath(), response.FileName); + }).Result; using (ZipFile zip = new ZipFile()) { @@ -190,28 +189,23 @@ namespace Tango.MachineStudio.Publisher Progress = 0; MaxProgress = 100; - FileStreamWrapper fs = null; - - using (fs = new FileStreamWrapper(tempFile, FileMode.Open, (current) => - { - InvokeUINow(() => - { - Thread.Sleep(10); - Progress = ((double)current / (double)fs.Length) * 100d; - }); - })) + using (StorageBlobUploader uploader = new StorageBlobUploader(response.BlobAddress,tempFile)) { - using (FtpClient ftp = new FtpClient(response.FtpHost, response.UserName, response.Password)) + uploader.Progress += (x, e) => { - ftp.ConnectAsync().Wait(); - ftp.UploadAsync(fs, response.FilePath, FtpExists.Overwrite, true).Wait(); - } + InvokeUINow(() => + { + Progress = ((double)e.Current / (double)e.Total) * 100d; + }); + }; + + uploader.Upload().Wait(); } _client.NotifyUploadCompleted(new UploadCompletedRequest() { Token = response.Token, - }); + }).Wait(); Progress = 0; UpdateVersions(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj index c462c21f4..a7e3e045b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Publisher/Tango.MachineStudio.Publisher.csproj @@ -55,6 +55,7 @@ ..\..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll + @@ -145,6 +146,10 @@ {8491d07b-c1f6-4b62-a412-41b9fd2d6538} Tango.SharedUI + + {74e700b0-1156-4126-be40-ee450d3c3026} + Tango.Transport + {cb0b0aa2-bb24-4bca-a720-45e397684e12} Tango.MachineStudio.Common @@ -165,7 +170,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index b3926190f..d3c22341d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -69,6 +69,7 @@ ..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + ..\..\packages\SimpleValidator.0.6.1.0\lib\net40\SimpleValidator.dll @@ -609,7 +610,7 @@ copy /Y "$(SolutionDir)Referenced Assemblies\Microsoft.WITDataStore32.dll" "$(Ta - + \ No newline at end of file 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 cafd0328a..545d51ef2 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -94,15 +94,15 @@ namespace Tango.MachineStudio.UI.ViewModels Status = "Checking for critical updates..."; LogManager.Log("Checking for forced update..."); - var service = UpdateServiceHelper.GetUpdateServiceChannel(); - var client = service.CreateChannel(); + + var client = new MachineStudioUpdateService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { Email = "ForceUpdate", Password = "ForceUpdate", Version = ApplicationManager.Version.ToString(), - }); + }).Result; if (response.IsUpdateAvailable && response.ForcedUpdate) { 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 c9cd3276f..befad162c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -359,8 +359,7 @@ namespace Tango.MachineStudio.UI.ViewModels { if (_authenticationProvider.CurrentUser != null) { - var service = UpdateServiceHelper.GetUpdateServiceChannel(); - var client = service.CreateChannel(); + var client = new MachineStudioUpdateService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { @@ -368,7 +367,7 @@ namespace Tango.MachineStudio.UI.ViewModels Password = _authenticationProvider.CurrentUser.Password, Version = _applicationManager.Version.ToString(), AcceptBetaRelease = _settings.AcceptBetaRelease, - }); + }).Result; IsUpdateAvailable = response.IsUpdateAvailable; LatestVersion = response.Version; 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 a9624da2d..af197ca3b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -24,6 +24,7 @@ using Tango.SharedUI; using Tango.MachineStudio.UI.Messages; using Tango.Settings; using Tango.MachineStudio.Common; +using Tango.Transport.Web; namespace Tango.MachineStudio.UI.ViewModels { @@ -193,8 +194,7 @@ namespace Tango.MachineStudio.UI.ViewModels { Thread.Sleep(2000); - service = UpdateServiceHelper.GetUpdateServiceChannel(); - var client = service.CreateChannel(); + var client = new MachineStudioUpdateService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { @@ -202,7 +202,7 @@ namespace Tango.MachineStudio.UI.ViewModels Password = _authentication.CurrentUser.Password, Version = _application.Version.ToString(), AcceptBetaRelease = settings.AcceptBetaRelease, - }); + }).Result; if (response.IsUpdateAvailable) { @@ -260,29 +260,18 @@ namespace Tango.MachineStudio.UI.ViewModels { logManager.Log("Creating temporary file " + tempFile); - int fileSize = 0; - - using (FileStreamWrapper fs = new FileStreamWrapper(tempFile.Path, FileMode.Create, (current) => - { - InvokeUINow(() => - { - Thread.Sleep(10); - DownloadProgress = ((double)current / (double)fileSize) * 100d; - }); - })) + using (StorageBlobDownloader downloader = new StorageBlobDownloader(_updateInfo.BlobAddress, tempFile.Path)) { - using (FtpClient ftp = new FtpClient(_updateInfo.FtpHost, _updateInfo.UserName, _updateInfo.Password)) + downloader.Progress += (x, e) => { - logManager.Log("Connecting to FTP site: " + _updateInfo.FtpHost); - ftp.ConnectAsync().Wait(); - logManager.Log("Retrieving download size..."); - fileSize = (int)ftp.GetFileSize(_updateInfo.FilePath); - logManager.Log("Download size: " + fileSize + " bytes."); - logManager.Log("Starting download..."); - ftp.DownloadAsync(fs, _updateInfo.FilePath).Wait(); - } - } + InvokeUINow(() => + { + DownloadProgress = ((double)e.Current / (double)e.Total) * 100d; + }); + }; + downloader.Download().Wait(); + } Status = UpdateStatus.Updating; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs index 881403ea8..4e7dd304e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/MainWindowVM.cs @@ -26,6 +26,7 @@ using Tango.PPC.Common.Update; using Tango.Settings; using Tango.SharedUI; using Tango.SQLExaminer; +using Tango.Transport.Web; namespace Tango.PPC.Publisher { @@ -234,20 +235,18 @@ namespace Tango.PPC.Publisher Progress = 0; MaxProgress = 100; - CloudBlockBlob blob = new CloudBlockBlob(new Uri(response.BlobAddress)); - - FileStreamWrapper fs = null; - - using (fs = new FileStreamWrapper(tempFile, FileMode.Open, (current) => + using (StorageBlobUploader uploader = new StorageBlobUploader(response.BlobAddress, tempFile)) { - InvokeUINow(() => + uploader.Progress += (x, e) => { - Thread.Sleep(10); - Progress = ((double)current / (double)fs.Length) * 100d; - }); - })) - { - await blob.UploadFromStreamAsync(fs); + InvokeUINow(() => + { + Thread.Sleep(10); + Progress = ((double)e.Current / (double)e.Total) * 100d; + }); + }; + + await uploader.Upload(); } await _client.NotifyUploadCompleted(new UploadCompletedRequest() @@ -277,7 +276,7 @@ namespace Tango.PPC.Publisher dlg.DefaultExt = ".tup"; if (dlg.ShowDialog().Value) { - Task.Factory.StartNew(() => + Task.Factory.StartNew(() => { try { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/Tango.PPC.Publisher.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/Tango.PPC.Publisher.csproj index ef692809f..9a4b8b595 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher/Tango.PPC.Publisher.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher/Tango.PPC.Publisher.csproj @@ -144,6 +144,10 @@ {e1e66ed9-597d-45fa-8048-de90a6930484} Tango.SQLExaminer + + {74e700b0-1156-4126-be40-ee450d3c3026} + Tango.Transport + {0be74eee-22cb-4dba-b896-793b9e1a3ac0} Tango.PPC.Common diff --git a/Software/Visual_Studio/Tango.BL/Entities/MachineStudioVersion.cs b/Software/Visual_Studio/Tango.BL/Entities/MachineStudioVersion.cs index 3167b3ccf..cc1425529 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/MachineStudioVersion.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/MachineStudioVersion.cs @@ -27,7 +27,7 @@ namespace Tango.BL.Entities public event EventHandler VersionChanged; - public event EventHandler FtpFilePathChanged; + public event EventHandler BlobNameChanged; public event EventHandler CommentsChanged; @@ -65,30 +65,30 @@ namespace Tango.BL.Entities } } - protected String _ftpfilepath; + protected String _blobname; /// - /// Gets or sets the machinestudioversion ftp file path. + /// Gets or sets the machinestudioversion blob name. /// - [Column("FTP_FILE_PATH")] + [Column("BLOB_NAME")] - public String FtpFilePath + public String BlobName { get { - return _ftpfilepath; + return _blobname; } set { - if (_ftpfilepath != value) + if (_blobname != value) { - _ftpfilepath = value; + _blobname = value; - FtpFilePathChanged?.Invoke(this, value); + BlobNameChanged?.Invoke(this, value); - RaisePropertyChanged(nameof(FtpFilePath)); + RaisePropertyChanged(nameof(BlobName)); } } } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE_STUDIO_VERSIONS.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE_STUDIO_VERSIONS.cs index eed787485..a4f10de26 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE_STUDIO_VERSIONS.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/MACHINE_STUDIO_VERSIONS.cs @@ -18,7 +18,7 @@ namespace Tango.DAL.Remote.DB public string GUID { get; set; } public System.DateTime LAST_UPDATED { get; set; } public string VERSION { get; set; } - public string FTP_FILE_PATH { get; set; } + public string BLOB_NAME { get; set; } public string COMMENTS { get; set; } public string USER_GUID { get; set; } public bool FORCE_UPDATE { get; set; } diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx index 7a01d5db8..86cf4ed6a 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -669,7 +669,7 @@ - + @@ -3757,7 +3757,7 @@ - + @@ -6032,7 +6032,7 @@ - + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram index c16e38955..cf9ff4f22 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,81 +5,81 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - + + + + + + diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj index 02e5381ee..4e677a041 100644 --- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj +++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj @@ -34,6 +34,7 @@ ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll @@ -111,6 +112,9 @@ + + + diff --git a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs new file mode 100644 index 000000000..603463823 --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobDownloader.cs @@ -0,0 +1,65 @@ +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.IO; + +namespace Tango.Transport.Web +{ + public class StorageBlobDownloader : IDisposable + { + private bool _disposed; + private FileStreamWrapper _stream; + private long _fileSize; + + public CloudBlockBlob Blob { get; private set; } + + public event EventHandler Progress; + + public StorageBlobDownloader(CloudBlockBlob blob, String fileName) + { + Blob = blob; + _stream = new FileStreamWrapper(fileName, FileMode.Create, OnProgress); + } + + public StorageBlobDownloader(String blobAddress, String fileName) : this(new CloudBlockBlob(new Uri(blobAddress)), fileName) + { + + } + + private void OnProgress(long current) + { + Progress?.Invoke(this, new StorageBlobProgressEventArgs() + { + Current = current, + Total = _fileSize, + }); + } + + public async Task Download() + { + if (_disposed) + { + throw new ObjectDisposedException("The storage blob downloader can only be used once."); + } + + await Blob.FetchAttributesAsync(); + _fileSize = Blob.Properties.Length; + + await Blob.DownloadToStreamAsync(_stream); + Dispose(); + } + + public void Dispose() + { + if (!_disposed) + { + _disposed = true; + _stream.Dispose(); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs new file mode 100644 index 000000000..ae48e34cf --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobProgressEventArgs.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Web +{ + public class StorageBlobProgressEventArgs : EventArgs + { + public long Total { get; set; } + public long Current { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs new file mode 100644 index 000000000..8d645f33f --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Web/StorageBlobUploader.cs @@ -0,0 +1,61 @@ +using Microsoft.WindowsAzure.Storage.Blob; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.IO; + +namespace Tango.Transport.Web +{ + public class StorageBlobUploader : IDisposable + { + private bool _disposed; + private FileStreamWrapper _stream; + + public CloudBlockBlob Blob { get; private set; } + + public event EventHandler Progress; + + public StorageBlobUploader(CloudBlockBlob blob, String fileName) + { + Blob = blob; + _stream = new FileStreamWrapper(fileName, FileMode.Open, OnProgress); + } + + public StorageBlobUploader(String blobAddress, String fileName) : this(new CloudBlockBlob(new Uri(blobAddress)), fileName) + { + + } + + private void OnProgress(long current) + { + Progress?.Invoke(this, new StorageBlobProgressEventArgs() + { + Current = current, + Total = _stream.Length, + }); + } + + public async Task Upload() + { + if (_disposed) + { + throw new ObjectDisposedException("The storage blob uploader can only be used once."); + } + + await Blob.UploadFromStreamAsync(_stream); + Dispose(); + } + + public void Dispose() + { + if (!_disposed) + { + _disposed = true; + _stream.Dispose(); + } + } + } +} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs new file mode 100644 index 000000000..245c18b9b --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -0,0 +1,186 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Security.Authentication; +using System.Web.Http; +using Tango.BL; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.MachineService.Helpers; +using Tango.MachineService.Models; +using Tango.MachineStudio.Common.Update; + +namespace Tango.MachineService.Controllers +{ + public class MachineStudioController : JsonController + { + private static List _pendingUploads; + + static MachineStudioController() + { + _pendingUploads = new List(); + } + + [HttpPost] + public CheckForUpdatesResponse CheckForUpdates(CheckForUpdatesRequest request) + { + LogManager.Log("Request received..."); + + CheckForUpdatesResponse response = new CheckForUpdatesResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + //Load relation first... + db.Roles.ToList(); + db.Permissions.ToList(); + db.UsersRoles.ToList(); + db.RolesPermissions.ToList(); + + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + + if (user != null && user.HasPermission(Permissions.RunMachineStudio) || (request.Email == "ForceUpdate")) + { + var versions = db.MachineStudioVersions.ToList(); + + MachineStudioVersion latestVersion = null; + + if (request.AcceptBetaRelease) + { + latestVersion = versions.OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + } + else + { + latestVersion = versions.Where(x => x.Stable).OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + } + + Version currentVersion = Version.Parse(request.Version); + + bool isForcedUpdate = versions.Exists(x => x.ForceUpdate && Version.Parse(x.Version) > currentVersion); + + 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 client = StorageHelper.GetStorageBlobClient(); + var container = StorageHelper.GetMachineStudioVersionsContainer(client); + var blob = container.GetBlockBlobReference(latestVersion.BlobName); + + response.BlobAddress = StorageHelper.GenerateBlobReadSignature(blob, TimeSpan.FromMinutes(60)); + + response.IsUpdateAvailable = true; + response.Version = latestVersion.Version; + response.Comments = latestVersion.Comments; + response.ForcedUpdate = isForcedUpdate; + response.IsStable = latestVersion.Stable; + } + } + else + { + throw new AuthenticationException("Invalid user credentials."); + } + } + + return response; + } + + [HttpPost] + public UploadVersionResponse UploadVersion(UploadVersionRequest request) + { + UploadVersionResponse response = new UploadVersionResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + //Load relation first... + db.Roles.ToList(); + db.Permissions.ToList(); + db.UsersRoles.ToList(); + db.RolesPermissions.ToList(); + + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + + if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersion)) + { + var latestVersion = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + Version currentVersion = Version.Parse(request.Version); + + if (latestVersion == null || currentVersion > Version.Parse(latestVersion.Version)) + { + String newVersionFileName = "Machine Studio Version" + " " + currentVersion.ToString() + ".zip"; + + var client = StorageHelper.GetStorageBlobClient(); + var container = StorageHelper.GetMachineStudioVersionsContainer(client); + var blob = StorageHelper.CreateEmptyBlob(container, newVersionFileName); + + response.Token = Guid.NewGuid().ToString(); + response.BlobAddress = StorageHelper.GenerateBlobWriteSignature(blob, TimeSpan.FromMinutes(30)); + + _pendingUploads.Add(new MachineStudioPendingUpload() + { + UserGuid = user.Guid, + Comments = request.Comments, + ForcedUpdate = request.ForcedUpdate, + Token = response.Token, + Version = request.Version, + IsStable = request.IsStable, + BlobName = blob.Name, + }); + } + else + { + throw new ArgumentException("New version must be greater than latest version."); + } + } + else + { + throw new AuthenticationException("Invalid user credentials."); + } + } + + return response; + } + + [HttpPost] + public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) + { + MachineStudioPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); + + if (upload != null) + { + _pendingUploads.RemoveAll(x => x.Token == upload.Token); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + db.MachineStudioVersions.Add(new MachineStudioVersion() + { + Comments = upload.Comments, + BlobName = upload.BlobName, + UserGuid = upload.UserGuid, + Version = upload.Version, + ForceUpdate = upload.ForcedUpdate, + Stable = upload.IsStable, + }); + + db.SaveChanges(); + } + + return new UploadCompletedResponse(); + } + else + { + throw new ArgumentException("Invalid Token."); + } + } + + [HttpPost] + public LatestVersionResponse GetLatestVersion(LatestVersionRequest request) + { + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + var version = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); + return new LatestVersionResponse() { Version = version != null ? version.Version : "0.0.0.0" }; + } + } + } +} diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 45396e47a..9ce22bbb0 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -37,13 +37,13 @@ namespace Tango.MachineService.Controllers { public class PPCController : JsonController { - private static List _pendingUploads; + private static List _pendingUploads; #region Constructors static PPCController() { - _pendingUploads = new List(); + _pendingUploads = new List(); } #endregion @@ -315,7 +315,7 @@ namespace Tango.MachineService.Controllers response.Token = Guid.NewGuid().ToString(); response.BlobAddress = StorageHelper.GenerateBlobWriteSignature(blob, TimeSpan.FromMinutes(30)); - _pendingUploads.Add(new PendingUpload() + _pendingUploads.Add(new PPCPendingUpload() { UserGuid = user.Guid, Comments = request.Comments, @@ -342,7 +342,7 @@ namespace Tango.MachineService.Controllers [HttpPost] public UploadCompletedResponse NotifyUploadCompleted(UploadCompletedRequest request) { - PendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); + PPCPendingUpload upload = _pendingUploads.FirstOrDefault(x => x.Token == request.Token); if (upload != null) { diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs index 04d5bbffe..a2cc2a0dc 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/StorageHelper.cs @@ -24,6 +24,12 @@ namespace Tango.MachineService.Helpers return container; } + public static CloudBlobContainer GetMachineStudioVersionsContainer(CloudBlobClient client) + { + var container = client.GetContainerReference("machine-studio-versions"); + return container; + } + public static CloudBlockBlob CreateEmptyBlob(CloudBlobContainer container, String name) { CloudBlockBlob emptyBlob = container.GetBlockBlobReference(name); diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Models/MachineStudioPendingUpload.cs b/Software/Visual_Studio/Web/Tango.MachineService/Models/MachineStudioPendingUpload.cs new file mode 100644 index 000000000..0347d35ea --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Models/MachineStudioPendingUpload.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Models +{ + public class MachineStudioPendingUpload + { + public String Token { get; set; } + + public String Version { get; set; } + + public String UserGuid { get; set; } + + public String Comments { get; set; } + + public bool ForcedUpdate { get; set; } + + public String FilePath { get; set; } + + public bool IsStable { get; set; } + + public String BlobName { get; set; } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpload.cs b/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpload.cs new file mode 100644 index 000000000..10797e758 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Models/PPCPendingUpload.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Models +{ + public class PPCPendingUpload + { + public String Token { get; set; } + + public String Version { get; set; } + + public String UserGuid { get; set; } + + public String Comments { get; set; } + + public String MachineVersionGuid { get; set; } + + public String BlobName { get; set; } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Models/PendingUpload.cs b/Software/Visual_Studio/Web/Tango.MachineService/Models/PendingUpload.cs deleted file mode 100644 index f18b3756a..000000000 --- a/Software/Visual_Studio/Web/Tango.MachineService/Models/PendingUpload.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - -namespace Tango.MachineService.Models -{ - public class PendingUpload - { - public String Token { get; set; } - - public String Version { get; set; } - - public String UserGuid { get; set; } - - public String Comments { get; set; } - - public String MachineVersionGuid { get; set; } - - public String BlobName { get; set; } - } -} \ 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 acb4ad84e..c6245e18e 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -270,11 +270,13 @@ + - + + @@ -305,6 +307,10 @@ + + {CB0B0AA2-BB24-4BCA-A720-45E397684E12} + Tango.MachineStudio.Common + {0be74eee-22cb-4dba-b896-793b9e1a3ac0} Tango.PPC.Common -- cgit v1.3.1 From 4e496467dcc8549605917a44263d78cef40f71bb Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 23 Dec 2018 12:44:08 +0200 Subject: Implemented machine studio active directory secure login. --- .../Build/Shortcuts/Machine Studio.lnk | Bin 1516 -> 1581 bytes .../MachineStudioSettings.cs | 5 +--- .../Tango.MachineStudio.Common.csproj | 4 +-- .../DefaultAuthenticationProvider.cs | 19 +++++++++++-- .../ViewModels/LoadingViewVM.cs | 5 ++-- .../ViewModels/LoginViewVM.cs | 16 +++++++---- .../Controllers/MachineStudioController.cs | 31 +++++++++++++-------- .../Controllers/PPCController.cs | 3 ++ .../Helpers/AzureDirectoryHelper.cs | 19 +++++++++++++ .../Tango.MachineService.csproj | 3 +- 10 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index adc17d481..9c594a6b0 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/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs index cab3d2bfc..1d3660c5f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs @@ -39,10 +39,8 @@ namespace Tango.MachineStudio.Common public String LastVirtualMachineSerialNumber { get; set; } /// - /// Gets or sets the update service address. + /// Gets or sets the machine service address. /// - public String UpdateServiceAddress { get; set; } - public String MachineServiceAddress { get; set; } /// @@ -97,7 +95,6 @@ namespace Tango.MachineStudio.Common { LastBounds = new Rect(); LoggingCategories = new List(); - UpdateServiceAddress = "http://twine01/MachineStudioUpdateService/MachineStudioUpdateService.svc"; MachineServiceAddress = "http://machineservice.twine-srv.com/"; DefaultIssueReportTags = new List(); StudioModulesBounds = new List(); 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 ca4d95805..cd99b00d0 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 @@ -127,7 +127,7 @@ - + @@ -310,7 +310,7 @@ - + \ No newline at end of file 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 fd68ed8d1..3293dab3f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -10,6 +10,9 @@ using Tango.MachineStudio.Common.Authentication; using Tango.BL; using Tango.BL.Enumerations; using System.Data.Entity; +using Tango.Transport.Web; +using Tango.Settings; +using Tango.MachineStudio.Common; namespace Tango.MachineStudio.UI.Authentication { @@ -49,11 +52,21 @@ namespace Tango.MachineStudio.UI.Authentication /// Login failed for user " + email public User Login(string email, string password) { - using (ObservablesContext db = ObservablesContext.CreateDefault()) + var settings = SettingsManager.Default.GetOrCreate(); + + IWebTransportClient service = new WebTransportClient(); + var response = service.PostJson(settings.MachineServiceAddress + "/api/MachineStudio/Login", new LoginRequest() { - String hash = User.GetPasswordHash(password); + Email = email, + Password = password, + + }).Result; + ObservablesContext.OverrideSettingsDataSource(response.DataSource); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { db.Roles.Load(); db.Permissions.Load(); db.RolesPermissions.Load(); @@ -62,7 +75,7 @@ namespace Tango.MachineStudio.UI.Authentication .Include(x => x.UsersRoles) .Include(x => x.Contact) .Include(x => x.Address) - .Include(x => x.Organization).SingleOrDefault(x => x.Email.ToLower() == email.ToLower() && x.Password == hash); + .Include(x => x.Organization).SingleOrDefault(x => x.Email.ToLower() == email.ToLower()); if (user == null) { 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 545d51ef2..6e8d0488b 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -144,9 +144,8 @@ namespace Tango.MachineStudio.UI.ViewModels Status = "Loading, please wait..."; - ObservablesStaticCollections.Instance.Initialize(); - - _eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); + //ObservablesStaticCollections.Instance.Initialize(); + //_eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); Status = "Starting application..."; 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 a37879a5e..4e659d46a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -6,6 +6,8 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Enumerations; using Tango.Core.Commands; using Tango.Core.Cryptography; using Tango.MachineStudio.Common; @@ -90,7 +92,7 @@ namespace Tango.MachineStudio.UI.ViewModels _navigationManager = navigationManager; _authenticationProvider = authenticationProvider; _eventLogger = eventLogger; - LoginCommand = new RelayCommand(Login,() => !IsLogging); + LoginCommand = new RelayCommand(Login, () => !IsLogging); cryptographer = new Rfc2898Cryptographer(); Email = _settings.LastLoginEmail; @@ -121,6 +123,10 @@ namespace Tango.MachineStudio.UI.ViewModels await Task.Factory.StartNew(() => { _authenticationProvider.Login(Email, Password); + + ObservablesStaticCollections.Instance.Initialize(); + _eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); + _navigationManager.NavigateTo(NavigationView.MainView); _settings.LastLoginEmail = Email; _settings.RememberMe = RememberMe; @@ -128,13 +134,13 @@ namespace Tango.MachineStudio.UI.ViewModels _settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null; _settings.Save(); - _eventLogger.Log("User logged in"); + _eventLogger.Log("User logged in."); }); } - catch (Exception) + catch (Exception ex) { - - _notificationProvider.ShowError("Invalid credentials. Please try again."); + LogManager.Log(ex, "Login Error."); + _notificationProvider.ShowError($"The specified email or password was incorrect, or you don't have a permission to run this application.\nError: {ex.Message}"); } finally { diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 8225d75e1..8485cd67d 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -14,6 +14,7 @@ using Tango.Core.Cryptography; using Tango.MachineService.Helpers; using Tango.MachineService.Models; using Tango.MachineStudio.Common.Authentication; +using System.Data.Entity; using Tango.MachineStudio.Common.Update; namespace Tango.MachineService.Controllers @@ -191,40 +192,45 @@ namespace Tango.MachineService.Controllers #endregion + [HttpPost] public LoginResponse Login(LoginRequest request) { - var authContext = new AuthenticationContext("https://login.microsoftonline.com/2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4"); - UserCredential userCredential = new UserCredential(request.Email, request.Password); - AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", "ec612854-7abc-457b-808a-5d0c5ba80c57", userCredential); + AuthenticationResult authResult = AzureDirectoryHelper.AuthenticateUser(request.Email, request.Password); using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - db.Roles.ToList(); db.Permissions.ToList(); db.UsersRoles.ToList(); db.RolesPermissions.ToList(); - var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); + var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower()); + + IHashGenerator g = new BasicHashGenerator(); if (user == null) { //Than add the user !! - - IHashGenerator g = new BasicHashGenerator(); - - BL.Entities.User new_user = new User(); + User new_user = new User(); new_user.Email = request.Email; - new_user.Password = g.Encrypt("Aa123456"); - new_user.Organization = db.Organizations.Single(x => x.Name == "Twine"); - new_user.Address = new Address() { }; + new_user.Password = g.Encrypt(request.Password); + new_user.Organization = db.Organizations.Include(x => x.Address).Single(x => x.Name == "Twine"); + new_user.Address = new_user.Organization.Address.Clone(); new_user.Contact = new Contact() { FirstName = authResult.UserInfo.GivenName, LastName = authResult.UserInfo.FamilyName, + FullName = authResult.UserInfo.GivenName + " " + authResult.UserInfo.FamilyName, + Email = request.Email, }; new_user.Roles.Add(db.Roles.Single(x => (Roles)x.Code == Roles.User)); } + else + { + user.Password = g.Encrypt(request.Password); + } + + db.SaveChanges(); } return new LoginResponse() @@ -234,6 +240,7 @@ namespace Tango.MachineService.Controllers Address = Config.DB_ADDRESS, Catalog = Config.DB_CATALOG, Type = Core.DataSourceType.Azure, + IntegratedSecurity = false, UserName = request.Email, Password = request.Password, } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 662883223..68f597fcc 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -108,6 +108,7 @@ namespace Tango.MachineService.Controllers Catalog = Config.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, + IntegratedSecurity = false, Type = DataSourceType.SQLServer, }; @@ -173,6 +174,7 @@ namespace Tango.MachineService.Controllers Catalog = Config.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, + IntegratedSecurity = false, Type = DataSourceType.SQLServer, }; } @@ -249,6 +251,7 @@ namespace Tango.MachineService.Controllers Catalog = Config.DB_CATALOG, UserName = credentials.UserName, Password = credentials.Password, + IntegratedSecurity = false, Type = DataSourceType.SQLServer, }; } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs new file mode 100644 index 000000000..fe7733323 --- /dev/null +++ b/Software/Visual_Studio/Web/Tango.MachineService/Helpers/AzureDirectoryHelper.cs @@ -0,0 +1,19 @@ +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Tango.MachineService.Helpers +{ + public static class AzureDirectoryHelper + { + public static AuthenticationResult AuthenticateUser(String email, String password) + { + var authContext = new AuthenticationContext("https://login.microsoftonline.com/2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4"); + UserCredential userCredential = new UserCredential(email, password); + AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", "ec612854-7abc-457b-808a-5d0c5ba80c57", userCredential); + return authResult; + } + } +} \ 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 5b13d8afd..c05cb5fe7 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -277,6 +277,7 @@ + @@ -379,7 +380,7 @@ False - + -- cgit v1.3.1 From 795444f234f6b45bc83d5c7b28725bd7ebc7ee89 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 24 Dec 2018 17:39:01 +0200 Subject: Working on machine service and machine studio. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 20578304 -> 20578304 bytes .../Authentication/IAuthenticationProvider.cs | 5 +++ .../Authentication/LoginResponse.cs | 1 + .../Update/CheckForUpdatesRequest.cs | 4 +- .../Update/CheckForUpdatesResponse.cs | 2 - .../DefaultAuthenticationProvider.cs | 7 ++++ .../ViewModels/LoadingViewVM.cs | 42 --------------------- .../ViewModels/MainViewVM.cs | 5 +-- .../ViewModels/UpdateViewVM.cs | 3 +- .../Tango.Web/Authentication/TokensManager.cs | 30 +++++++++++++++ .../Tango.Web/Controllers/JsonController.cs | 2 +- Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 1 + .../Controllers/MachineStudioController.cs | 22 ++++------- .../Web/Tango.MachineService/Web.config | 2 +- 15 files changed, 58 insertions(+), 68 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 978deab2f..3068c20a8 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 30de45e33..315369a3f 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf 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 0c2aa3cb7..785dc1523 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs @@ -12,6 +12,11 @@ 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/Authentication/LoginResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs index 075a5ec10..3da033b9f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/LoginResponse.cs @@ -11,5 +11,6 @@ namespace Tango.MachineStudio.Common.Authentication public class LoginResponse : WebResponseMessage { public DataSource DataSource { get; set; } + public String Token { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs index 11911dd7e..cf06e678d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesRequest.cs @@ -10,9 +10,7 @@ namespace Tango.MachineStudio.Common.Update { public class CheckForUpdatesRequest : WebRequestMessage { - public String Email { get; set; } - - public String Password { get; set; } + public String Token { get; set; } 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 index b0577f40b..ae1e958ab 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Update/CheckForUpdatesResponse.cs @@ -18,8 +18,6 @@ namespace Tango.MachineStudio.Common.Update public String Comments { get; set; } - public bool ForcedUpdate { get; set; } - public String BlobAddress { get; set; } } } 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 450756705..4acc76c25 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -63,6 +63,8 @@ namespace Tango.MachineStudio.UI.Authentication }).Result; + AccessToken = response.Token; + ObservablesContext.OverrideSettingsDataSource(response.DataSource); ObservablesStaticCollections.Instance.Initialize(); @@ -107,5 +109,10 @@ 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/ViewModels/LoadingViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs index 6e8d0488b..283ea3637 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -89,48 +89,6 @@ namespace Tango.MachineStudio.UI.ViewModels { try { - try - { - Status = "Checking for critical updates..."; - - LogManager.Log("Checking for forced update..."); - - var client = new MachineStudioUpdateService(); - - CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() - { - Email = "ForceUpdate", - Password = "ForceUpdate", - Version = ApplicationManager.Version.ToString(), - }).Result; - - if (response.IsUpdateAvailable && response.ForcedUpdate) - { - LogManager.Log("Forced update found, Navigating to update view!"); - - InvokeUI(() => - { - if (_notificationProvider.ShowQuestion("Machine Studio has detected a critical update which must be installed in order for the application to run properly. Do you wish to download and install this update?")) - { - TangoMessenger.Default.Send(new Messages.ForcedUpdateMessage() { UpdateResponse = response }); - _navigationManager.NavigateTo(NavigationView.UpdateView); - } - else - { - ApplicationManager.ShutDown(); - } - - IsLoading = false; - }); - - return; - } - } - catch (Exception ex) - { - LogManager.Log(ex, "Error checking for forced update!"); - } - try { Status = "Connecting to Team Foundation Services..."; 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 befad162c..818d507ae 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -363,8 +363,7 @@ namespace Tango.MachineStudio.UI.ViewModels CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { - Email = _authenticationProvider.CurrentUser.Email, - Password = _authenticationProvider.CurrentUser.Password, + Token = _authenticationProvider.AccessToken, Version = _applicationManager.Version.ToString(), AcceptBetaRelease = _settings.AcceptBetaRelease, }).Result; @@ -455,7 +454,7 @@ namespace Tango.MachineStudio.UI.ViewModels //Check machine exist on my database first if (x.SelectedMachine.Machine == null) { - _notificationProvider.ShowError( $"The specified machine '{x.SelectedMachine.SerialNumber}' could not be found on the database. Aborting connection."); + _notificationProvider.ShowError($"The specified machine '{x.SelectedMachine.SerialNumber}' could not be found on the database. Aborting connection."); return; } 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 3fec96629..e19dcdbe5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -196,8 +196,7 @@ namespace Tango.MachineStudio.UI.ViewModels CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { - Email = _authentication.CurrentUser.Email, - Password = _authentication.CurrentUser.Password, + Token = _authentication.AccessToken, Version = _application.Version.ToString(), AcceptBetaRelease = settings.AcceptBetaRelease, }).Result; diff --git a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs new file mode 100644 index 000000000..20fc8ab50 --- /dev/null +++ b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Web.Authentication +{ + public class TokensManager + { + private List _tokens; + + public TokensManager() + { + _tokens = new List(); + } + + public String CreateNew() + { + String token = Guid.NewGuid().ToString(); + _tokens.Add(token); + return token; + } + + public bool Exists(String token) + { + return _tokens.Contains(token); + } + } +} diff --git a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs b/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs index a581d9ec7..9d9016d5a 100644 --- a/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs +++ b/Software/Visual_Studio/Tango.Web/Controllers/JsonController.cs @@ -65,7 +65,7 @@ namespace Tango.Web.Controllers code = HttpStatusCode.Unauthorized; } - throw new HttpResponseException(Request.CreateErrorResponse(code, ex.Message)); + throw new HttpResponseException(Request.CreateErrorResponse(code, ex.ToString())); } } } diff --git a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj index 9d199a409..385b3bde8 100644 --- a/Software/Visual_Studio/Tango.Web/Tango.Web.csproj +++ b/Software/Visual_Studio/Tango.Web/Tango.Web.csproj @@ -228,6 +228,7 @@ GlobalVersionInfo.cs + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 8d46ed7d9..18f8dbc0b 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -18,15 +18,18 @@ using Tango.MachineStudio.Common.Update; using Tango.Web.Controllers; using Tango.Web.Helpers; using Tango.Web.Storage; +using Tango.Web.Authentication; namespace Tango.MachineService.Controllers { public class MachineStudioController : JsonController { + private static TokensManager _tokens_manager; private static List _pendingUploads; static MachineStudioController() { + _tokens_manager = new TokensManager(); _pendingUploads = new List(); } @@ -41,15 +44,7 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - //Load relation first... - db.Roles.ToList(); - db.Permissions.ToList(); - db.UsersRoles.ToList(); - db.RolesPermissions.ToList(); - - var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == request.Password); - - if (user != null && user.HasPermission(Permissions.RunMachineStudio) || (request.Email == "ForceUpdate")) + if (_tokens_manager.Exists(request.Token)) { var versions = db.MachineStudioVersions.ToList(); @@ -66,8 +61,6 @@ namespace Tango.MachineService.Controllers Version currentVersion = Version.Parse(request.Version); - bool isForcedUpdate = versions.Exists(x => x.ForceUpdate && Version.Parse(x.Version) > currentVersion); - 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) @@ -81,13 +74,12 @@ namespace Tango.MachineService.Controllers response.IsUpdateAvailable = true; response.Version = latestVersion.Version; response.Comments = latestVersion.Comments; - response.ForcedUpdate = isForcedUpdate; response.IsStable = latestVersion.Stable; } } else { - throw new AuthenticationException("Invalid user credentials."); + throw new AuthenticationException("Invalid token."); } } @@ -245,7 +237,9 @@ namespace Tango.MachineService.Controllers IntegratedSecurity = false, UserName = request.Email, Password = request.Password, - } + }, + + Token = _tokens_manager.CreateNew() }; } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 77d9a1bb3..097943016 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -19,7 +19,7 @@ - + -- cgit v1.3.1