diff options
| author | Roy Ben Shabat <Roy@twine-s.com> | 2020-12-30 15:11:34 +0000 |
|---|---|---|
| committer | Roy Ben Shabat <Roy@twine-s.com> | 2020-12-30 15:11:34 +0000 |
| commit | d33c19b3ac6803de4b5c8d475832efef131c1a45 (patch) | |
| tree | ea725abc39def99a755b041c13cba1fe0d594ddc /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels | |
| parent | 1bdcaa9f51303bbff682507f31fb3b4414692ca4 (diff) | |
| download | Tango-d33c19b3ac6803de4b5c8d475832efef131c1a45.tar.gz Tango-d33c19b3ac6803de4b5c8d475832efef131c1a45.zip | |
Revert "Hope it is fine"
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels')
8 files changed, 411 insertions, 110 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs index 16f6938a0..30b2c83fd 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectedMachineViewVM.cs @@ -95,11 +95,11 @@ namespace Tango.MachineStudio.UI.ViewModels using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var jobs = await db.Jobs.Include(x => x.JobRuns).Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).ToListAsync(); + var jobRuns = await db.JobRuns.Where(x => x.MachineGuid == ApplicationManager.Machine.Guid).Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).ToListAsync(); - TotalMachineWorkTime = TimeSpan.FromHours(jobs.SelectMany(x => x.JobRuns).Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToString(@"hh\:mm\:ss"); + TotalMachineWorkTime = TimeSpan.FromHours(jobRuns.Select(x => x.EndDate - x.StartDate).Sum(x => x.TotalHours)).ToStringUnlimitedHours(); - int meters = (int)jobs.SelectMany(x => x.JobRuns).Select(x => x.EndPosition).Sum(); + int meters = (int)jobRuns.Select(x => x.EndPosition).Sum(); TotalMachineMeters = $"{meters.ToString("N0")} meters"; } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs index f1f4f69c0..e96f0ab62 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/ConnectionLostViewVM.cs @@ -3,12 +3,76 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Timers; +using System.Windows.Threading; using Tango.SharedUI; namespace Tango.MachineStudio.UI.ViewModels { public class ConnectionLostViewVM : DialogViewVM { + private Timer _reconnectTimer; + public String Exception { get; set; } + + private int _reconnectinSeconds; + public int ReconnectinSeconds + { + get { return _reconnectinSeconds; } + set { _reconnectinSeconds = value; RaisePropertyChangedAuto(); } + } + + private bool _autoReconnect; + public bool AutoReconnect + { + get { return _autoReconnect; } + set { _autoReconnect = value; RaisePropertyChangedAuto(); } + } + + + public ConnectionLostViewVM() : base() + { + ReconnectinSeconds = 10; + _reconnectTimer = new Timer(); + _reconnectTimer.Interval = TimeSpan.FromSeconds(1).TotalMilliseconds; + _reconnectTimer.Elapsed += _reconnectTimer_Elapsed; + } + + private void _reconnectTimer_Elapsed(object sender, ElapsedEventArgs e) + { + ReconnectinSeconds--; + + if (ReconnectinSeconds == -1) + { + _reconnectTimer.Stop(); + + InvokeUI(() => + { + Accept(); + }); + } + } + + public override void OnShow() + { + base.OnShow(); + + if (AutoReconnect) + { + _reconnectTimer.Start(); + } + } + + protected override void Accept() + { + _reconnectTimer.Stop(); + base.Accept(); + } + + protected override void Cancel() + { + base.Cancel(); + _reconnectTimer.Stop(); + } } } 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 e45c29f73..7d2d8b401 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/FirmwareUpgradeViewVM.cs @@ -202,11 +202,17 @@ namespace Tango.MachineStudio.UI.ViewModels { IsFree = true; CanClose = true; + _stream?.Dispose(); UpgradeError = ex.FlattenMessage(); CurrentPage = 3; } } + protected override bool CanOK() + { + return base.CanOK() && CanClose; + } + private async void AbortUpgrade() { CanClose = true; 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 cf34764d9..f4645ecf2 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -22,6 +22,9 @@ using Tango.MachineStudio.UI.Messages; using Tango.Settings; using Tango.SharedUI; using Tango.Web; +using SimpleValidator.Extensions; +using Tango.BL.Entities; +using System.Data.Entity; namespace Tango.MachineStudio.UI.ViewModels { @@ -38,6 +41,7 @@ namespace Tango.MachineStudio.UI.ViewModels private Rfc2898Cryptographer cryptographer; private MachineStudioSettings _settings; private MachineStudioWebClient _machineStudioWebClient; + private TaskCompletionSource<object> _updatePasswordCompletionSource; private String _email; /// <summary> @@ -82,6 +86,14 @@ namespace Tango.MachineStudio.UI.ViewModels set { _isLogging = value; RaisePropertyChangedAuto(); } } + private bool _showLogginDetails; + public bool ShowLoggingDetails + { + get { return _showLogginDetails; } + set { _showLogginDetails = value; RaisePropertyChangedAuto(); } + } + + private bool _rememberMe; /// <summary> /// Gets or sets a value indicating whether to remember the last user email and password. @@ -102,6 +114,47 @@ namespace Tango.MachineStudio.UI.ViewModels set { _enableSlotSelection = value; RaisePropertyChangedAuto(); } } + private bool _isActiveDirectory; + public bool IsActiveDirectory + { + get { return _isActiveDirectory; } + set { _isActiveDirectory = value; RaisePropertyChangedAuto(); if (value) IsStandardUser = false; } + } + + private bool _isStandardUser; + public bool IsStandardUser + { + get { return _isStandardUser; } + set { _isStandardUser = value; RaisePropertyChangedAuto(); if (value) IsActiveDirectory = false; } + } + + private String _progressLog; + public String ProgressLog + { + get { return _progressLog; } + set { _progressLog = value; RaisePropertyChangedAuto(); } + } + + private bool _isChangingPassword; + public bool IsChangingPassword + { + get { return _isChangingPassword; } + set { _isChangingPassword = value; RaisePropertyChangedAuto(); } + } + + private String _newPassword1; + public String NewPassword1 + { + get { return _newPassword1; } + set { _newPassword1 = value; RaisePropertyChangedAuto(); } + } + + private String _newPassword2; + public String NewPassword2 + { + get { return _newPassword2; } + set { _newPassword2 = value; RaisePropertyChangedAuto(); } + } /// <summary> /// Gets or sets the login command. @@ -109,6 +162,11 @@ namespace Tango.MachineStudio.UI.ViewModels public RelayCommand LoginCommand { get; set; } /// <summary> + /// Gets or sets the update password command. + /// </summary> + public RelayCommand UpdatePasswordCommand { get; set; } + + /// <summary> /// Initializes a new instance of the <see cref="LoginViewVM"/> class. /// </summary> /// <param name="authenticationProvider">The authentication provider.</param> @@ -117,6 +175,7 @@ namespace Tango.MachineStudio.UI.ViewModels public LoginViewVM(MachineStudioWebClient machineStudioWebClient, IAuthenticationProvider authenticationProvider, INavigationManager navigationManager, INotificationProvider notificationProvider, IEventLogger eventLogger) { EnableSlotSelection = true; + ShowLoggingDetails = true; _machineStudioWebClient = machineStudioWebClient; _settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>(); @@ -126,12 +185,22 @@ namespace Tango.MachineStudio.UI.ViewModels _authenticationProvider = authenticationProvider; _eventLogger = eventLogger; LoginCommand = new RelayCommand(Login, () => !IsLogging); + UpdatePasswordCommand = new RelayCommand(UpdatePassword, () => IsChangingPassword); cryptographer = new Rfc2898Cryptographer(); Email = _settings.LastLoginEmail; DeploymentSlot = _settings.DeploymentSlot; RememberMe = _settings.RememberMe; + if (_settings.LastLoginMethod == LoginMethod.ActiveDirectory) + { + IsActiveDirectory = true; + } + else + { + IsStandardUser = true; + } + try { Password = cryptographer.Decrypt(_settings.LastLoginPassword); @@ -152,13 +221,22 @@ namespace Tango.MachineStudio.UI.ViewModels try { IsLogging = true; + ShowLoggingDetails = false; + NewPassword1 = String.Empty; + NewPassword2 = String.Empty; + InvalidateRelayCommands(); + LoginMethod loginMethod = IsActiveDirectory ? LoginMethod.ActiveDirectory : LoginMethod.StandardUser; + await Task.Factory.StartNew(() => { _settings.DeploymentSlot = DeploymentSlot; - LoginResponse result = _authenticationProvider.Login(Email, Password, _settings.ByPassEnvironmentVersionCheck).Response; + LoginResponse result = _authenticationProvider.Login(Email, Password, loginMethod, _settings.ByPassEnvironmentVersionCheck, (progress) => + { + ProgressLog = progress; + }).Response; if (result.VersionChangeRequired && !_settings.ByPassEnvironmentVersionCheck) { @@ -177,31 +255,113 @@ namespace Tango.MachineStudio.UI.ViewModels return; } - _eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!"); + if (result.PasswordChangeRequired) + { + StartUpdatePassword().Task.GetAwaiter().GetResult(); + Password = NewPassword1; + Login(); + return; + } + + //_eventLogger.Log(EventTypes.APPLICATION_STARTED, "Application Started!"); _navigationManager.NavigateTo(NavigationView.MainView); _settings.LastLoginEmail = Email; _settings.RememberMe = RememberMe; + _settings.LastLoginMethod = loginMethod; _settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null; _settings.Save(); - _eventLogger.Log("User logged in."); - EnableSlotSelection = false; + + IsLogging = false; + ShowLoggingDetails = true; + IsChangingPassword = false; + InvalidateRelayCommands(); }); } catch (Exception ex) { + IsLogging = false; + ShowLoggingDetails = true; + IsChangingPassword = false; + InvalidateRelayCommands(); LogManager.Log(ex, "Login Error."); _notificationProvider.ShowError($"An error occurred while trying to perform the log-in operation.\n{ex.FlattenMessage()}"); } - finally + } + } + + private TaskCompletionSource<object> StartUpdatePassword() + { + _updatePasswordCompletionSource = new TaskCompletionSource<object>(); + + IsChangingPassword = true; + ShowLoggingDetails = false; + IsLogging = false; + InvalidateRelayCommands(); + + return _updatePasswordCompletionSource; + } + + private async void UpdatePassword() + { + await Task.Factory.StartNew(() => + { + try + { + if (!Validate()) + { + return; + } + + ProgressLog = "Updating your password..."; + IsChangingPassword = false; + IsLogging = true; + InvalidateRelayCommands(); + + using (var db = ObservablesContext.CreateDefault()) + { + var user = db.Users.SingleOrDefault(x => x.Email == Email); + user.PasswordChangeRequired = false; + user.Password = User.GetPasswordHash(NewPassword1); + db.SaveChanges(); + } + + _updatePasswordCompletionSource.SetResult(true); + } + catch (Exception ex) { IsLogging = false; + IsChangingPassword = false; + ShowLoggingDetails = true; InvalidateRelayCommands(); + _updatePasswordCompletionSource.SetException(ex); + } + finally + { + InvalidateRelayCommands(); + } + }); + } + + protected override void OnValidating() + { + if (IsChangingPassword) + { + if (!NewPassword1.IsBetweenLength(6, 8)) + { + InsertError(nameof(NewPassword1), "Password must be 6 to 8 characters long"); + } + + if (NewPassword1 != NewPassword2) + { + InsertError(nameof(NewPassword2), "Passwords do not match"); } } + + base.OnValidating(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs index d1f3cc69e..5e44bf43d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineConnectionViewVM.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +using Tango.Core.DI; using Tango.Emulations.ExternalBridge; using Tango.Integration.ExternalBridge; using Tango.MachineStudio.Common; @@ -52,7 +53,18 @@ namespace Tango.MachineStudio.UI.ViewModels { if (_scanner == null) { + var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>(); _scanner = new ExternalBridgeScanner(); + _scanner.SignalRConfiguration.Enabled = settings.EnableExternalBridgeSignalR; + if (App.StartupArgs.Contains("-webDebug")) + { + _scanner.SignalRConfiguration.Address = "http://localhost:1111/"; //settings.DeploymentSlot.ToAddress(); + } + else + { + _scanner.SignalRConfiguration.Address = settings.DeploymentSlot.ToAddress(); + } + _scanner.SignalRConfiguration.Hub = settings.ExternalBridgeSignalRHub; } EnableDiagnostics = true; @@ -108,6 +120,8 @@ namespace Tango.MachineStudio.UI.ViewModels catch (Exception ex) { LogManager.Log(ex, "Error starting external bridge scanner."); + Cancel(); + TangoIOC.Default.GetInstance<INotificationProvider>().ShowError($"There is a problem with machine scanning.\n{ex.FlattenMessage()}"); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs index 7584617ed..81d3f4243 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineLoginViewVM.cs @@ -27,6 +27,11 @@ namespace Tango.MachineStudio.UI.ViewModels public ExternalBridgeLoginIntent Intent { get; set; } /// <summary> + /// Gets or sets a value indicating whether to require safety level operations permission from the remote machine. + /// </summary> + public bool RequireSafetyOperations { get; set; } + + /// <summary> /// Gets or sets the login command. /// </summary> public RelayCommand<String> LoginCommand { get; set; } @@ -41,7 +46,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// </summary> public MachineLoginViewVM() { - Intent = ExternalBridgeLoginIntent.FullControl; + Intent = ExternalBridgeLoginIntent.Diagnostics; LoginCommand = new RelayCommand<string>(Login); CancelCommand = new RelayCommand(Cancel); } 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 90fe25c8f..4f8c8a9b1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -58,6 +58,9 @@ namespace Tango.MachineStudio.UI.ViewModels private IEventLogger _eventLogger; private MachineStudioSettings _settings; private MachineStudioWebClient _machineStudioWebClient; + private IExternalBridgeClient _reconnectionMachine; + private MachineLoginViewVM _reconnectionMachineConfig; + private bool _lastUploadHardwareConfigLocal; /// <summary> /// Gets or sets the current loaded module. @@ -344,6 +347,20 @@ namespace Tango.MachineStudio.UI.ViewModels AboutCommand = new RelayCommand(ShowAboutDialog); ChangeAppThemeCommand = new RelayCommand<MachineStudioTheme>(ChangeTheme); + + ApplicationManager.ReconnectionRequired += ApplicationManager_ReconnectionRequired; + } + + private async void ApplicationManager_ReconnectionRequired(object sender, EventArgs e) + { + if (_reconnectionMachine is IExternalBridgeSecureClient client) + { + ConnectToMachineSecure(client, _reconnectionMachineConfig); + } + else + { + await ConnectToMachineLocal(_reconnectionMachine, _reconnectionMachine.Machine, _lastUploadHardwareConfigLocal); + } } private void MachineEventsStateProvider_EventsResolved(object sender, IEnumerable<MachinesEvent> e) @@ -401,13 +418,11 @@ namespace Tango.MachineStudio.UI.ViewModels String serial = ApplicationManager.ConnectedMachine.SerialNumber; await ApplicationManager.ConnectedMachine.Disconnect(); ApplicationManager.SetConnectedMachine(null); - _eventLogger.Log("Disconnected from machine " + serial); PostMessage(new MachineConnectionChangedMessage() { Machine = null }); } catch (Exception ex) { - _eventLogger.Log(ex, "Error disconnecting from machine."); LogManager.Log(ex, "Could not disconnect from machine."); } finally @@ -455,71 +470,23 @@ namespace Tango.MachineStudio.UI.ViewModels x.SelectedMachine.EnableEventsNotification = x.EnableDiagnostics; x.SelectedMachine.UseKeepAlive = x.EnableKeepAlive; x.SelectedMachine.JobUnitsMethod = _settings.JobUnitsMethod; + x.SelectedMachine.JobRunsLogger.JobSource = BL.Enumerations.JobSource.Remote; if (x.SelectedMachine is ExternalBridgeTcpClient) { x.SelectedMachine.As<ExternalBridgeTcpClient>().EnableApplicationLogs = x.EnableApplicationLogs; x.SelectedMachine.RequestTimeout = _settings.ExternalBridgeRequestTimeout; + x.SelectedMachine.ContinuousRequestTimeout = _settings.ExternalBridgeContinuousRequestTimeout; } - if (x.SelectedMachine.RequiresAuthentication) + if (x.SelectedMachine.Adapter is TcpTransportAdapter) { - //Check machine exist on my database first - if (x.SelectedMachine.Machine == null) - { - _notificationProvider.ShowError($"The specified machine '{x.SelectedMachine.SerialNumber}' could not be found on the database. Aborting connection."); - return; - } - - _notificationProvider.ShowModalDialog<MachineLoginViewVM>(async (login) => - { - using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.ToString() + "...")) - { - try - { - await x.SelectedMachine.As<IExternalBridgeSecureClient>().Connect(new PMR.Integration.ExternalBridgeLoginRequest() - { - AppID = "Machine Studio", - HostName = Environment.MachineName, - Password = login.Password, - UserGuid = AuthenticationProvider.CurrentUser.Guid, - Intent = login.Intent, - }); - - ApplicationManager.SetConnectedMachine(x.SelectedMachine); - (x.SelectedMachine as IExternalBridgeSecureClient).SessionClosed += (_, __) => - { - InvokeUI(() => - { - _notificationProvider.ShowError("The remote machine has closed the current session. Machine disconnected."); - ApplicationManager.SetConnectedMachine(null); - }); - }; - PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); - _eventLogger.Log(String.Format("Successfully connected to machine {0} via TCP", x.SelectedMachine.SerialNumber)); - - //if (x.UploadHardwareConfiguration) - //{ - // UploadHardwareConfiguration(false); - //} - - } - catch (ResponseErrorException ex) - { - LogManager.Log(ex); - _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Container.ErrorMessage); - } - catch (Exception ex) - { - LogManager.Log(ex); - _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); - } + (x.SelectedMachine.Adapter as TcpTransportAdapter).WriteMode = _settings.TcpTransportAdapterWriteMode; + } - InvalidateRelayCommands(); - } - }); + if (x.SelectedMachine.RequiresAuthentication) + { + ConnectToMachineSecure(x.SelectedMachine as IExternalBridgeSecureClient); } else { @@ -527,47 +494,15 @@ namespace Tango.MachineStudio.UI.ViewModels { if (vm.SelectedMachine != null) { - using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) - { - try - { - await x.SelectedMachine.Connect(); - x.SelectedMachine.SerialNumber = vm.SelectedMachine.SerialNumber; - ApplicationManager.SetConnectedMachine(x.SelectedMachine); - - PostMessage(new MachineConnectionChangedMessage() { Machine = x.SelectedMachine }); - _eventLogger.Log(String.Format("Successfully connected to machine {0} via USB", x.SelectedMachine.SerialNumber)); - _settings.LastVirtualMachineSerialNumber = vm.SelectedMachine.SerialNumber; - _settings.Save(); - - if (x.UploadHardwareConfiguration) - { - UploadHardwareConfiguration(false); - } - } - catch (Exception ex) - { - LogManager.Log(ex); - - if (x.SelectedMachine != null) - { - _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); - } - - _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); - - } - - InvalidateRelayCommands(); - } + await ConnectToMachineLocal(x.SelectedMachine, vm.SelectedMachine, x.UploadHardwareConfiguration); } }); } - InvalidateRelayCommands(); + base.InvalidateRelayCommands(); } - InvalidateRelayCommands(); + base.InvalidateRelayCommands(); }); } else @@ -632,6 +567,115 @@ namespace Tango.MachineStudio.UI.ViewModels InvalidateRelayCommands(); } + private async Task ConnectToMachineLocal(IExternalBridgeClient client, Machine machine, bool uploadHardwareConfig) + { + using (NotificationProvider.PushTaskItem("Connecting to " + client.ToString() + "...")) + { + try + { + _reconnectionMachine = client; + + await client.Connect(); + client.SerialNumber = machine.SerialNumber; + ApplicationManager.SetConnectedMachine(client); + + PostMessage(new MachineConnectionChangedMessage() { Machine = client }); + _settings.LastVirtualMachineSerialNumber = machine.SerialNumber; + _settings.Save(); + + _lastUploadHardwareConfigLocal = uploadHardwareConfig; + + if (uploadHardwareConfig) + { + UploadHardwareConfiguration(false); + } + } + catch (Exception ex) + { + LogManager.Log(ex); + + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); + + } + + InvalidateRelayCommands(); + } + } + + private async void ConnectToMachineSecure(IExternalBridgeSecureClient machine, MachineLoginViewVM config) + { + using (NotificationProvider.PushTaskItem("Connecting to machine " + machine.ToString() + "...")) + { + try + { + await machine.Connect(new PMR.Integration.ExternalBridgeLoginRequest() + { + AppID = "Machine Studio", + HostName = Environment.MachineName, + Password = config.Password, + UserGuid = AuthenticationProvider.CurrentUser.Guid, + Intent = config.Intent, + UserName = AuthenticationProvider.CurrentUser.Contact.FullName, + RequireSafetyLevelOperations = config.RequireSafetyOperations + }, new PMR.Integration.ConfigureProtocolRequest() + { + EnableCompression = true, + GenericProtocol = PMR.Integration.GenericMessageProtocol.Bson + }); + + _reconnectionMachine = machine; + _reconnectionMachineConfig = config; + + ApplicationManager.SetConnectedMachine(machine); + machine.SessionClosed -= Machine_SessionClosed; + machine.SessionClosed += Machine_SessionClosed; + PostMessage(new MachineConnectionChangedMessage() { Machine = machine }); + + //if (x.UploadHardwareConfiguration) + //{ + // UploadHardwareConfiguration(false); + //} + + } + catch (ResponseErrorException ex) + { + LogManager.Log(ex); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Container.ErrorMessage); + } + catch (Exception ex) + { + LogManager.Log(ex); + _notificationProvider.ShowError("Could not connect to the selected machine." + Environment.NewLine + ex.Message); + } + + InvalidateRelayCommands(); + } + } + + private void ConnectToMachineSecure(IExternalBridgeSecureClient machine) + { + //Check machine exist on my database first + if (machine.Machine == null) + { + _notificationProvider.ShowError($"The specified machine '{machine.SerialNumber}' could not be found on the database. Aborting connection."); + return; + } + + _notificationProvider.ShowModalDialog<MachineLoginViewVM>((login) => + { + ConnectToMachineSecure(machine, login); + }); + } + + private void Machine_SessionClosed(object sender, EventArgs e) + { + InvokeUI(() => + { + _notificationProvider.ShowError("The remote machine has closed the current session. Machine disconnected."); + ApplicationManager.SetConnectedMachine(null); + }); + } + private async void UploadHardwareConfiguration(bool showSuccessMessage = true) { try @@ -667,7 +711,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Starts the specified module. /// </summary> /// <param name="module">The module.</param> - internal void StartModule(IStudioModule module) + internal async void StartModule(IStudioModule module) { IsMenuOpened = false; @@ -692,10 +736,9 @@ namespace Tango.MachineStudio.UI.ViewModels m.IsLoaded = false; } - CurrentModule = module; - if (module != null) { + CurrentModule = module; CurrentModule.IsLoaded = true; IsModuleLoaded = true; @@ -706,7 +749,10 @@ namespace Tango.MachineStudio.UI.ViewModels { IsModuleLoaded = false; LogManager.Log(String.Format("Navigating to Home...")); - (MainView.Self as MainView).NavigationControl.NavigateTo("Home"); + (MainView.Self as MainView).NavigationControl.NavigateTo("Home", () => + { + CurrentModule = module; + }); } } @@ -714,7 +760,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Opens the module in a new window. /// </summary> /// <param name="module">The module.</param> - private void OpenModuleInWindow(IStudioModule module, Rect? bounds = null, WindowState? state = null) + private async void OpenModuleInWindow(IStudioModule module, Rect? bounds = null, WindowState? state = null, bool setHomeModule = true) { if (module == null) return; @@ -722,7 +768,12 @@ namespace Tango.MachineStudio.UI.ViewModels { module.InNewWindow = true; - StartModule(null); + if (setHomeModule) + { + StartModule(null); + } + + await Task.Delay(1000); LogManager.Log(String.Format("Starting module '{0}' in new window...", module.Name)); @@ -918,7 +969,7 @@ namespace Tango.MachineStudio.UI.ViewModels if (module != null && !module.InNewWindow) { - OpenModuleInWindow(module, item.Bounds, item.State); + OpenModuleInWindow(module, item.Bounds, item.State, false); } } 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 2ee8574b1..160041b5f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -179,6 +179,7 @@ namespace Tango.MachineStudio.UI.ViewModels _updateInfo = new CheckForUpdatesResponse(); _updateInfo.BlobAddress = response.BlobAddress; _updateInfo.Version = response.Version; + _updateInfo.CdnAddress = response.CdnAddress; LatestVersion = _updateInfo.Version; StartUpdate(); @@ -270,7 +271,7 @@ namespace Tango.MachineStudio.UI.ViewModels { logManager.Log("Creating temporary file " + tempFile); - using (StorageBlobDownloader downloader = new StorageBlobDownloader(_updateInfo.BlobAddress, tempFile.Path)) + using (AutoFileDownloader downloader = new AutoFileDownloader(_updateInfo.BlobAddress, _updateInfo.CdnAddress, tempFile.Path)) { downloader.Progress += (x, e) => { |
