From 73196dd48da9d16b6949ab9dec0ae0a5d63accfe Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 14 Feb 2019 18:50:59 +0200 Subject: Working on DFU firmware upgrade... --- .../ViewModels/FirmwareUpgradeViewVM.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs index 09b63cfc9..14b9d0d8e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -5,11 +5,14 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; using Tango.Core.Commands; using Tango.Integration.Operation; using Tango.Integration.Upgrade; using Tango.MachineStudio.Common.Notifications; using Tango.SharedUI; +using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.UI.ViewModels { @@ -96,6 +99,10 @@ namespace Tango.MachineStudio.UI.ViewModels try { + IsFree = false; + + _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU; + _stream = new FileStream(SelectedFile, FileMode.Open); Handler = await _operator.UpgradeFirmware(_stream); Handler.Progress += (_, e) => @@ -104,18 +111,22 @@ namespace Tango.MachineStudio.UI.ViewModels { AbortCommand.RaiseCanExecuteChanged(); }); + + UIHelper.DoEvents(); }; Handler.Completed += (_, __) => { CanClose = true; _stream.Dispose(); CurrentPage = 2; + IsFree = true; }; Handler.Canceled += (_, __) => { CanClose = true; _stream.Dispose(); CurrentPage = 0; + IsFree = true; }; Handler.Failed += (_, ex) => { @@ -123,10 +134,12 @@ namespace Tango.MachineStudio.UI.ViewModels CanClose = true; _stream.Dispose(); CurrentPage = 3; + IsFree = true; }; } catch (Exception ex) { + IsFree = true; CanClose = true; UpgradeError = ex.FlattenMessage(); CurrentPage = 3; -- cgit v1.3.1 From 0cd0b590f62b31a8874ea21f225ba75c7a37053c Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 17 Feb 2019 11:46:27 +0200 Subject: Improved firmware upgrade.. Added firmware upgrade type selection to machine studio. Made upload hw config async when connecting. Removed success message for hw upload after connect. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../ViewModels/FirmwareUpgradeViewVM.cs | 40 ++++++++++++++++++++- .../ViewModels/MainViewVM.cs | 18 ++++++---- .../Views/FirmwareUpgradeView.xaml | 17 ++++++--- .../Tango.Integration/Operation/MachineOperator.cs | 16 +++++++-- .../Upgrade/FirmwareUpgradeStatus.cs | 2 +- 9 files changed, 76 insertions(+), 17 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 1780c8e20..e31f48019 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 804f5dce4..c69dbfe8d 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 415dd596f..3c2a1b2d6 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 dcaff17f4..6b8cc9fc2 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.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs index 14b9d0d8e..e3726f1dd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -50,6 +50,35 @@ namespace Tango.MachineStudio.UI.ViewModels set { upgradeError = value; RaisePropertyChangedAuto(); } } + private bool _dfu; + public bool DFU + { + get { return _dfu; } + set + { + _dfu = value; RaisePropertyChangedAuto(); + + if (_dfu) + { + UploadTFP = false; + } + } + } + + private bool _uploadTFP; + public bool UploadTFP + { + get { return _uploadTFP; } + set + { + _uploadTFP = value; RaisePropertyChangedAuto(); + + if (_uploadTFP) + { + DFU = false; + } + } + } public RelayCommand SelectCommand { get; set; } @@ -59,6 +88,8 @@ namespace Tango.MachineStudio.UI.ViewModels public FirmwareUpgradeViewVM(IMachineOperator machineOperator, INotificationProvider notificationProvider) : base() { + DFU = true; + UploadTFP = true; _notification = notificationProvider; _operator = machineOperator; SelectCommand = new RelayCommand(BrowseForFile); @@ -101,7 +132,14 @@ namespace Tango.MachineStudio.UI.ViewModels { IsFree = false; - _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU; + if (UploadTFP) + { + _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; + } + else + { + _operator.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU; + } _stream = new FileStream(SelectedFile, FileMode.Open); Handler = await _operator.UpgradeFirmware(_stream); 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 573e56fff..1d03dd389 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -11,6 +11,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; using Tango.BL; +using Tango.BL.Builders; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Core.DI; @@ -483,7 +484,7 @@ namespace Tango.MachineStudio.UI.ViewModels if (x.UploadHardwareConfiguration) { - UploadHardwareConfiguration(); + UploadHardwareConfiguration(false); } } @@ -525,7 +526,7 @@ namespace Tango.MachineStudio.UI.ViewModels if (x.UploadHardwareConfiguration) { - UploadHardwareConfiguration(); + UploadHardwareConfiguration(false); } } catch (Exception ex) @@ -615,18 +616,21 @@ namespace Tango.MachineStudio.UI.ViewModels InvalidateRelayCommands(); } - private async void UploadHardwareConfiguration() + private async void UploadHardwareConfiguration(bool showSuccessMessage = true) { try { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var config = db.Adapter.GetConfiguration(s => s.Guid == ApplicationManager.Machine.ConfigurationGuid); - var hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.Machine.Guid); + var config = (await new ConfigurationBuilder(db).Set(ApplicationManager.Machine.ConfigurationGuid).WithIdsPacks().WithHardwareVersion().BuildAsync()); - await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(hw, config); + await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(config.HardwareVersion, config); + } + + if (showSuccessMessage) + { + NotificationProvider.ShowInfo("Hardware configuration uploaded successfully."); } - NotificationProvider.ShowInfo("Hardware configuration uploaded successfully."); } catch (Exception ex) { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml index 4de64db12..9acd0386a 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/FirmwareUpgradeView.xaml @@ -25,7 +25,7 @@ - + @@ -58,10 +58,17 @@ Press 'SELECT' to browse for an .tfp file (Tango Firmware Package). - - - - + + + + + + + + DFU + DFU & Package + + diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index d421120ea..e170b2fb8 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -2093,7 +2093,7 @@ namespace Tango.Integration.Operation FirmwareUpgradeManager upgradeManager = new FirmwareUpgradeManager(); upgradeManager.UpgradeProgress += (sender, e) => { - upgradeHandler.Total = 100; + upgradeHandler.Total = (long)e.Total; upgradeHandler.RaiseProgress((long)e.Progress, FirmwareUpgradeStatus.Upgrading, e.State.ToDescription()); }; @@ -2105,16 +2105,26 @@ namespace Tango.Integration.Operation } upgradeManager.PerformUpgrade(data).Wait(); - upgradeHandler.Total = zip.Entries.Sum(x => x.UncompressedSize); - Thread.Sleep(2000); + upgradeHandler.RaiseProgress(100, FirmwareUpgradeStatus.Upgrading, "Waiting for the device..."); + Thread.Sleep(5000); + + upgradeHandler.RaiseProgress(100, FirmwareUpgradeStatus.Upgrading, "Connecting..."); Adapter.Connect().Wait(); Connect().Wait(); + + upgradeHandler.RaiseProgress(100, FirmwareUpgradeStatus.Upgrading, "Connected."); + Thread.Sleep(2000); + + upgradeHandler.RaiseProgress(100, FirmwareUpgradeStatus.Upgrading, "Waiting..."); + Thread.Sleep(2000); + Status = MachineStatuses.Upgrading; } if (FirmwareUpgradeMode.HasFlag(FirmwareUpgradeModes.TFP_PACKAGE)) { + upgradeHandler.Total = zip.Entries.Sum(x => x.UncompressedSize); uploadNext(); } else diff --git a/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs index cf9cb2364..72a892d04 100644 --- a/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs +++ b/Software/Visual_Studio/Tango.Integration/Upgrade/FirmwareUpgradeStatus.cs @@ -11,7 +11,7 @@ namespace Tango.Integration.Upgrade { [Description("Initializing...")] Initializing, - [Description("Upgrading Firmware...")] + [Description("Upgrading firmware...")] Upgrading, [Description("Uploading files...")] Uploading, -- cgit v1.3.1 From e29d962c5602fc9fc3a54fa4da8957609de7eea4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 17 Feb 2019 15:52:11 +0200 Subject: Completed PPC watchdog ! --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/Graphics/Mobile/cat24.ico | Bin 0 -> 105237 bytes Software/Graphics/Mobile/cat24.png | Bin 0 -> 1433 bytes .../ViewModels/FirmwareUpgradeViewVM.cs | 1 - .../PPC/Tango.PPC.Common/PPCSettings.cs | 6 + .../Tango.PPC.Common/WatchDog/WatchDogClient.cs | 87 ++++++++++- .../Tango.PPC.Common/WatchDog/WatchDogServer.cs | 108 ++++++++++++-- .../Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs | 1 + .../PPC/Tango.PPC.UI/MainWindow.xaml.cs | 2 +- .../PPCApplication/DefaultPPCApplicationManager.cs | 44 +++++- .../Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 4 +- .../Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs | 2 +- .../PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs | 1 + .../PPC/Tango.PPC.WatchDog/App.xaml.cs | 12 ++ .../PPC/Tango.PPC.WatchDog/MainWindow.xaml | 37 +++-- .../PPC/Tango.PPC.WatchDog/MainWindow.xaml.cs | 44 ++++++ .../PPC/Tango.PPC.WatchDog/MainWindowVM.cs | 107 ++++++++++++++ .../Tango.PPC.WatchDog/Tango.PPC.WatchDog.csproj | 16 +- .../Visual_Studio/PPC/Tango.PPC.WatchDog/cat24.ico | Bin 0 -> 105237 bytes .../Visual_Studio/PPC/Tango.PPC.WatchDog/close.png | Bin 651 -> 0 bytes .../Tango.SharedUI/Components/TextController.cs | 163 +++++++++++++++++++++ .../Tango.SharedUI/Tango.SharedUI.csproj | 3 +- 23 files changed, 598 insertions(+), 40 deletions(-) create mode 100644 Software/Graphics/Mobile/cat24.ico create mode 100644 Software/Graphics/Mobile/cat24.png create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.WatchDog/cat24.ico delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.WatchDog/close.png create mode 100644 Software/Visual_Studio/Tango.SharedUI/Components/TextController.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index e31f48019..de6d72eeb 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index c69dbfe8d..79fde42df 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Graphics/Mobile/cat24.ico b/Software/Graphics/Mobile/cat24.ico new file mode 100644 index 000000000..6fa3cb368 Binary files /dev/null and b/Software/Graphics/Mobile/cat24.ico differ diff --git a/Software/Graphics/Mobile/cat24.png b/Software/Graphics/Mobile/cat24.png new file mode 100644 index 000000000..1fc35c8fe Binary files /dev/null and b/Software/Graphics/Mobile/cat24.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs index e3726f1dd..e54c28e17 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -89,7 +89,6 @@ namespace Tango.MachineStudio.UI.ViewModels public FirmwareUpgradeViewVM(IMachineOperator machineOperator, INotificationProvider notificationProvider) : base() { DFU = true; - UploadTFP = true; _notification = notificationProvider; _operator = machineOperator; SelectCommand = new RelayCommand(BrowseForFile); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index 7b617ddaa..409dd1cfc 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -71,6 +71,11 @@ namespace Tango.PPC.Common /// public DeploymentSlot DeploymentSlot { get; set; } + /// + /// Gets or sets a value indicating whether to enable the watch dog process. + /// + public bool EnableWatchDog { get; set; } + /// /// Gets the machine service address. /// @@ -91,6 +96,7 @@ namespace Tango.PPC.Common ExternalBridgePassword = "Aa123456"; HotSpotPassword = "Aa123456"; DeploymentSlot = DeploymentSlot.TEST; + EnableWatchDog = true; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogClient.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogClient.cs index 47a24ea85..bbdfbf7e2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogClient.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogClient.cs @@ -1,12 +1,97 @@ using System; using System.Collections.Generic; +using System.IO; +using System.IO.Pipes; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; +using Tango.Core; namespace Tango.PPC.Common.WatchDog { - public class WatchDogClient + public class WatchDogClient : ExtendedObject { + public event EventHandler ServerNotResponding; + + private NamedPipeClientStream _client; + private StreamReader _reader; + private StreamWriter _writer; + private Thread _thread; + + public bool IsStarted { get; private set; } + + public TimeSpan Interval { get; set; } + + public WatchDogClient() + { + Interval = TimeSpan.FromSeconds(5); + } + + public void Start() + { + if (!IsStarted) + { + LogManager.Log("Starting watchdog client..."); + + IsStarted = true; + + _thread = new Thread(ThreadMethod); + _thread.IsBackground = true; + _thread.Start(); + } + } + + private void ThreadMethod() + { + try + { + LogManager.Log("Watchdog client started."); + + while (IsStarted) + { + _client = new NamedPipeClientStream("Tango_Watch_Dog_Pipe"); + _client.Connect(5000); + + _reader = new StreamReader(_client); + _writer = new StreamWriter(_client); + + _writer.WriteLine("ping"); + _writer.Flush(); + + var line = _reader.ReadLine(); + + if (line != "ping") + { + LogManager.Log("Watchdog server not found. Raising notification..."); + try + { + IsStarted = false; + _client.Dispose(); + } + catch { } + + ServerNotResponding?.Invoke(this, new EventArgs()); + return; + } + + _client.Dispose(); + + Thread.Sleep(Interval); + } + } + catch (Exception ex) + { + IsStarted = false; + LogManager.Log(ex, "Error in watchdog client."); + ServerNotResponding?.Invoke(this, new EventArgs()); + } + } + + public void Stop() + { + IsStarted = false; + _client.Dispose(); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogServer.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogServer.cs index 77bca2e30..84ff68d08 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogServer.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/WatchDog/WatchDogServer.cs @@ -1,26 +1,60 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.IO.Pipes; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Threading; +using Tango.Core; +using Tango.Core.Helpers; namespace Tango.PPC.Common.WatchDog { - public class WatchDogServer + public class WatchDogServer : ExtendedObject, IDisposable { private NamedPipeServerStream _server; + private StreamReader _reader; + private StreamWriter _writer; private Thread _thread; + private Dispatcher _dispatcher; + private String _watchdogAppPath; + private Process _watchdogProcess; public bool IsStarted { get; private set; } + public WatchDogServer(Dispatcher uiDispatcher) + { + _watchdogAppPath = Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), "Tango.PPC.WatchDog.exe"); + + _dispatcher = uiDispatcher; + } + public void Start() { - _thread = new Thread(ThreadMethod); - _thread.IsBackground = true; - _thread.Start(); + LogManager.Log("Starting watchdog server..."); + + try + { + _watchdogProcess = Process.GetProcessesByName("Tango.PPC.WatchDog").FirstOrDefault(); + + _server = new NamedPipeServerStream("Tango_Watch_Dog_Pipe"); + _reader = new StreamReader(_server); + _writer = new StreamWriter(_server); + + IsStarted = true; + _thread = new Thread(ThreadMethod); + _thread.IsBackground = true; + _thread.Start(); + + LogManager.Log("Watchdog server started."); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error starting watchdog server!"); + } } private void ThreadMethod() @@ -29,27 +63,73 @@ namespace Tango.PPC.Common.WatchDog try { - _server = new NamedPipeServerStream("Tango_Watch_Dog_Pipe"); - _server.WaitForConnection(); - StreamReader reader = new StreamReader(_server); - StreamWriter writer = new StreamWriter(_server); - while (IsStarted) { - var line = reader.ReadLine(); - writer.WriteLine(line); - writer.Flush(); + if (_watchdogProcess == null) + { + LogManager.Log($"Starting watchdog process at '{_watchdogAppPath}'..."); + + try + { + _watchdogProcess = Process.Start(_watchdogAppPath); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error starting watchdog process!"); + return; + } + } + + _server.WaitForConnection(); + + var line = _reader.ReadLine(); + + _dispatcher.Invoke(() => + { + _writer.WriteLine(line); + _writer.Flush(); + }); + + _server.Disconnect(); } } - catch + catch (Exception ex) { + LogManager.Log(ex, "Error in watchdog server. Restarting watchdog..."); IsStarted = false; + + try + { + _server.Dispose(); + } + catch { } + + Start(); + return; } } public void Stop() { - _server.Dispose(); + if (IsStarted) + { + try + { + _watchdogProcess.Kill(); + _watchdogProcess = null; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error killing watchdog process!"); + } + IsStarted = false; + _server.Dispose(); + } + } + + public void Dispose() + { + Stop(); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs index 98ed016ae..0eb982d08 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -12,6 +12,7 @@ using Tango.Core; using Tango.Core.Helpers; using Tango.Logging; using Tango.PPC.Common; +using Tango.PPC.Common.WatchDog; using Tango.Settings; namespace Tango.PPC.UI diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs index 4ca4a1fb7..edc7cce52 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/MainWindow.xaml.cs @@ -89,7 +89,7 @@ namespace Tango.PPC.UI private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - Environment.Exit(0); + TangoIOC.Default.GetInstance().ShutDown(); } protected override void OnPreviewKeyDown(System.Windows.Input.KeyEventArgs e) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 39ce8cd30..43b0cc047 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -27,6 +27,7 @@ using System.Diagnostics; using Tango.PPC.Common.EventLogging; using Tango.BL.Enumerations; using Tango.PPC.Common.Notifications; +using Tango.PPC.Common.WatchDog; namespace Tango.PPC.UI.PPCApplication { @@ -44,6 +45,7 @@ namespace Tango.PPC.UI.PPCApplication private IEventLogger _eventLogger; private IPPCModuleLoader _moduleLoader; private INotificationProvider _notificationProvider; + private WatchDogServer _watchdogServer; /// /// Occurs when a system restart is required. @@ -157,6 +159,14 @@ namespace Tango.PPC.UI.PPCApplication LogManager.Log(settings.ToJsonString()); + //Start watchdog + _watchdogServer = new WatchDogServer(Application.Current.Dispatcher); + + if (settings.EnableWatchDog) + { + _watchdogServer.Start(); + } + LogManager.Log("Reading Core settings..."); var coreSettings = SettingsManager.Default.GetOrCreate(); @@ -323,16 +333,23 @@ namespace Tango.PPC.UI.PPCApplication /// public void ShutDown() { - //TODO: Needs some work on logging and shutdown procedures! Do I really need this? - - LogManager.Log("Shutting down application..."); + if (IsShuttingDown) return; IsShuttingDown = true; - foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) + try { - vm.OnApplicationShuttingDown(); + LogManager.Log("Shutting down application..."); + _watchdogServer.Dispose(); + + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) + { + vm.OnApplicationShuttingDown(); + } } + catch { } + + Environment.Exit(0); } /// @@ -340,6 +357,23 @@ namespace Tango.PPC.UI.PPCApplication /// public void Restart() { + if (IsShuttingDown) return; + + IsShuttingDown = true; + + try + { + LogManager.Log("Restarting the application..."); + + _watchdogServer.Dispose(); + + foreach (var vm in TangoIOC.Default.GetAllInstancesByBase()) + { + vm.OnApplicationShuttingDown(); + } + } + catch { } + Process.Start(Application.ResourceAssembly.Location); Environment.Exit(0); } 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 ee1b39ca6..48aae2b8f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -59,6 +59,7 @@ namespace Tango.PPC.UI.ViewModels private MachineSetupResult _setup_result; private IOperationSystemManager _operationSystemManager; + private IPPCApplicationManager _appManager; #region Properties @@ -193,6 +194,7 @@ namespace Tango.PPC.UI.ViewModels /// The machine setup manager. public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager, IOperationSystemManager operationSystemManager) { + _appManager = applicationManager; MachineSetupManager = machineSetupManager; DeploymentSlot = Settings.DeploymentSlot; @@ -282,7 +284,7 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log($"Executing '{updater_exe}' with arguments '{PathHelper.GetStartupPath()}'..."); Process.Start(updater_exe, PathHelper.GetStartupPath()); LogManager.Log("Terminating application process!"); - Environment.Exit(0); + _appManager.ShutDown(); } /// diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs index 07d034964..2f6199ecb 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineUpdateViewVM.cs @@ -220,7 +220,7 @@ namespace Tango.PPC.UI.ViewModels LogManager.Log($"Executing '{updater_exe}' with arguments '{PathHelper.GetStartupPath()}'..."); Process.Start(updater_exe, PathHelper.GetStartupPath()); LogManager.Log("Terminating application process!"); - Environment.Exit(0); + ApplicationManager.ShutDown(); } else { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs index b01be3734..a4f550a39 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MainViewVM.cs @@ -13,6 +13,7 @@ using Tango.PPC.Common.ExternalBridge; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; +using Tango.PPC.Common.WatchDog; using Tango.SharedUI; namespace Tango.PPC.UI.ViewModels diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.xaml.cs index 3e39963bd..2247b95e5 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/App.xaml.cs @@ -5,6 +5,7 @@ using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; +using Tango.Logging; namespace Tango.PPC.WatchDog { @@ -13,5 +14,16 @@ namespace Tango.PPC.WatchDog /// public partial class App : Application { + private LogManager LogManager = LogManager.Default; + + protected override void OnStartup(StartupEventArgs e) + { + LogManager.RegisterLogger(new FileLogger()); + LogManager.RegisterLogger(new VSOutputLogger()); + + LogManager.Log("Watchdog process started..."); + + base.OnStartup(e); + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml index 4e772e774..82056048e 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml @@ -3,31 +3,44 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:components="clr-namespace:Tango.SharedUI.Components;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.PPC.WatchDog" mc:Ignorable="d" - Title="Tango Watch Dog" Background="Transparent" AllowsTransparency="True" Height="250" Width="500" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="NoResize" Icon="/cat.png" + Title="Tango WatchDog" Visibility="Visible" Background="Transparent" AllowsTransparency="True" Height="400" Width="700" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="NoResize" Icon="/cat.png" d:DataContext="{d:DesignInstance Type=local:MainWindowVM, IsDesignTimeCreatable=False}"> - + - + - Tango Watch Dog - + Tango WatchDog + + + + + - + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml.cs index 585fc3510..1e3c90342 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -7,11 +8,14 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; +using System.Windows.Forms; using System.Windows.Input; +using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.SharedUI.Helpers; namespace Tango.PPC.WatchDog { @@ -20,10 +24,50 @@ namespace Tango.PPC.WatchDog /// public partial class MainWindow : Window { + private NotifyIcon _icon; + public MainWindow() { InitializeComponent(); DataContext = new MainWindowVM(); + Visibility = Visibility.Hidden; + + var helper = new WindowInteropHelper(this); + helper.EnsureHandle(); + + _icon = new NotifyIcon(); + _icon.Icon = new System.Drawing.Icon(Core.Helpers.EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.PPC.WatchDog.cat24.ico")); + _icon.BalloonTipIcon = ToolTipIcon.Info; + _icon.BalloonTipTitle = Title; + _icon.BalloonTipText = "Working..."; + _icon.Click += _icon_Click; + _icon.Visible = true; + } + + private void _icon_Click(object sender, EventArgs e) + { + _icon.Visible = false; + Show(); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + _icon.Visible = true; + Hide(); + } + + protected override void OnClosing(CancelEventArgs e) + { + _icon.Visible = false; + _icon.Dispose(); + base.OnClosing(e); + } + + private void Button_Click_1(object sender, RoutedEventArgs e) + { + _icon.Visible = false; + _icon.Dispose(); + Environment.Exit(0); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindowVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindowVM.cs index a95a9503c..466c178a2 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindowVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/MainWindowVM.cs @@ -1,14 +1,121 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; +using Tango.Core.Helpers; +using Tango.Logging; +using Tango.PPC.Common.WatchDog; using Tango.SharedUI; +using Tango.SharedUI.Components; namespace Tango.PPC.WatchDog { public class MainWindowVM : ViewModel { + private const String tango_process_name = "Tango.PPC.UI"; + private WatchDogClient _watchdog; + public TextController Log { get; set; } + public MainWindowVM() + { + var logger = new SimpleStringLogger(); + logger.LogReceived += Logger_LogReceived; + LogManager.RegisterLogger(logger); + + _watchdog = new WatchDogClient(); + _watchdog.ServerNotResponding += _watchdog_ServerNotResponding; + Log = new TextController(); + + _watchdog.Start(); + } + + private void Logger_LogReceived(object sender, LogItemBase e) + { + if (e is ExceptionLogItem) + { + Log.WriteLine(e.ToString()); + } + else + { + Log.WriteLine($"[{e.TimeStamp.ToString()}] {e.Message}"); + } + } + + private void _watchdog_ServerNotResponding(object sender, EventArgs e) + { + LogManager.Log("PPC application failed to respond!", LogCategory.Warning); + LogManager.Log("Ensuring PPC application is down..."); + + var appProcess = Process.GetProcessesByName(tango_process_name).FirstOrDefault(); + Process p = new Process(); + p.StartInfo.CreateNoWindow = true; + p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + p.StartInfo.FileName = "wmic"; + p.StartInfo.Arguments = String.Format("process where name='{0}' delete", tango_process_name); + + try + { + if (appProcess != null) + { + LogManager.Log("PPC application process found and seems to be frozen. Trying to kill the process..."); + appProcess.Kill(); + + appProcess = Process.GetProcessesByName(tango_process_name).FirstOrDefault(); + + if (appProcess != null) + { + LogManager.Log("Process kill failed. Trying again..."); + p.Start(); + Thread.Sleep(2000); + + appProcess = Process.GetProcessesByName(tango_process_name).FirstOrDefault(); + + if (appProcess == null) + { + LogManager.Log("PPC application is down."); + } + } + else + { + LogManager.Log("PPC application is down."); + } + } + } + catch + { + try + { + LogManager.Log("Process kill failed. Trying again..."); + p.Start(); + Thread.Sleep(2000); + + appProcess = Process.GetProcessesByName(tango_process_name).FirstOrDefault(); + + if (appProcess == null) + { + LogManager.Log("PPC application is down."); + } + } + catch { } + } + + LogManager.Log("Restarting PPC application..."); + + try + { + Process.Start(Path.Combine(AssemblyHelper.GetCurrentAssemblyFolder(), tango_process_name + ".exe")); + LogManager.Log("PPC application started."); + Thread.Sleep(5000); + _watchdog.Start(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error starting PPC application."); + } + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/Tango.PPC.WatchDog.csproj b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/Tango.PPC.WatchDog.csproj index b9429e044..a1e6e5e88 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/Tango.PPC.WatchDog.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/Tango.PPC.WatchDog.csproj @@ -37,6 +37,8 @@ + + @@ -101,18 +103,26 @@ - - - {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core + + {BC932DBD-7CDB-488C-99E4-F02CF441F55E} + Tango.Logging + {8491d07b-c1f6-4b62-a412-41b9fd2d6538} Tango.SharedUI + + {0be74eee-22cb-4dba-b896-793b9e1a3ac0} + Tango.PPC.Common + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/cat24.ico b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/cat24.ico new file mode 100644 index 000000000..6fa3cb368 Binary files /dev/null and b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/cat24.ico differ diff --git a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/close.png b/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/close.png deleted file mode 100644 index 3a040a008..000000000 Binary files a/Software/Visual_Studio/PPC/Tango.PPC.WatchDog/close.png and /dev/null differ diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/TextController.cs b/Software/Visual_Studio/Tango.SharedUI/Components/TextController.cs new file mode 100644 index 000000000..786754d6e --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Components/TextController.cs @@ -0,0 +1,163 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; + +namespace Tango.SharedUI.Components +{ + /// + /// Represents an MVVM TextBox controller + /// + /// + public class TextController : DependencyObject + { + private TextBox _textBox; + private bool _isMouseDown; + + /// + /// Determines whether an element is Controller. + /// + public static readonly DependencyProperty ControllerProperty = + DependencyProperty.RegisterAttached("Controller", + typeof(TextController), typeof(TextController), + new FrameworkPropertyMetadata(null,ControllerChanged)); + + /// + /// On controller changed. + /// + /// The d. + /// The instance containing the event data. + /// The text controller component can only handle elements of type TextBox. + private static void ControllerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d != null && e.NewValue != null) + { + if (!(d is TextBox)) + { + throw new ArgumentException("The text controller component can only handle elements of type TextBox."); + } + + (e.NewValue as TextController).SetTextBox(d as TextBox); + } + } + + /// + /// Sets the Controller attached property. + /// + /// The element. + /// if set to true [value]. + public static void SetController(FrameworkElement element, TextController value) + { + element.SetValue(ControllerProperty, value); + } + + /// + /// Gets the Controller attached property. + /// + /// The element. + /// + public static TextController GetController(FrameworkElement element) + { + return (TextController)element.GetValue(ControllerProperty); + } + + /// + /// Gets or sets a value indicating whether to automatically scroll to end of text. + /// + public bool AutoScrollToEnd { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public TextController() + { + AutoScrollToEnd = true; + } + + /// + /// Sets the text box. + /// + /// The text box. + private void SetTextBox(TextBox textBox) + { + _textBox = textBox; + _textBox.PreviewMouseDown += (_, __) => _isMouseDown = true; + _textBox.PreviewMouseUp += (_, __) => _isMouseDown = false; + } + + /// + /// Appends the specified text. + /// + /// The text. + public void WriteLine(String text) + { + Write(text + Environment.NewLine); + } + + /// + /// Appends the specified text. + /// + /// The text. + public void Write(String text) + { + Invoke(() => + { + _textBox.AppendText(text); + + if (AutoScrollToEnd && !_isMouseDown) + { + ScrollToEnd(); + } + }); + } + + /// + /// Sets the specified text. + /// + /// The text. + public void Set(String text) + { + Invoke(() => + { + _textBox.Text = text; + + if (AutoScrollToEnd && !_isMouseDown) + { + ScrollToEnd(); + } + }); + } + + /// + /// Clears the text. + /// + public void Clear() + { + Invoke(() => + { + _textBox.Clear(); + }); + } + + /// + /// Scrolls to the end of the text. + /// + public void ScrollToEnd() + { + _textBox.ScrollToEnd(); + } + + /// + /// Invokes the specified action. + /// + /// The action. + private void Invoke(Action action) + { + Dispatcher.BeginInvoke(action); + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index 048edca82..65f2fe46b 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -65,6 +65,7 @@ + @@ -233,7 +234,7 @@ - + \ No newline at end of file -- 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.UI/ViewModels') 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.UI/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs index 19f186525..b9a50ec73 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs @@ -18,7 +18,7 @@ namespace Tango.MachineStudio.Common.Publish { public class MachineStudioPublisher : ExtendedObject { - private IMachineStudioService _client; + private IMachineStudioWebService _client; /// /// Occurs on publish progress. @@ -40,7 +40,7 @@ namespace Tango.MachineStudio.Common.Publish /// public MachineStudioPublisher() { - _client = new MachineStudioService(); + _client = new MachineStudioWebService(); Options = new PublishOptions(); } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 40d7da460..d5e62f4e1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -134,10 +134,10 @@ - + - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs deleted file mode 100644 index 748df4644..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioService.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.ServiceModel; -using System.Text; -using System.Threading.Tasks; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public interface IMachineStudioService - { - DeploymentSlot Environment { get; set; } - - Task CheckForUpdates(CheckForUpdatesRequest request); - - Task DownloadLatestVersion(DownloadLatestVersionRequest request); - - Task UploadVersion(UploadVersionRequest request); - - Task NotifyUploadCompleted(UploadCompletedRequest request); - - Task GetLatestVersion(LatestVersionRequest request); - - Task Login(LoginRequest request); - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs new file mode 100644 index 000000000..5a89f688f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.ServiceModel; +using System.Text; +using System.Threading.Tasks; +using Tango.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public interface IMachineStudioWebService + { + DeploymentSlot Environment { get; set; } + + Task CheckForUpdates(CheckForUpdatesRequest request); + + Task DownloadLatestVersion(DownloadLatestVersionRequest request); + + Task UploadVersion(UploadVersionRequest request); + + Task NotifyUploadCompleted(UploadCompletedRequest request); + + Task GetLatestVersion(LatestVersionRequest request); + + Task Login(LoginRequest request); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs deleted file mode 100644 index 8b43146e1..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioService.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.MachineStudio.Common.Authentication; -using Tango.Settings; -using Tango.Transport.Web; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public class MachineStudioService : IMachineStudioService - { - private WebTransportClient _client; - - public DeploymentSlot Environment { get; set; } - - public MachineStudioService() - { - Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; - _client = new WebTransportClient(); - } - - public Task CheckForUpdates(CheckForUpdatesRequest request) - { - return _client.PostJson(GetAddress() + "CheckForUpdates", request); - } - - public Task UploadVersion(UploadVersionRequest request) - { - return _client.PostJson(GetAddress() + "UploadVersion", request); - } - - public Task NotifyUploadCompleted(UploadCompletedRequest request) - { - return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); - } - - public Task GetLatestVersion(LatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "GetLatestVersion", request); - } - - public Task DownloadLatestVersion(DownloadLatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "DownloadLatestVersion", request); - } - - public Task Login(LoginRequest request) - { - return _client.PostJson(GetAddress() + "Login", request); - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/MachineStudio/"; - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs new file mode 100644 index 000000000..d0aa8a5bf --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.MachineStudio.Common.Authentication; +using Tango.Settings; +using Tango.Transport.Web; +using Tango.Web; + +namespace Tango.MachineStudio.Common.Web +{ + public class MachineStudioWebService : IMachineStudioWebService + { + private WebTransportClient _client; + + public DeploymentSlot Environment { get; set; } + + public MachineStudioWebService() + { + Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; + _client = new WebTransportClient(); + } + + public Task CheckForUpdates(CheckForUpdatesRequest request) + { + return _client.PostJson(GetAddress() + "CheckForUpdates", request); + } + + public Task UploadVersion(UploadVersionRequest request) + { + return _client.PostJson(GetAddress() + "UploadVersion", request); + } + + public Task NotifyUploadCompleted(UploadCompletedRequest request) + { + return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); + } + + public Task GetLatestVersion(LatestVersionRequest request) + { + return _client.PostJson(GetAddress() + "GetLatestVersion", request); + } + + public Task DownloadLatestVersion(DownloadLatestVersionRequest request) + { + return _client.PostJson(GetAddress() + "DownloadLatestVersion", request); + } + + public Task Login(LoginRequest request) + { + return _client.PostJson(GetAddress() + "Login", request); + } + + private String GetAddress() + { + return Environment.ToAddress() + "/api/MachineStudio/"; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index 1f9aee937..d81f0d561 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -57,7 +57,7 @@ namespace Tango.MachineStudio.UI.Authentication { var settings = SettingsManager.Default.GetOrCreate(); - IMachineStudioService service = new MachineStudioService(); + IMachineStudioWebService service = new MachineStudioWebService(); var response = service.Login(new LoginRequest() { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 64043e556..56ebb1e00 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -357,7 +357,7 @@ namespace Tango.MachineStudio.UI.ViewModels { if (_authenticationProvider.CurrentUser != null) { - var client = new MachineStudioService(); + var client = new MachineStudioWebService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 8d4553e32..57043df0e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -169,7 +169,7 @@ namespace Tango.MachineStudio.UI.ViewModels Status = UpdateStatus.CheckingForUpdate; - var client = new MachineStudioService(); + var client = new MachineStudioWebService(); DownloadLatestVersionResponse response = await client.DownloadLatestVersion(new DownloadLatestVersionRequest() { @@ -216,7 +216,7 @@ namespace Tango.MachineStudio.UI.ViewModels { Thread.Sleep(2000); - var client = new MachineStudioService(); + var client = new MachineStudioWebService(); CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index b5140e336..256804f67 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -40,7 +40,6 @@ namespace Tango.PPC.Common.MachineSetup private IRemoteAssistanceProvider _remoteAssistance; private IUnifiedWriteFilterManager _uwf; private IOperationSystemManager _windows_manager; - private String _accessToken; #region Events @@ -84,19 +83,17 @@ namespace Tango.PPC.Common.MachineSetup #region Private Methods - private Task Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { using (var client = new PPCWebService()) { - var response = client.Login(new LoginRequest() + return client.Login(new LoginRequest() { Mode = LoginMode.Machine, SerialNumber = serialNumber, - }).Result; - - _accessToken = response.AccessToken; + }).Result.AccessToken; } }); } @@ -128,10 +125,10 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - await Login(serialNumber); + var accessToken = await Login(serialNumber); MachineSetupRequest request = new MachineSetupRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; MachineSetupResponse setup_response = null; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index c19208724..8661168b0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -29,7 +29,6 @@ namespace Tango.PPC.Common.MachineUpdate { private IPPCApplicationManager _app_manager; private IMachineProvider _machineProvider; - private String _accessToken; #region Events @@ -72,19 +71,17 @@ namespace Tango.PPC.Common.MachineUpdate #region Private Methods - private Task Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { using (var client = new PPCWebService()) { - var response = client.Login(new LoginRequest() + return client.Login(new LoginRequest() { Mode = LoginMode.Machine, SerialNumber = serialNumber, - }).Result; - - _accessToken = response.AccessToken; + }).Result.AccessToken; } }); } @@ -131,10 +128,10 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - await Login(serialNumber); + String accessToken = await Login(serialNumber); DownloadUpdateRequest request = new DownloadUpdateRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; DownloadUpdateResponse update_response = null; @@ -301,12 +298,12 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - Login(serialNumber).Wait(); + String accessToken = Login(serialNumber).Result; LogManager.Log($"Checking if updates available..."); CheckForUpdateRequest request = new CheckForUpdateRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; request.Version = _app_manager.Version.ToString(); CheckForUpdateResponse update_response = null; @@ -417,10 +414,10 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - Login(serialNumber).Wait(); + String accessToken = Login(serialNumber).Result; UpdateDBRequest request = new UpdateDBRequest(); - request.AccessToken = _accessToken; + request.AccessToken = accessToken; UpdateDBResponse update_response = null; diff --git a/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs new file mode 100644 index 000000000..ca1653e3e --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/MachineService_TST.cs @@ -0,0 +1,64 @@ +using System; +using System.Threading; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Tango.Web.Authentication; + +namespace Tango.UnitTesting +{ + [TestClass] + [TestCategory("Machine Service")] + public class MachineService_TST + { + private class TokenObject : IEquatable + { + public String Value { get; set; } + + public bool Equals(TokenObject other) + { + return Value == other.Value; + } + } + + [TestMethod] + public void Test_Tokens_Manager() + { + TokensManager tokensManager = new TokensManager(); + + TokenObject t1 = new TokenObject(); + t1.Value = "Roy"; + + TokenObject t2 = new TokenObject(); + t2.Value = "Sagi"; + + String token1 = tokensManager.GetOrCreate(t1); + String token2 = tokensManager.GetOrCreate(t2); + + Assert.AreEqual(tokensManager.GetTokenObject(token1), t1); + Assert.AreEqual(tokensManager.GetTokenObject(token2), t2); + + TokenObject t3 = new TokenObject(); + t3.Value = "Roy"; + + String token3 = tokensManager.GetOrCreate(t3); + Assert.AreEqual(token3, token1); + Assert.AreEqual(tokensManager.GetTokenObject(token1), tokensManager.GetTokenObject(token3)); + + TokenObject tOld = new TokenObject() + { + Value = "Expired Token" + }; + + tokensManager.ExpirationTime = TimeSpan.FromSeconds(2); + + Thread.Sleep(2000); + + String recent_token = tokensManager.GetOrCreate(tOld); + + Thread.Sleep(1000); + + Assert.IsTrue(tokensManager.Exists(recent_token)); + + Assert.IsFalse(tokensManager.Exists(token1)); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index fa4652899..9ebc45dfc 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -107,6 +107,7 @@ + @@ -193,6 +194,10 @@ {74e700b0-1156-4126-be40-ee450d3c3026} Tango.Transport + + {5001990f-977b-48ff-b217-0236a5022ad8} + Tango.Web + {ebb7cb9f-6af2-456b-a5dd-1b136b605d90} Tango.DBObservablesGenerator.CLI @@ -212,7 +217,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs index 701a87a3c..8e0eb4288 100644 --- a/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs +++ b/Software/Visual_Studio/Tango.Web/Authentication/TokensManager.cs @@ -7,35 +7,85 @@ using System.Threading.Tasks; namespace Tango.Web.Authentication { - public class TokensManager + public class TokensManager where T : IEquatable { - private Dictionary _tokens; + private Dictionary _tokens; + + private class TokenWrapper : IEquatable + { + public DateTime Date { get; set; } + + public T Value { get; set; } + + public bool Equals(TokenWrapper other) + { + return Value.Equals(other.Value); + } + } public TokensManager() { - _tokens = new Dictionary(); + _tokens = new Dictionary(); + ExpirationTime = TimeSpan.FromHours(1); } - public String CreateNew(T userID) + public TimeSpan ExpirationTime { get; set; } + + public String GetOrCreate(T tokenObject) { - String token = Guid.NewGuid().ToString(); - _tokens.Add(token, userID); - return token; + var existing_token = _tokens.FirstOrDefault(x => x.Value.Value.Equals(tokenObject)); + + if (existing_token.Key != null) + { + return existing_token.Key; + } + else + { + String token = Guid.NewGuid().ToString(); + _tokens.Add(token, new TokenWrapper() + { + Value = tokenObject, + Date = DateTime.Now, + }); + return token; + } } public bool Exists(String token) { + RemoveOrRenewExpired(token); + return _tokens.ContainsKey(token); } public T GetTokenObject(String token) { + RemoveOrRenewExpired(token); + if (!_tokens.ContainsKey(token)) { throw new AuthenticationException("Invalid token."); } - return _tokens[token]; + return _tokens[token].Value; + } + + private void RemoveOrRenewExpired(String token) + { + DateTime now = DateTime.Now; + + if (_tokens.ContainsKey(token)) + { + _tokens[token].Date = now; + } + + foreach (var t in _tokens.ToList()) + { + if (now > t.Value.Date.Add(ExpirationTime)) + { + _tokens.Remove(t.Key); + } + } } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 142980fdd..98ea8d827 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -347,7 +347,7 @@ namespace Tango.MachineService.Controllers Password = request.Password, }, - AccessToken = TokensManager.CreateNew(user.Guid), + AccessToken = TokensManager.GetOrCreate(user.Guid), VersionChangeRequired = versionChangeRequired, RequiredVersion = requiredVersion, }; diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index af861923c..064a44fdb 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -31,11 +31,16 @@ namespace Tango.MachineService.Controllers private static List _pendingUploads; private ActiveDirectoryManager _ad_manager; - public class TokenObject + public class TokenObject : IEquatable { public LoginMode Mode { get; set; } public String UserGuid { get; set; } public String MachineGuid { get; set; } + + public bool Equals(TokenObject other) + { + return UserGuid == other.UserGuid || MachineGuid == MachineGuid; + } } public static TokensManager TokensManager { get; set; } @@ -434,7 +439,7 @@ namespace Tango.MachineService.Controllers throw new AuthenticationException("Domain user found but the database entry validation failed."); } - response.AccessToken = TokensManager.CreateNew(new TokenObject() + response.AccessToken = TokensManager.GetOrCreate(new TokenObject() { Mode = LoginMode.User, UserGuid = user.Guid, @@ -449,7 +454,7 @@ namespace Tango.MachineService.Controllers throw new AuthenticationException("Invalid serial number."); } - response.AccessToken = TokensManager.CreateNew(new TokenObject() + response.AccessToken = TokensManager.GetOrCreate(new TokenObject() { Mode = LoginMode.Machine, UserGuid = machine.Guid, -- cgit v1.3.1 From 9736b8c8ede6a0d121dea8381f0abb561fad5631 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 19 Feb 2019 01:50:58 +0200 Subject: Implemented auto generated web clients for PPC and machine studio. Improved interactions with web clients across solutions. --- .../Build/Shortcuts/Machine Emulator.lnk | Bin 1445 -> 1530 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1581 bytes .../Build/Shortcuts/Proto Compiler GUI.lnk | Bin 1444 -> 1529 bytes .../Build/Shortcuts/Stubs Execution GUI.lnk | Bin 1462 -> 1547 bytes .../Build/Shortcuts/Transport Router.lnk | Bin 1493 -> 1578 bytes .../Authentication/IAuthenticationProvider.cs | 5 - .../Publish/MachineStudioPublisher.cs | 15 +-- .../Tango.MachineStudio.Common.csproj | 6 +- .../Web/IMachineStudioWebService.cs | 28 ---- .../Web/LoginResponse.cs | 4 +- .../Web/MachineStudioWebClient.cs | 33 +++++ .../Web/MachineStudioWebClientBase.cs | 79 ++++++++++++ .../Web/MachineStudioWebService.cs | 60 --------- .../DefaultAuthenticationProvider.cs | 23 ++-- .../Tango.MachineStudio.UI/ViewModelLocator.cs | 3 + .../ViewModels/LoginViewVM.cs | 5 +- .../ViewModels/MainViewVM.cs | 10 +- .../ViewModels/UpdateViewVM.cs | 20 ++- .../MachineSetup/IMachineSetupManager.cs | 3 +- .../MachineSetup/MachineSetupManager.cs | 32 +++-- .../MachineUpdate/MachineUpdateManager.cs | 43 +++---- .../PPC/Tango.PPC.Common/Publish/PPCPublisher.cs | 15 +-- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 6 +- .../PPC/Tango.PPC.Common/Web/IPPCWebService.cs | 85 ------------- .../PPC/Tango.PPC.Common/Web/LoginResponse.cs | 5 +- .../PPC/Tango.PPC.Common/Web/PPCWebClient.cs | 30 +++++ .../PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs | 106 ++++++++++++++++ .../PPC/Tango.PPC.Common/Web/PPCWebService.cs | 79 ------------ .../PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs | 6 +- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 3 + .../Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs | 10 +- .../Tango.CodeGeneration.csproj | 4 +- .../Tango.CodeGeneration/TangoWebClientCodeFile.cs | 30 +++++ .../Templates/TangoWebClientCodeFile.cshtml | 51 ++++++++ .../Visual_Studio/Tango.Core/Helpers/PathHelper.cs | 16 +++ .../Tango.Transport/Tango.Transport.csproj | 3 +- .../Tango.Transport/Web/SessionExpiredException.cs | 16 +++ .../Tango.Transport/Web/WebTransportClient.cs | 9 +- .../Tango.UnitTesting/MachineService_TST.cs | 13 +- .../Tango.Web/Authentication/TokensManager.cs | 49 +++---- .../Tango.Web/Authentication/WebToken.cs | 14 ++ .../Tango.Web/Authentication/WebTokenResponse.cs | 14 ++ Software/Visual_Studio/Tango.Web/Tango.Web.csproj | 7 + Software/Visual_Studio/Tango.Web/TangoWebClient.cs | 141 +++++++++++++++++++++ Software/Visual_Studio/Tango.sln | 55 +++++++- .../Utilities/Tango.WebClientGenerator/App.config | 78 ++++++++++++ .../Utilities/Tango.WebClientGenerator/Program.cs | 49 +++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../Tango.WebClientGenerator.csproj | 86 +++++++++++++ .../Tango.WebClientGenerator/packages.config | 4 + .../Controllers/MachineStudioController.cs | 2 +- .../Controllers/PPCController.cs | 4 +- .../Filters/MachineStudioLoginFilter.cs | 8 +- .../Tango.MachineService/Filters/PPCLoginFilter.cs | 8 +- 54 files changed, 994 insertions(+), 417 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs delete mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs delete mode 100644 Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/TangoWebClientCodeFile.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/TangoWebClientCodeFile.cshtml create mode 100644 Software/Visual_Studio/Tango.Transport/Web/SessionExpiredException.cs create mode 100644 Software/Visual_Studio/Tango.Web/Authentication/WebToken.cs create mode 100644 Software/Visual_Studio/Tango.Web/Authentication/WebTokenResponse.cs create mode 100644 Software/Visual_Studio/Tango.Web/TangoWebClient.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/App.config create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Program.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/Tango.WebClientGenerator.csproj create mode 100644 Software/Visual_Studio/Utilities/Tango.WebClientGenerator/packages.config (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels') diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 43aace6b5..d95642721 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 4d317d343..1550b6e18 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk index 1be399f50..72ad667d8 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk index db7f7c338..5258be2c6 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Stubs Execution GUI.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk b/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk index 6f0433af2..73b23b4ce 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk and b/Software/Visual_Studio/Build/Shortcuts/Transport Router.lnk differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs index 7cc2b5b51..4958cb0f4 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Authentication/IAuthenticationProvider.cs @@ -12,11 +12,6 @@ namespace Tango.MachineStudio.Common.Authentication /// public interface IAuthenticationProvider { - /// - /// Gets the access token that was retrieved at the last login. - /// - String AccessToken { get; } - /// /// Occurs when the current logged-in user has changed. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs index b9a50ec73..dfbe0adc6 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Publish/MachineStudioPublisher.cs @@ -18,7 +18,7 @@ namespace Tango.MachineStudio.Common.Publish { public class MachineStudioPublisher : ExtendedObject { - private IMachineStudioWebService _client; + private MachineStudioWebClient _client; /// /// Occurs on publish progress. @@ -40,7 +40,7 @@ namespace Tango.MachineStudio.Common.Publish /// public MachineStudioPublisher() { - _client = new MachineStudioWebService(); + _client = new MachineStudioWebClient(); Options = new PublishOptions(); } @@ -98,16 +98,16 @@ namespace Tango.MachineStudio.Common.Publish /// Login to machine service and returns an access token. /// /// - private Task Login() + private Task Login() { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { return _client.Login(new LoginRequest() { Email = Options.Email, Password = Options.Password, Version = GetLocalVersion(), - }).Result.AccessToken; + }).Result; }); } @@ -121,7 +121,6 @@ namespace Tango.MachineStudio.Common.Publish String appPath = GetMachineStudioExecutablePath(); String folder = Options.GetApplicationPath(); - String accessToken = String.Empty; if (!File.Exists(appPath)) { @@ -135,7 +134,7 @@ namespace Tango.MachineStudio.Common.Publish try { OnPublishProgress(0, 100, $"Logging in to machine service at {Options.Environment.ToAddress()}..."); - accessToken = Login().Result; + Login().Wait(); OnPublishProgress(0, 100, $"Fetching remote version from {Options.Environment.ToAddress()}..."); @@ -154,7 +153,6 @@ namespace Tango.MachineStudio.Common.Publish var response = _client.UploadVersion(new UploadVersionRequest() { - AccessToken = accessToken, Version = local_version, Comments = Options.Comments, }).Result; @@ -200,7 +198,6 @@ namespace Tango.MachineStudio.Common.Publish _client.NotifyUploadCompleted(new UploadCompletedRequest() { - AccessToken = accessToken, Token = response.Token, }).Wait(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index d5e62f4e1..48c78e865 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -134,10 +134,10 @@ - - + + @@ -326,7 +326,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs deleted file mode 100644 index 5a89f688f..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/IMachineStudioWebService.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.ServiceModel; -using System.Text; -using System.Threading.Tasks; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public interface IMachineStudioWebService - { - DeploymentSlot Environment { get; set; } - - Task CheckForUpdates(CheckForUpdatesRequest request); - - Task DownloadLatestVersion(DownloadLatestVersionRequest request); - - Task UploadVersion(UploadVersionRequest request); - - Task NotifyUploadCompleted(UploadCompletedRequest request); - - Task GetLatestVersion(LatestVersionRequest request); - - Task Login(LoginRequest request); - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs index 643e3930d..78c7bc560 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/LoginResponse.cs @@ -5,13 +5,13 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Transport.Web; +using Tango.Web.Authentication; namespace Tango.MachineStudio.Common.Web { - public class LoginResponse : WebResponseMessage + public class LoginResponse : WebTokenResponse { public DataSource DataSource { get; set; } - public String AccessToken { get; set; } public bool VersionChangeRequired { get; set; } public String RequiredVersion { get; set; } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs new file mode 100644 index 000000000..02276d641 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClient.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.MachineStudio.Common.Web +{ + public class MachineStudioWebClient : MachineStudioWebClientBase + { + public MachineStudioWebClient(DeploymentSlot environment) : base(environment) + { + } + + public MachineStudioWebClient(DeploymentSlot environment, WebToken token) : base(environment, token) + { + + } + + public MachineStudioWebClient(WebToken token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) + { + + } + + public MachineStudioWebClient() : this(null) + { + + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs new file mode 100644 index 000000000..dc5a14856 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebClientBase.cs @@ -0,0 +1,79 @@ + +using System.Threading.Tasks; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.MachineStudio.Common.Web +{ + /// + /// Represents a machine service MachineStudio web client. + /// + /// + public abstract class MachineStudioWebClientBase : TangoWebClient + { + /// + /// Initializes a new instance of the class. + /// + /// The environment. + /// Existing token. + public MachineStudioWebClientBase(DeploymentSlot environment, WebToken token) : base(environment, "MachineStudio", token) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The environment. + public MachineStudioWebClientBase(DeploymentSlot environment) : this(environment, null) + { + + } + + /// + /// Executes the CheckForUpdates action and returns Tango.MachineStudio.Common.Web.CheckForUpdatesResponse. + /// + /// + public Task CheckForUpdates(Tango.MachineStudio.Common.Web.CheckForUpdatesRequest request) + { + return Post("CheckForUpdates", request); + } + + /// + /// Executes the DownloadLatestVersion action and returns Tango.MachineStudio.Common.Web.DownloadLatestVersionResponse. + /// + /// + public Task DownloadLatestVersion(Tango.MachineStudio.Common.Web.DownloadLatestVersionRequest request) + { + return Post("DownloadLatestVersion", request); + } + + /// + /// Executes the UploadVersion action and returns Tango.MachineStudio.Common.Web.UploadVersionResponse. + /// + /// + public Task UploadVersion(Tango.MachineStudio.Common.Web.UploadVersionRequest request) + { + return Post("UploadVersion", request); + } + + /// + /// Executes the NotifyUploadCompleted action and returns Tango.MachineStudio.Common.Web.UploadCompletedResponse. + /// + /// + public Task NotifyUploadCompleted(Tango.MachineStudio.Common.Web.UploadCompletedRequest request) + { + return Post("NotifyUploadCompleted", request); + } + + /// + /// Executes the GetLatestVersion action and returns Tango.MachineStudio.Common.Web.LatestVersionResponse. + /// + /// + public Task GetLatestVersion(Tango.MachineStudio.Common.Web.LatestVersionRequest request) + { + return Post("GetLatestVersion", request); + } + + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs deleted file mode 100644 index d0aa8a5bf..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Web/MachineStudioWebService.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.MachineStudio.Common.Authentication; -using Tango.Settings; -using Tango.Transport.Web; -using Tango.Web; - -namespace Tango.MachineStudio.Common.Web -{ - public class MachineStudioWebService : IMachineStudioWebService - { - private WebTransportClient _client; - - public DeploymentSlot Environment { get; set; } - - public MachineStudioWebService() - { - Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; - _client = new WebTransportClient(); - } - - public Task CheckForUpdates(CheckForUpdatesRequest request) - { - return _client.PostJson(GetAddress() + "CheckForUpdates", request); - } - - public Task UploadVersion(UploadVersionRequest request) - { - return _client.PostJson(GetAddress() + "UploadVersion", request); - } - - public Task NotifyUploadCompleted(UploadCompletedRequest request) - { - return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); - } - - public Task GetLatestVersion(LatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "GetLatestVersion", request); - } - - public Task DownloadLatestVersion(DownloadLatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "DownloadLatestVersion", request); - } - - public Task Login(LoginRequest request) - { - return _client.PostJson(GetAddress() + "Login", request); - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/MachineStudio/"; - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index d81f0d561..e07952f29 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -26,6 +26,8 @@ namespace Tango.MachineStudio.UI.Authentication /// public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider { + private MachineStudioWebClient _client; + private User _currentUser; /// /// Gets the current logged-in user. @@ -46,6 +48,15 @@ namespace Tango.MachineStudio.UI.Authentication /// public event EventHandler CurrentUserChanged; + /// + /// Initializes a new instance of the class. + /// + /// The machine studio web client. + public DefaultAuthenticationProvider(MachineStudioWebClient machineStudioWebClient) + { + _client = machineStudioWebClient; + } + /// /// Performs a user login by the specified email and password. /// @@ -57,9 +68,8 @@ namespace Tango.MachineStudio.UI.Authentication { var settings = SettingsManager.Default.GetOrCreate(); - IMachineStudioWebService service = new MachineStudioWebService(); - - var response = service.Login(new LoginRequest() + _client.Environment = settings.DeploymentSlot; + var response = _client.Login(new LoginRequest() { Email = email, @@ -68,8 +78,6 @@ namespace Tango.MachineStudio.UI.Authentication }).Result; - AccessToken = response.AccessToken; - if (settings.Environment == MachineStudioSettings.WorkingEnvironment.Remote) { ObservablesContext.OverrideSettingsDataSource(response.DataSource); @@ -114,10 +122,5 @@ namespace Tango.MachineStudio.UI.Authentication { CurrentUser = null; } - - /// - /// Gets the access token that was retrieved at the last login. - /// - public string AccessToken { get; private set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs index b0a3a8c11..7fbb0008c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModelLocator.cs @@ -14,6 +14,7 @@ using Tango.MachineStudio.Common.Speech; using Tango.MachineStudio.Common.StudioApplication; using Tango.MachineStudio.Common.Threading; using Tango.MachineStudio.Common.Video; +using Tango.MachineStudio.Common.Web; using Tango.MachineStudio.UI.Authentication; using Tango.MachineStudio.UI.Console; using Tango.MachineStudio.UI.FirmwareUpgrade; @@ -68,8 +69,10 @@ namespace Tango.MachineStudio.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); + TangoIOC.Default.Register(new MachineStudioWebClient()); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs index 8b3747584..1165c0920 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -16,6 +16,7 @@ using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.Common.Web; using Tango.MachineStudio.UI.Messages; using Tango.Settings; using Tango.SharedUI; @@ -35,6 +36,7 @@ namespace Tango.MachineStudio.UI.ViewModels private IEventLogger _eventLogger; private Rfc2898Cryptographer cryptographer; private MachineStudioSettings _settings; + private MachineStudioWebClient _machineStudioWebClient; private String _email; /// @@ -111,10 +113,11 @@ namespace Tango.MachineStudio.UI.ViewModels /// The authentication provider. /// The navigation manager. /// The notification provider. - public LoginViewVM(IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger) + public LoginViewVM(MachineStudioWebClient machineStudioWebClient, IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger) { EnableSlotSelection = true; + _machineStudioWebClient = machineStudioWebClient; _settings = SettingsManager.Default.GetOrCreate(); _notificationProvider = notificationProvider; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 56ebb1e00..986bf483f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -55,6 +55,7 @@ namespace Tango.MachineStudio.UI.ViewModels private Thread _updateCheckThread; private IEventLogger _eventLogger; private MachineStudioSettings _settings; + private MachineStudioWebClient _machineStudioWebClient; /// /// Gets or sets the current loaded module. @@ -281,8 +282,10 @@ namespace Tango.MachineStudio.UI.ViewModels IEventLogger eventLogger, IDiagnosticsFrameProvider frameProvider, ISpeechProvider speechProvider, - TeamFoundationServiceExtendedClient tfs) : base() + TeamFoundationServiceExtendedClient tfs, + MachineStudioWebClient machineStudioWebClient) : base() { + _machineStudioWebClient = machineStudioWebClient; TFSClient = tfs; _eventLogger = eventLogger; _navigation = navigationManager; @@ -357,11 +360,8 @@ namespace Tango.MachineStudio.UI.ViewModels { if (_authenticationProvider.CurrentUser != null) { - var client = new MachineStudioWebService(); - - CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() + CheckForUpdatesResponse response = _machineStudioWebClient.CheckForUpdates(new CheckForUpdatesRequest() { - AccessToken = _authenticationProvider.AccessToken, Version = _applicationManager.Version.ToString(), }).Result; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs index 57043df0e..17edf1dfd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -25,7 +25,6 @@ using Tango.MachineStudio.UI.Messages; using Tango.Settings; using Tango.MachineStudio.Common; using Tango.Transport.Web; -using Tango.MachineStudio.Common.Web; namespace Tango.MachineStudio.UI.ViewModels { @@ -56,6 +55,7 @@ namespace Tango.MachineStudio.UI.ViewModels private CheckForUpdatesResponse _updateInfo; private TemporaryFolder _newPackageTempFolder; private TemporaryFolder _previousPackageTempFolder; + private MachineStudioWebClient _machineStudioWebClient; private bool _forcedUpdate; public bool ForcedUpdate @@ -140,8 +140,9 @@ namespace Tango.MachineStudio.UI.ViewModels public RelayCommand TryRollbackAgainCommand { get; set; } - public UpdateViewVM(INotificationProvider notification, IAuthenticationProvider authentication, INavigationManager navigation, IStudioApplicationManager application) + public UpdateViewVM(MachineStudioWebClient machineStudioWebClient, INotificationProvider notification, IAuthenticationProvider authentication, INavigationManager navigation, IStudioApplicationManager application) { + _machineStudioWebClient = machineStudioWebClient; _notification = notification; _navigation = navigation; _application = application; @@ -169,11 +170,9 @@ namespace Tango.MachineStudio.UI.ViewModels Status = UpdateStatus.CheckingForUpdate; - var client = new MachineStudioWebService(); - - DownloadLatestVersionResponse response = await client.DownloadLatestVersion(new DownloadLatestVersionRequest() + DownloadLatestVersionResponse response = await _machineStudioWebClient.DownloadLatestVersion(new DownloadLatestVersionRequest() { - AccessToken = _authentication.AccessToken, + }); _updateInfo = new CheckForUpdatesResponse(); @@ -210,17 +209,14 @@ namespace Tango.MachineStudio.UI.ViewModels var settings = SettingsManager.Default.GetOrCreate(); - Task.Factory.StartNew(() => + Task.Factory.StartNew((Action)(() => { try { Thread.Sleep(2000); - var client = new MachineStudioWebService(); - - CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest() + CheckForUpdatesResponse response = _machineStudioWebClient.CheckForUpdates(new CheckForUpdatesRequest() { - AccessToken = _authentication.AccessToken, Version = _application.Version.ToString(), }).Result; @@ -241,7 +237,7 @@ namespace Tango.MachineStudio.UI.ViewModels logManager.Log(ex, "Error while checking for version update!"); Status = UpdateStatus.Error; } - }); + })); } private void BackToApplication() diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs index 896c7b921..4808252d0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/IMachineSetupManager.cs @@ -27,8 +27,7 @@ namespace Tango.PPC.Common.MachineSetup /// Performs a machine setup using the specified serial number and machine service address. /// /// The serial number. - /// The machine service address. /// - Task Setup(String serialNumber, String machineServiceAddress); + Task Setup(String serialNumber); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index 256804f67..369248c7b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -40,6 +40,7 @@ namespace Tango.PPC.Common.MachineSetup private IRemoteAssistanceProvider _remoteAssistance; private IUnifiedWriteFilterManager _uwf; private IOperationSystemManager _windows_manager; + private PPCWebClient _client; #region Events @@ -72,8 +73,9 @@ namespace Tango.PPC.Common.MachineSetup /// Initializes a new instance of the class. /// /// The remote assistance. - public MachineSetupManager(IRemoteAssistanceProvider remoteAssistance, IUnifiedWriteFilterManager unifiedWriterFilterManager, IOperationSystemManager operationSystemManager) + public MachineSetupManager(PPCWebClient ppcWebClient, IRemoteAssistanceProvider remoteAssistance, IUnifiedWriteFilterManager unifiedWriterFilterManager, IOperationSystemManager operationSystemManager) { + _client = ppcWebClient; _remoteAssistance = remoteAssistance; _uwf = unifiedWriterFilterManager; _windows_manager = operationSystemManager; @@ -83,18 +85,16 @@ namespace Tango.PPC.Common.MachineSetup #region Private Methods - private Task Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { - using (var client = new PPCWebService()) + return _client.Login(new LoginRequest() { - return client.Login(new LoginRequest() - { - Mode = LoginMode.Machine, - SerialNumber = serialNumber, - }).Result.AccessToken; - } + Mode = LoginMode.Machine, + SerialNumber = serialNumber, + }).Result; + }); } @@ -108,7 +108,7 @@ namespace Tango.PPC.Common.MachineSetup /// The serial number. /// The machine service address. /// - public async Task Setup(string serialNumber, string machineServiceAddress) + public async Task Setup(string serialNumber) { TaskCompletionSource result = new TaskCompletionSource(); @@ -116,6 +116,8 @@ namespace Tango.PPC.Common.MachineSetup { LogManager.Log($"Starting machine setup for serial number {serialNumber}..."); + var machineServiceAddress = SettingsManager.Default.GetOrCreate().GetMachineServiceAddress(); + IMachineOperator op = null; var settings = SettingsManager.Default.GetOrCreate(); @@ -125,19 +127,15 @@ namespace Tango.PPC.Common.MachineSetup LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - var accessToken = await Login(serialNumber); + Login(serialNumber).Wait(); MachineSetupRequest request = new MachineSetupRequest(); - request.AccessToken = accessToken; MachineSetupResponse setup_response = null; try { - using (var client = new PPCWebService()) - { - setup_response = await client.MachineSetup(request); - } + setup_response = await _client.MachineSetup(request); } catch (Exception ex) { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 8661168b0..8b9aede87 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -29,6 +29,7 @@ namespace Tango.PPC.Common.MachineUpdate { private IPPCApplicationManager _app_manager; private IMachineProvider _machineProvider; + private PPCWebClient _client; #region Events @@ -61,8 +62,9 @@ namespace Tango.PPC.Common.MachineUpdate /// Initializes a new instance of the class. /// /// The application manager. - public MachineUpdateManager(IPPCApplicationManager applicationManager, IMachineProvider machineProvider) + public MachineUpdateManager(PPCWebClient ppcWebClient, IPPCApplicationManager applicationManager, IMachineProvider machineProvider) { + _client = ppcWebClient; _machineProvider = machineProvider; _app_manager = applicationManager; } @@ -71,18 +73,15 @@ namespace Tango.PPC.Common.MachineUpdate #region Private Methods - private Task Login(String serialNumber) + private Task Login(String serialNumber) { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { - using (var client = new PPCWebService()) + return _client.Login(new LoginRequest() { - return client.Login(new LoginRequest() - { - Mode = LoginMode.Machine, - SerialNumber = serialNumber, - }).Result.AccessToken; - } + Mode = LoginMode.Machine, + SerialNumber = serialNumber, + }).Result; }); } @@ -128,17 +127,13 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - String accessToken = await Login(serialNumber); + await Login(serialNumber); DownloadUpdateRequest request = new DownloadUpdateRequest(); - request.AccessToken = accessToken; DownloadUpdateResponse update_response = null; - using (var client = new PPCWebService()) - { - update_response = await client.MachineUpdate(request); - } + update_response = await _client.MachineUpdate(request); LogManager.Log($"Machine update response received: {Environment.NewLine}{update_response.ToJsonString()}"); @@ -298,20 +293,16 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - String accessToken = Login(serialNumber).Result; + Login(serialNumber).Wait(); LogManager.Log($"Checking if updates available..."); CheckForUpdateRequest request = new CheckForUpdateRequest(); - request.AccessToken = accessToken; request.Version = _app_manager.Version.ToString(); CheckForUpdateResponse update_response = null; - using (var client = new PPCWebService()) - { - update_response = client.CheckForUpdate(request).Result; - } + update_response = _client.CheckForUpdate(request).Result; LogManager.Log($"Check for update response received: {Environment.NewLine}{update_response.ToJsonString()}"); @@ -414,17 +405,13 @@ namespace Tango.PPC.Common.MachineUpdate LogManager.Log($"Connecting to machine service on {machineServiceAddress}..."); - String accessToken = Login(serialNumber).Result; + Login(serialNumber).Wait(); UpdateDBRequest request = new UpdateDBRequest(); - request.AccessToken = accessToken; UpdateDBResponse update_response = null; - using (var client = new PPCWebService()) - { - update_response = client.UpdateDB(request).Result; - } + update_response = _client.UpdateDB(request).Result; LogManager.Log($"Update DB response received: {Environment.NewLine}{update_response.ToJsonString()}"); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs index 1c69f0934..dfb544177 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Publish/PPCPublisher.cs @@ -17,7 +17,7 @@ namespace Tango.PPC.Common.Publish { public class PPCPublisher : ExtendedObject { - private IPPCWebService _client; + private PPCWebClient _client; /// /// Occurs on publish progress. @@ -39,7 +39,7 @@ namespace Tango.PPC.Common.Publish /// public PPCPublisher() { - _client = new PPCWebService(); + _client = new PPCWebClient(); Options = new PublishOptions(); } @@ -100,16 +100,16 @@ namespace Tango.PPC.Common.Publish /// Login to machine service and returns an access token. /// /// - private Task Login() + private Task Login() { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { return _client.Login(new LoginRequest() { Mode = LoginMode.User, Email = Options.Email, Password = Options.Password, - }).Result.AccessToken; + }).Result; }); } @@ -123,7 +123,6 @@ namespace Tango.PPC.Common.Publish String appPath = GetPPCExecutablePath(); String folder = Options.GetApplicationPath(); - String accessToken = String.Empty; if (!File.Exists(appPath)) { @@ -137,7 +136,7 @@ namespace Tango.PPC.Common.Publish try { OnPublishProgress(0, 100, $"Logging in to machine service at {Options.Environment.ToAddress()}..."); - accessToken = Login().Result; + Login().Wait(); OnPublishProgress(0, 100, $"Fetching remote version from {Options.Environment.ToAddress()}..."); @@ -159,7 +158,6 @@ namespace Tango.PPC.Common.Publish Comments = Options.Comments, Version = local_version, MachineVersionGuid = Options.MachineVersionGuid, - AccessToken = accessToken, }).Result; CreateTupPackage(tempFile).Wait(); @@ -183,7 +181,6 @@ namespace Tango.PPC.Common.Publish _client.NotifyUploadCompleted(new UploadCompletedRequest() { - AccessToken = accessToken, Token = response.Token, }); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 3b18a6217..e47437f4d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -161,6 +161,8 @@ + + @@ -194,14 +196,12 @@ - - @@ -366,7 +366,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs deleted file mode 100644 index 6347836a9..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/IPPCWebService.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.ServiceModel; -using System.Text; -using System.Threading.Tasks; -using Tango.PPC.Common.Web; -using Tango.Web; - -namespace Tango.PPC.Common.Web -{ - /// - /// Represents an PPC update service for uploading PPC software packages. - /// - public interface IPPCWebService : IDisposable - { - /// - /// Gets or sets the environment. - /// - DeploymentSlot Environment { get; set; } - - /// - /// Uploads the version. - /// - /// The request. - /// - Task UploadVersion(UploadVersionRequest request); - - /// - /// Notifies the upload completed. - /// - /// The request. - Task NotifyUploadCompleted(UploadCompletedRequest request); - - /// - /// Gets the latest version. - /// - /// The machine version unique identifier. - /// - Task GetLatestVersion(LatestVersionRequest request); - - /// - /// Gets the machine versions. - /// - /// The request. - /// - Task GetMachineVersions(); - - /// - /// Checks for available update. - /// - /// The request. - /// - Task CheckForUpdate(CheckForUpdateRequest request); - - /// - /// Gets the version download info for the specified version. - /// - /// The request. - /// - Task MachineUpdate(DownloadUpdateRequest request); - - /// - /// Gets the machine setup information. - /// - /// The request. - /// - Task MachineSetup(MachineSetupRequest request); - - /// - /// Gets the machine database update information. - /// - /// The request. - /// - Task UpdateDB(UpdateDBRequest request); - - /// - /// Logins to the PPC service. - /// - /// The request. - /// - Task Login(LoginRequest request); - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs index bf2a1e88e..5d97c6470 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/LoginResponse.cs @@ -4,11 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Transport.Web; +using Tango.Web.Authentication; namespace Tango.PPC.Common.Web { - public class LoginResponse : WebResponseMessage + public class LoginResponse : WebTokenResponse { - public String AccessToken { get; set; } + } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs new file mode 100644 index 000000000..5900dd697 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClient.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.PPC.Common.Web +{ + public class PPCWebClient : PPCWebClientBase + { + public PPCWebClient(DeploymentSlot environment) : base(environment) + { + } + + public PPCWebClient(DeploymentSlot environment, WebToken token) : base(environment, token) + { + } + + public PPCWebClient(WebToken token) : this(SettingsManager.Default.GetOrCreate().DeploymentSlot, token) + { + } + + public PPCWebClient() : this(null) + { + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs new file mode 100644 index 000000000..e5c1beb4a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebClientBase.cs @@ -0,0 +1,106 @@ + +using System.Threading.Tasks; +using Tango.Web; +using Tango.Web.Authentication; + +namespace Tango.PPC.Common.Web +{ + /// + /// Represents a machine service PPC web client. + /// + /// + public abstract class PPCWebClientBase : TangoWebClient + { + /// + /// Initializes a new instance of the class. + /// + /// The environment. + /// Existing token. + public PPCWebClientBase(DeploymentSlot environment, WebToken token) : base(environment, "PPC", token) + { + + } + + /// + /// Initializes a new instance of the class. + /// + /// The environment. + public PPCWebClientBase(DeploymentSlot environment) : this(environment, null) + { + + } + + /// + /// Executes the MachineSetup action and returns Tango.PPC.Common.Web.MachineSetupResponse. + /// + /// + public Task MachineSetup(Tango.PPC.Common.Web.MachineSetupRequest request) + { + return Post("MachineSetup", request); + } + + /// + /// Executes the MachineUpdate action and returns Tango.PPC.Common.Web.DownloadUpdateResponse. + /// + /// + public Task MachineUpdate(Tango.PPC.Common.Web.DownloadUpdateRequest request) + { + return Post("MachineUpdate", request); + } + + /// + /// Executes the CheckForUpdate action and returns Tango.PPC.Common.Web.CheckForUpdateResponse. + /// + /// + public Task CheckForUpdate(Tango.PPC.Common.Web.CheckForUpdateRequest request) + { + return Post("CheckForUpdate", request); + } + + /// + /// Executes the UpdateDB action and returns Tango.PPC.Common.Web.UpdateDBResponse. + /// + /// + public Task UpdateDB(Tango.PPC.Common.Web.UpdateDBRequest request) + { + return Post("UpdateDB", request); + } + + /// + /// Executes the GetLatestVersion action and returns Tango.PPC.Common.Web.LatestVersionResponse. + /// + /// + public Task GetLatestVersion(Tango.PPC.Common.Web.LatestVersionRequest request) + { + return Post("GetLatestVersion", request); + } + + /// + /// Executes the UploadVersion action and returns Tango.PPC.Common.Web.UploadVersionResponse. + /// + /// + public Task UploadVersion(Tango.PPC.Common.Web.UploadVersionRequest request) + { + return Post("UploadVersion", request); + } + + /// + /// Executes the NotifyUploadCompleted action and returns Tango.PPC.Common.Web.UploadCompletedResponse. + /// + /// + public Task NotifyUploadCompleted(Tango.PPC.Common.Web.UploadCompletedRequest request) + { + return Post("NotifyUploadCompleted", request); + } + + /// + /// Executes the GetMachineVersions action and returns Tango.PPC.Common.Web.MachineVersionsResponse. + /// + /// + public Task GetMachineVersions(Tango.PPC.Common.Web.MachineVersionsRequest request) + { + return Post("GetMachineVersions", request); + } + + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs deleted file mode 100644 index 02821e8d4..000000000 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Web/PPCWebService.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Settings; -using Tango.Transport.Web; -using Tango.Web; - -namespace Tango.PPC.Common.Web -{ - public class PPCWebService : IPPCWebService - { - private WebTransportClient _client; - - public DeploymentSlot Environment { get; set; } - - public PPCWebService() - { - _client = new WebTransportClient(); - Environment = SettingsManager.Default.GetOrCreate().DeploymentSlot; - } - - private String GetAddress() - { - return Environment.ToAddress() + "/api/PPC/"; - } - - public Task UploadVersion(UploadVersionRequest request) - { - return _client.PostJson(GetAddress() + "UploadVersion", request); - } - - public Task NotifyUploadCompleted(UploadCompletedRequest request) - { - return _client.PostJson(GetAddress() + "NotifyUploadCompleted", request); - } - - public Task GetLatestVersion(LatestVersionRequest request) - { - return _client.PostJson(GetAddress() + "GetLatestVersion", request); - } - - public Task GetMachineVersions() - { - return _client.PostJson(GetAddress() + "GetMachineVersions", new MachineVersionsRequest()); - } - - public Task CheckForUpdate(CheckForUpdateRequest request) - { - return _client.PostJson(GetAddress() + "CheckForUpdate", request); - } - - public Task MachineUpdate(DownloadUpdateRequest request) - { - return _client.PostJson(GetAddress() + "MachineUpdate", request); - } - - public Task MachineSetup(MachineSetupRequest request) - { - return _client.PostJson(GetAddress() + "MachineSetup", request); - } - - public Task UpdateDB(UpdateDBRequest request) - { - return _client.PostJson(GetAddress() + "UpdateDB", request); - } - - public Task Login(LoginRequest request) - { - return _client.PostJson(GetAddress() + "Login", request); - } - - public void Dispose() - { - _client.Dispose(); - } - } -} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs index 6c7e1d005..1d77b152f 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Publisher.UI/MainWindowVM.cs @@ -35,7 +35,7 @@ namespace Tango.PPC.Publisher.UI { public class MainWindowVM : ViewModel { - private IPPCWebService _client; + private PPCWebClient _client; private PPCPublisher _publisher; private PublishOptions _options; @@ -102,7 +102,7 @@ namespace Tango.PPC.Publisher.UI public MainWindowVM() { - _client = new PPCWebService(); + _client = new PPCWebClient(); var settings = SettingsManager.Default.GetOrCreate(); Options = settings.Options; @@ -152,7 +152,7 @@ namespace Tango.PPC.Publisher.UI private async Task UpdateAvailableMachineVersions() { IsFree = false; - _machineVersions = (await _client.GetMachineVersions()).MachineVersions; + _machineVersions = (await _client.GetMachineVersions(new MachineVersionsRequest())).MachineVersions; _selectedMachineVersion = MachineVersions.OrderBy(x => x.Version).LastOrDefault(); RaisePropertyChanged(nameof(MachineVersions)); RaisePropertyChanged(nameof(SelectedMachineVersion)); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index 4eb5475f0..018c9b223 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -22,6 +22,7 @@ using Tango.PPC.Common.RemoteAssistance; using Tango.PPC.Common.Storage; using Tango.PPC.Common.Threading; using Tango.PPC.Common.UWF; +using Tango.PPC.Common.Web; using Tango.PPC.UI.Authentication; using Tango.PPC.UI.Connectivity; using Tango.PPC.UI.Modules; @@ -69,7 +70,9 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); + TangoIOC.Default.Register(new PPCWebClient()); TangoIOC.Default.Register(new DefaultDispatcherProvider(Application.Current.Dispatcher)); TangoIOC.Default.Register(); TangoIOC.Default.Register(); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs index 514a517ff..1bd1e1eea 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineSetupViewVM.cs @@ -18,6 +18,7 @@ using Tango.PPC.Common.Connection; using Tango.PPC.Common.MachineSetup; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.OS; +using Tango.PPC.Common.Web; using Tango.PPC.UI.ViewsContracts; using Tango.Settings; using Tango.SharedUI.Helpers; @@ -60,6 +61,7 @@ namespace Tango.PPC.UI.ViewModels private MachineSetupResult _setup_result; private IOperationSystemManager _operationSystemManager; private IPPCApplicationManager _appManager; + private PPCWebClient _ppcWebClient; #region Properties @@ -192,8 +194,9 @@ namespace Tango.PPC.UI.ViewModels /// /// The application manager. /// The machine setup manager. - public MachineSetupViewVM(IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager, IOperationSystemManager operationSystemManager) + public MachineSetupViewVM(PPCWebClient ppcWebClient, IPPCApplicationManager applicationManager, IMachineSetupManager machineSetupManager, IOperationSystemManager operationSystemManager) { + _ppcWebClient = ppcWebClient; _appManager = applicationManager; MachineSetupManager = machineSetupManager; @@ -210,7 +213,7 @@ namespace Tango.PPC.UI.ViewModels InstallCommand = new RelayCommand(Install); RestartCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.WelcomeView); }); TimeZoneSelectedCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.EnvironmentView); }); - EnvironmentSelectedCommand = new RelayCommand(() => + EnvironmentSelectedCommand = new RelayCommand(() => { NavigateTo(MachineSetupView.SetupWelcomeView); Settings.DeploymentSlot = DeploymentSlot; @@ -348,8 +351,9 @@ namespace Tango.PPC.UI.ViewModels try { + _ppcWebClient.Environment = DeploymentSlot; await _operationSystemManager.ChangeTimeZone(SelectedTimeZone); - _setup_result = await MachineSetupManager.Setup(SerialNumber, HostAddress); + _setup_result = await MachineSetupManager.Setup(SerialNumber); State = MachineSetupStates.Completed; LogManager.Log("Machine setup completed."); await NavigateTo(MachineSetupView.SetupCompletedView); diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj index 436bfae33..98c063a86 100644 --- a/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj +++ b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj @@ -87,6 +87,7 @@ + @@ -118,11 +119,12 @@ + - + - + diff --git a/Software/Visual_Studio/Tango.BL/Builders/EntityBuilderBase.cs b/Software/Visual_Studio/Tango.BL/Builders/EntityBuilderBase.cs index 37ec2ae5c..8e0869310 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/EntityBuilderBase.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/EntityBuilderBase.cs @@ -12,6 +12,7 @@ namespace Tango.BL.Builders { private List> _steps; private bool _entity_set; + private List, IQueryable>>> _querySteps; protected T Entity { get; set; } protected ObservablesContext Context { get; set; } @@ -19,6 +20,7 @@ namespace Tango.BL.Builders public EntityBuilderBase(ObservablesContext context) { _steps = new List>(); + _querySteps = new List, IQueryable>>>(); Context = context; } @@ -30,6 +32,12 @@ namespace Tango.BL.Builders { IQueryable query = Context.Set().Where(condition); query = OnSetQuery(query); + + foreach (var queryStep in _querySteps.ToList().DistinctBy(x => x.Key).OrderBy(x => x.Key)) + { + query = queryStep.Value(query); + } + Entity = query.FirstOrDefault(); }); @@ -46,6 +54,12 @@ namespace Tango.BL.Builders { IQueryable query = Context.Set(); query = OnSetQuery(query); + + foreach (var queryStep in _querySteps.ToList().DistinctBy(x => x.Key).OrderBy(x => x.Key)) + { + query = queryStep.Value(query); + } + Entity = query.FirstOrDefault(); }); @@ -84,6 +98,12 @@ namespace Tango.BL.Builders return this as TBuilder; } + protected TBuilder AddQueryStep(int index, Func, IQueryable> func) + { + _querySteps.Add(new KeyValuePair, IQueryable>>(index, func)); + return this as TBuilder; + } + protected void CommitSteps() { foreach (var step in _steps.ToList().DistinctBy(x => x.Key).OrderBy(x => x.Key)) diff --git a/Software/Visual_Studio/Tango.BL/Builders/EntityCollectionBuilderBase.cs b/Software/Visual_Studio/Tango.BL/Builders/EntityCollectionBuilderBase.cs index 9ed42cab6..a0cd24511 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/EntityCollectionBuilderBase.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/EntityCollectionBuilderBase.cs @@ -11,6 +11,7 @@ namespace Tango.BL.Builders public class EntityCollectionBuilderBase : IEntityCollectionBuilder where T : ObservableEntity where TBuilder : EntityCollectionBuilderBase { private List> _steps; + private List, IQueryable>>> _querySteps; private bool _entity_set; protected IEnumerable Entities { get; set; } @@ -21,15 +22,22 @@ namespace Tango.BL.Builders { Entities = new List(); _steps = new List>(); + _querySteps = new List, IQueryable>>>(); Context = context; } - public virtual TBuilder Set() + public virtual TBuilder SetAll() { AddStep(0, () => { IQueryable query = Context.Set(); query = OnSetQuery(query); + + foreach (var queryStep in _querySteps.ToList().DistinctBy(x => x.Key).OrderBy(x => x.Key)) + { + query = queryStep.Value(query); + } + Entities = query.ToList(); }); @@ -44,6 +52,12 @@ namespace Tango.BL.Builders { IQueryable query = Context.Set().Where(condition); query = OnSetQuery(query); + + foreach (var queryStep in _querySteps.ToList().DistinctBy(x => x.Key).OrderBy(x => x.Key)) + { + query = queryStep.Value(query); + } + Entities = query.ToList(); }); @@ -72,6 +86,12 @@ namespace Tango.BL.Builders return this as TBuilder; } + protected TBuilder AddQueryStep(int index, Func, IQueryable> func) + { + _querySteps.Add(new KeyValuePair, IQueryable>>(index, func)); + return this as TBuilder; + } + public SynchronizedObservableCollection Build() { if (!_entity_set) diff --git a/Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs new file mode 100644 index 000000000..7eae8cff2 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class OrganizationBuilder : EntityBuilderBase + { + public OrganizationBuilder(ObservablesContext context) : base(context) + { + + } + + protected override IQueryable OnSetQuery(IQueryable query) + { + return query.Include(x => x.Address).Include(x => x.Contact); + } + + public virtual OrganizationBuilder WithUsers() + { + return AddStep(1, () => + { + Context.Roles.Load(); + Context.Permissions.Load(); + Context.RolesPermissions.Load(); + + Context.Users.Where(x => x.OrganizationGuid == Entity.Guid && !x.Deleted) + .Include(x => x.Address) + .Include(x => x.Contact) + .Include(x => x.UsersRoles).ToSynchronizedObservableCollection(); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/OrganizationsCollectionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/OrganizationsCollectionBuilder.cs new file mode 100644 index 000000000..bd9ca54d9 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/OrganizationsCollectionBuilder.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class OrganizationsCollectionBuilder : EntityCollectionBuilderBase + { + public OrganizationsCollectionBuilder(ObservablesContext context) : base(context) + { + + } + + protected override IQueryable OnSetQuery(IQueryable query) + { + return query.Include(x => x.Contact).Include(x => x.Address); + } + + public virtual OrganizationsCollectionBuilder WithMachines() + { + return AddQueryStep(1, (query) => + { + return query.Include(x => x.Machines); + }); + } + + public virtual OrganizationsCollectionBuilder WithUsers() + { + return AddStep(2, () => + { + foreach (var organization in Entities) + { + new UsersCollectionBuilder(Context).Set(x => x.OrganizationGuid == organization.Guid).WithAddress().WithContacts().Build(); + } + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/RolesCollectionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/RolesCollectionBuilder.cs new file mode 100644 index 000000000..00646ac13 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/RolesCollectionBuilder.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class RolesCollectionBuilder : EntityCollectionBuilderBase + { + public RolesCollectionBuilder(ObservablesContext context) : base(context) + { + + } + + public virtual RolesCollectionBuilder WithPermission() + { + return AddQueryStep(1, (query) => + { + return query + .Include(x => x.RolesPermissions) + .Include(x => x.RolesPermissions.Select(y => y.Permission)); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Builders/UserBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/UserBuilder.cs index 9da682e27..5fdcd34c0 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/UserBuilder.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/UserBuilder.cs @@ -10,6 +10,8 @@ namespace Tango.BL.Builders { public class UserBuilder : EntityBuilderBase { + private bool deleted; + public UserBuilder(ObservablesContext context) : base(context) { @@ -17,7 +19,20 @@ namespace Tango.BL.Builders protected override IQueryable OnSetQuery(IQueryable query) { - return query.Include(x => x.Address).Include(x => x.Contact); + if (!deleted) + { + return query.Where(x => !x.Deleted).Include(x => x.Address).Include(x => x.Contact); + } + else + { + return query.Include(x => x.Address).Include(x => x.Contact); + } + } + + public virtual UserBuilder WithDeleted() + { + deleted = true; + return this; } public virtual UserBuilder WithOrganization() @@ -28,6 +43,7 @@ namespace Tango.BL.Builders }); } + public virtual UserBuilder WithRolesAndPermissions() { return AddStep(2, () => diff --git a/Software/Visual_Studio/Tango.BL/Builders/UsersCollectionBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/UsersCollectionBuilder.cs new file mode 100644 index 000000000..39e5d73a6 --- /dev/null +++ b/Software/Visual_Studio/Tango.BL/Builders/UsersCollectionBuilder.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using System.Data.Entity; + +namespace Tango.BL.Builders +{ + public class UsersCollectionBuilder : EntityCollectionBuilderBase + { + private bool deleted; + + public UsersCollectionBuilder(ObservablesContext context) : base(context) + { + + } + + protected override IQueryable OnSetQuery(IQueryable query) + { + if (!deleted) + { + return query.Where(x => !x.Deleted); + } + else + { + return query; + } + } + + public virtual UsersCollectionBuilder WithDeleted() + { + deleted = true; + return this; + } + + public virtual UsersCollectionBuilder WithContacts() + { + return AddQueryStep(2, (query) => + { + return query.Include(x => x.Contact); + }); + } + + public virtual UsersCollectionBuilder WithAddress() + { + return AddQueryStep(3, (query) => + { + return query.Include(x => x.Address); + }); + } + + public virtual UsersCollectionBuilder WithOrganization() + { + return AddQueryStep(4, (query) => + { + return query.Include(x => x.Organization); + }); + } + } +} diff --git a/Software/Visual_Studio/Tango.BL/Entities/UsersRoleBase.cs b/Software/Visual_Studio/Tango.BL/Entities/UsersRoleBase.cs index 50248a7a2..b852916e0 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/UsersRoleBase.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/UsersRoleBase.cs @@ -25,39 +25,10 @@ namespace Tango.BL.Entities public abstract class UsersRoleBase : ObservableEntity { - public event EventHandler DeletedChanged; - public event EventHandler RoleChanged; public event EventHandler UserChanged; - protected Boolean _deleted; - - /// - /// Gets or sets the usersrolebase deleted. - /// - - [Column("DELETED")] - - public Boolean Deleted - { - get - { - return _deleted; - } - - set - { - if (_deleted != value) - { - _deleted = value; - - OnDeletedChanged(value); - - } - } - } - protected String _userguid; /// @@ -162,15 +133,6 @@ namespace Tango.BL.Entities } } - /// - /// Called when the Deleted has changed. - /// - protected virtual void OnDeletedChanged(Boolean deleted) - { - DeletedChanged?.Invoke(this, deleted); - RaisePropertyChanged(nameof(Deleted)); - } - /// /// Called when the Role has changed. /// diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContext.Views.cs b/Software/Visual_Studio/Tango.BL/ObservablesContext.Views.cs index e268251e2..035166337 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContext.Views.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContext.Views.cs @@ -11,7 +11,7 @@ using System.Data.Entity.Infrastructure.MappingViews; [assembly: DbMappingViewCacheTypeAttribute( typeof(Tango.BL.ObservablesContext), - typeof(Edm_EntityMappingGeneratedViews.ViewsForBaseEntitySets91164af96978f329be8dbfbcaab4ded62e91156cf1a365c28cdfe98d9901ffb6))] + typeof(Edm_EntityMappingGeneratedViews.ViewsForBaseEntitySets0d16b15979dfe51121471eb5a4f154efd8d2725e999a657f5a837ed4cce78ba6))] namespace Edm_EntityMappingGeneratedViews { @@ -23,14 +23,14 @@ namespace Edm_EntityMappingGeneratedViews /// Implements a mapping view cache. /// [GeneratedCode("Entity Framework Power Tools", "0.9.0.0")] - internal sealed class ViewsForBaseEntitySets91164af96978f329be8dbfbcaab4ded62e91156cf1a365c28cdfe98d9901ffb6 : DbMappingViewCache + internal sealed class ViewsForBaseEntitySets0d16b15979dfe51121471eb5a4f154efd8d2725e999a657f5a837ed4cce78ba6 : DbMappingViewCache { /// /// Gets a hash value computed over the mapping closure. /// public override string MappingHashValue { - get { return "91164af96978f329be8dbfbcaab4ded62e91156cf1a365c28cdfe98d9901ffb6"; } + get { return "0d16b15979dfe51121471eb5a4f154efd8d2725e999a657f5a837ed4cce78ba6"; } } /// @@ -2307,11 +2307,10 @@ namespace Edm_EntityMappingGeneratedViews { return new DbMappingView(@" SELECT VALUE -- Constructing UsersRole - [CodeFirstDatabaseSchema.UsersRole](T1.UsersRole_GUID, T1.UsersRole_DELETED, T1.[UsersRole.USER_GUID], T1.[UsersRole.ROLE_GUID], T1.UsersRole_ID, T1.[UsersRole.LAST_UPDATED]) + [CodeFirstDatabaseSchema.UsersRole](T1.UsersRole_GUID, T1.[UsersRole.USER_GUID], T1.[UsersRole.ROLE_GUID], T1.UsersRole_ID, T1.[UsersRole.LAST_UPDATED]) FROM ( SELECT T.Guid AS UsersRole_GUID, - T.Deleted AS UsersRole_DELETED, T.UserGuid AS [UsersRole.USER_GUID], T.RoleGuid AS [UsersRole.ROLE_GUID], T.ID AS UsersRole_ID, @@ -3933,11 +3932,10 @@ namespace Edm_EntityMappingGeneratedViews { return new DbMappingView(@" SELECT VALUE -- Constructing UsersRoles - [Tango.BL.UsersRole](T1.UsersRole_Guid, T1.UsersRole_Deleted, T1.UsersRole_UserGuid, T1.UsersRole_RoleGuid, T1.UsersRole_ID, T1.UsersRole_LastUpdated) + [Tango.BL.UsersRole](T1.UsersRole_Guid, T1.UsersRole_UserGuid, T1.UsersRole_RoleGuid, T1.UsersRole_ID, T1.UsersRole_LastUpdated) FROM ( SELECT T.GUID AS UsersRole_Guid, - T.DELETED AS UsersRole_Deleted, T.USER_GUID AS UsersRole_UserGuid, T.ROLE_GUID AS UsersRole_RoleGuid, T.ID AS UsersRole_ID, diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs index ef44c2db6..cb9f63938 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextAdapter.cs @@ -152,49 +152,6 @@ namespace Tango.BL return _db.LiquidTypesRmls.Where(x => x.RmlGuid == rmlGuid).ToObservableCollection(); } - /// - /// Gets the organization with all it's users addresses and contacts. - /// - /// The organization unique identifier. - /// - public Organization GetOrganizationAndUsers(String organizationGuid) - { - var org = _db.Organizations.SingleOrDefault(x => x.Guid == organizationGuid); - - org.Address = _db.Addresses.SingleOrDefault(x => x.Guid == org.AddressGuid); - org.Contact = _db.Contacts.SingleOrDefault(x => x.Guid == org.ContactGuid); - - _db.Roles.Load(); - _db.Permissions.Load(); - _db.RolesPermissions.Load(); - - - org.Users = _db.Users.Where(x => x.OrganizationGuid == organizationGuid) - .Include(x => x.Address) - .Include(x => x.Contact) - .Include(x => x.UsersRoles).ToSynchronizedObservableCollection(); - - return org; - } - - /// - /// Gets the user with it's address and contact. - /// - /// The user unique identifier. - /// - public User GetUser(String userGuid) - { - _db.Roles.Load(); - _db.Permissions.Load(); - _db.RolesPermissions.Load(); - - return _db.Users.Where(x => x.Guid == userGuid) - .Include(x => x.Address) - .Include(x => x.Contact) - .Include(x => x.UsersRoles) - .FirstOrDefault(); - } - /// /// Gets the job with all its segments and brush stops. /// diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs index e3fb7dee4..90d78f6bc 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs @@ -6,18 +6,32 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.Helpers; namespace Tango.BL { public class ObservablesContextConfiguration : DbConfiguration { - public String FolderPath { get; private set; } + public static String FolderPath { get; private set; } - public ObservablesContextConfiguration() : base() + static ObservablesContextConfiguration() { FolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "EFCache", Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName)); + } + + public ObservablesContextConfiguration() : base() + { Directory.CreateDirectory(FolderPath); SetModelStore(new DefaultDbModelStore(FolderPath)); } + + public static void ClearModelStore() + { + try + { + Directory.Delete(FolderPath); + } + catch { } + } } } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index 5ee04c01f..d36113e71 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -209,5 +209,13 @@ namespace Tango.BL { return GetActualDataSource().ToString(); } + + /// + /// Clears the model store on the file system. + /// + public static void ClearModelStore() + { + ObservablesContextConfiguration.ClearModelStore(); + } } } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs index a4b36b739..89c8f8d86 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs @@ -97,7 +97,7 @@ namespace Tango.BL Machines = db.Machines.Include(x => x.Organization).ToObservableCollection(); - Users = db.Users.Include(x => x.Contact).ToObservableCollection(); + Users = db.Users.Where(x => !x.Deleted).Include(x => x.Contact).ToObservableCollection(); MachineVersions = db.MachineVersions.ToObservableCollection(); diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index 825759b23..c4f672593 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -91,9 +91,13 @@ + + + + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx index c21be7dbc..093721d7a 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx @@ -1027,7 +1027,6 @@ - @@ -1987,9 +1986,7 @@ - - - + @@ -2001,9 +1998,7 @@ - - - + @@ -2041,9 +2036,7 @@ - - - + @@ -4003,7 +3996,6 @@ - @@ -4036,9 +4028,7 @@ - - - + @@ -4308,9 +4298,7 @@ - - - + @@ -5020,9 +5008,7 @@ - - - + @@ -6128,7 +6114,6 @@ - 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 29bfb381b..f22d19e11 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/RemoteADO.edmx.diagram @@ -5,76 +5,76 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.DAL.Remote/DB/USERS_ROLES.cs b/Software/Visual_Studio/Tango.DAL.Remote/DB/USERS_ROLES.cs index d3702146d..a81b9e138 100644 --- a/Software/Visual_Studio/Tango.DAL.Remote/DB/USERS_ROLES.cs +++ b/Software/Visual_Studio/Tango.DAL.Remote/DB/USERS_ROLES.cs @@ -17,7 +17,6 @@ namespace Tango.DAL.Remote.DB public int ID { get; set; } public string GUID { get; set; } public System.DateTime LAST_UPDATED { get; set; } - public bool DELETED { get; set; } public string USER_GUID { get; set; } public string ROLE_GUID { get; set; } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index 82082ca2f..054c8d781 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -145,15 +145,9 @@ namespace Tango.MachineService.Controllers using (ObservablesContext db = ObservablesContextHelper.CreateContext()) { - //Load relation first... - db.Roles.ToList(); - db.Permissions.ToList(); - db.UsersRoles.ToList(); - db.RolesPermissions.ToList(); - String userID = TokensManager.GetTokenObject(request.AccessToken); - var user = db.Users.SingleOrDefault(x => x.Guid == userID); + var user = new UserBuilder(db).Set(userID).WithRolesAndPermissions().Build(); if (user != null && user.HasPermission(Permissions.PublishMachineStudioVersions)) { @@ -281,7 +275,7 @@ namespace Tango.MachineService.Controllers db.UsersRoles.ToList(); db.RolesPermissions.ToList(); - user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower()); + user = new UserBuilder(db).Set(x => x.Email.ToLower() == request.Email.ToLower()).WithRolesAndPermissions().WithDeleted().Build(); IHashGenerator g = new BasicHashGenerator(); @@ -318,6 +312,11 @@ namespace Tango.MachineService.Controllers } else { + if (user.Deleted) + { + throw new AuthenticationException("Your account has been disabled. Please contact your administrator."); + } + user.LastLogin = DateTime.UtcNow; user.Password = g.Encrypt(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 5e41e0d8a..ead64fb38 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -317,7 +317,7 @@ namespace Tango.MachineService.Controllers var user_guid = TokensManager.GetTokenObject(request.AccessToken).UserGuid; - var user = db.Users.SingleOrDefault(x => x.Guid == user_guid); + var user = new UserBuilder(db).Set(user_guid).WithRolesAndPermissions().Build(); if (user != null && user.HasPermission(Permissions.PublishPPCVersions)) { @@ -432,7 +432,7 @@ namespace Tango.MachineService.Controllers BasicHashGenerator hash = new BasicHashGenerator(); String pass = hash.Encrypt(request.Password); - var user = db.Users.SingleOrDefault(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == pass); + var user = new UserBuilder(db).Set(x => x.Email.ToLower() == request.Email.ToLower() && x.Password == pass).Build(); if (user == null) { -- cgit v1.3.1