diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-26 10:55:44 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-08-26 10:55:44 +0300 |
| commit | 6e2fbaffeec9d6e3518ea9706eea107a4f1b348c (patch) | |
| tree | f50b3d8962dd37188061f8f52c1a7aeff1642232 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels | |
| parent | db3dc558ec5fe5f3584081795865cd22f912da7d (diff) | |
| parent | e6704dce7a2b7f6d5f9bbf1b8374cc7f00ea061e (diff) | |
| download | Tango-6e2fbaffeec9d6e3518ea9706eea107a4f1b348c.tar.gz Tango-6e2fbaffeec9d6e3518ea9706eea107a4f1b348c.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels')
5 files changed, 63 insertions, 31 deletions
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 a468dc2e7..215f7afb5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoadingViewVM.cs @@ -28,7 +28,7 @@ namespace Tango.MachineStudio.UI.ViewModels /// Represents the Machine Studio loading view, view model. /// </summary> /// <seealso cref="Tango.SharedUI.ViewModel" /> - public class LoadingViewVM : StudioViewModelInternal + public class LoadingViewVM : StudioViewModel { private INotificationProvider _notificationProvider; private TeamFoundationServiceExtendedClient _tfs; @@ -141,7 +141,7 @@ namespace Tango.MachineStudio.UI.ViewModels Status = "Loading, please wait..."; - ObservablesEntitiesAdapter.Instance.Initialize(); + ObservablesStaticCollections.Instance.Initialize(); _eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); @@ -172,5 +172,10 @@ namespace Tango.MachineStudio.UI.ViewModels } }); } + + public override void OnApplicationReady() + { + + } } } 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 f2a4f1143..a37879a5e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/LoginViewVM.cs @@ -51,6 +51,15 @@ namespace Tango.MachineStudio.UI.ViewModels set { _password = value; RaisePropertyChangedAuto(); } } + private bool _isLogging; + /// <summary> + /// Gets or sets a value indicating whether this instance is logging. + /// </summary> + public bool IsLogging + { + get { return _isLogging; } + set { _isLogging = value; RaisePropertyChangedAuto(); } + } private bool _rememberMe; /// <summary> @@ -81,7 +90,7 @@ namespace Tango.MachineStudio.UI.ViewModels _navigationManager = navigationManager; _authenticationProvider = authenticationProvider; _eventLogger = eventLogger; - LoginCommand = new RelayCommand(Login); + LoginCommand = new RelayCommand(Login,() => !IsLogging); cryptographer = new Rfc2898Cryptographer(); Email = _settings.LastLoginEmail; @@ -100,26 +109,38 @@ namespace Tango.MachineStudio.UI.ViewModels /// <summary> /// Logins the requested user. /// </summary> - private void Login() + private async void Login() { if (Validate()) { try { - _authenticationProvider.Login(Email, Password); - _navigationManager.NavigateTo(NavigationView.MainView); - _settings.LastLoginEmail = Email; - _settings.RememberMe = RememberMe; + IsLogging = true; + InvalidateRelayCommands(); - _settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null; - _settings.Save(); + await Task.Factory.StartNew(() => + { + _authenticationProvider.Login(Email, Password); + _navigationManager.NavigateTo(NavigationView.MainView); + _settings.LastLoginEmail = Email; + _settings.RememberMe = RememberMe; - _eventLogger.Log("User logged in"); + _settings.LastLoginPassword = RememberMe ? cryptographer.Encrypt(Password) : null; + _settings.Save(); + + _eventLogger.Log("User logged in"); + }); } - catch + catch (Exception) { + _notificationProvider.ShowError("Invalid credentials. Please try again."); } + finally + { + IsLogging = false; + InvalidateRelayCommands(); + } } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs index 44cfc6788..db32fe623 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MachineSerialViewVM.cs @@ -29,7 +29,7 @@ namespace Tango.MachineStudio.UI.ViewModels var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>(); - SelectedMachine = ObservablesEntitiesAdapter.Instance.Machines.SingleOrDefault(x => x.SerialNumber == settings.LastVirtualMachineSerialNumber); + SelectedMachine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == settings.LastVirtualMachineSerialNumber); } } } 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 f8320e1f2..ee4435832 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using Tango.BL; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Core.DI; @@ -515,8 +516,14 @@ namespace Tango.MachineStudio.UI.ViewModels catch (Exception ex) { LogManager.Log(ex); - _eventLogger.Log(ex, "Error connecting to machine " + x.SelectedMachine.SerialNumber); + + 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(); @@ -547,8 +554,13 @@ namespace Tango.MachineStudio.UI.ViewModels { try { - var configuration = ApplicationManager.ConnectedMachine.Machine.Configuration; - await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(configuration.HardwareVersion, configuration); + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var config = db.Adapter.GetConfiguration(s => s.Guid == ApplicationManager.ConnectedMachine.Machine.ConfigurationGuid); + var hw = db.Adapter.GetHardwareVersionByMachine(ApplicationManager.ConnectedMachine.Machine.Guid); + + await ApplicationManager.ConnectedMachine.UploadHardwareConfiguration(hw, config); + } NotificationProvider.ShowInfo("Hardware configuration uploaded successfully."); } catch (Exception ex) @@ -623,20 +635,19 @@ namespace Tango.MachineStudio.UI.ViewModels { LogManager.Log(String.Format("Starting module '{0}'...", module.Name)); - if (!(MainView.Self as MainView).TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!(MainView.Self as MainView).NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { LogManager.Log("Module was not initialized. Initializing..."); FrameworkElement view = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(view, module.Name); - (MainView.Self as MainView).TransitionControl.Elements.Add(view); + (MainView.Self as MainView).NavigationControl.Elements.Add(view); } } foreach (var m in StudioModuleLoader.AllModules.Where(x => x != module && !x.InNewWindow)) { m.IsLoaded = false; - TangoIOC.Default.GetModuleViewModels(m).ToList().ForEach(x => x.OnNavigatedFrom()); } if (module != null) @@ -646,15 +657,13 @@ namespace Tango.MachineStudio.UI.ViewModels IsModuleLoaded = true; LogManager.Log(String.Format("Navigating to module '{0}'...", module.Name)); - (MainView.Self as MainView).TransitionControl.NavigateTo(module.Name); - - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(x => x.OnNavigatedTo()); + (MainView.Self as MainView).NavigationControl.NavigateTo(module.Name); } else { IsModuleLoaded = false; LogManager.Log(String.Format("Navigating to Home...")); - (MainView.Self as MainView).TransitionControl.NavigateTo("Home"); + (MainView.Self as MainView).NavigationControl.NavigateTo("Home"); } } @@ -674,16 +683,16 @@ namespace Tango.MachineStudio.UI.ViewModels LogManager.Log(String.Format("Starting module '{0}' in new window...", module.Name)); - if (!(MainView.Self as MainView).TransitionControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) + if (!(MainView.Self as MainView).NavigationControl.Elements.ToList().Exists(x => x.GetType() == module.MainViewType)) { LogManager.Log("Module was not initialized. Initializing..."); FrameworkElement v = Activator.CreateInstance(module.MainViewType) as FrameworkElement; NavigationControl.SetNavigationName(v, module.Name); - (MainView.Self as MainView).TransitionControl.Elements.Add(v); + (MainView.Self as MainView).NavigationControl.Elements.Add(v); } LogManager.Log("Detaching module view..."); - var view = (MainView.Self as MainView).TransitionControl.GetAndDetach(module.Name); + var view = (MainView.Self as MainView).NavigationControl.GetAndDetach(module.Name); ModuleWindowVM vm = new ModuleWindowVM(module); ModuleWindow window = new ModuleWindow(this, vm, view); @@ -694,7 +703,6 @@ namespace Tango.MachineStudio.UI.ViewModels window.grid.Children.Remove(view); module.InNewWindow = false; - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(v => v.OnNavigatedFrom()); }; window.Owner = MainWindow.Instance; @@ -702,8 +710,6 @@ namespace Tango.MachineStudio.UI.ViewModels LogManager.Log("Opening new window..."); window.Show(); - TangoIOC.Default.GetModuleViewModels(module).ToList().ForEach(x => x.OnNavigatedTo()); - (_applicationManager as DefaultStudioApplicationManager).RegisterOpenedWindow(window); } catch (Exception ex) 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 f2550c598..c5831f701 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/UpdateViewVM.cs @@ -319,9 +319,9 @@ namespace Tango.MachineStudio.UI.ViewModels try { Process p = new Process(); - p.StartInfo.FileName = _appPath + "\\Tango.MachineStudio.Updater.exe"; + p.StartInfo.FileName = _newPackageTempFolder + "\\Tango.MachineStudio.Updater.exe"; p.StartInfo.UseShellExecute = true; - p.StartInfo.Arguments = _newPackageTempFolder; + p.StartInfo.Arguments = _appPath; p.Start(); } catch (Exception ex) |
