diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-02-20 16:45:00 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-02-20 16:45:00 +0200 |
| commit | 6c208c90bc45aff4a7fa214356a42fe7757c5e6f (patch) | |
| tree | 0d77bc6a0ecfbb53cf42c5462ee19212197ee1bd /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs | |
| parent | b0823127f152fe97a6e8fce29e427c7f3db9cf5a (diff) | |
| parent | 1a573aaa346ec4b8bd58a0e35ab9df571a09b855 (diff) | |
| download | Tango-6c208c90bc45aff4a7fa214356a42fe7757c5e6f.tar.gz Tango-6c208c90bc45aff4a7fa214356a42fe7757c5e6f.zip | |
MERGE
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs | 98 |
1 files changed, 84 insertions, 14 deletions
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 b21b23935..679ba5ff3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -1,4 +1,5 @@ -using System; +using GalaSoft.MvvmLight.Ioc; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -7,6 +8,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; +using Tango.Integration.Services; using Tango.Logging; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Authentication; @@ -22,12 +24,19 @@ using Tango.Transport.Adapters; namespace Tango.MachineStudio.UI.ViewModels { + /// <summary> + /// Represents the Machine Studio main view, view model. + /// </summary> + /// <seealso cref="Tango.SharedUI.ViewModel{Tango.MachineStudio.UI.SupervisingController.IMainView}" /> public class MainViewVM : ViewModel<IMainView> { private IStudioModule _currentModule; private INavigationManager _navigation; private bool _isDisconnecting; + /// <summary> + /// Gets or sets the current loaded module. + /// </summary> public IStudioModule CurrentModule { get { return _currentModule; } @@ -35,33 +44,54 @@ namespace Tango.MachineStudio.UI.ViewModels } private bool _isModuleLoaded; - + /// <summary> + /// Gets or sets a value indicating whether any module is loaded at the moment. + /// </summary> public bool IsModuleLoaded { get { return _isModuleLoaded; } set { _isModuleLoaded = value; RaisePropertyChangedAuto(); } } - private bool _isMenuOpened; - + /// <summary> + /// Gets or sets a value indicating whether the side menu is opened. + /// </summary> public bool IsMenuOpened { get { return _isMenuOpened; } set { _isMenuOpened = value; RaisePropertyChangedAuto(); } } + /// <summary> + /// Gets or sets the start module command. + /// </summary> public RelayCommand<IStudioModule> StartModuleCommand { get; set; } + /// <summary> + /// Gets or sets the home command. + /// </summary> public RelayCommand HomeCommand { get; set; } + /// <summary> + /// Gets or sets the connect command. + /// </summary> public RelayCommand ConnectCommand { get; set; } + /// <summary> + /// Gets or sets the disconnect command. + /// </summary> public RelayCommand DisconnectCommand { get; set; } + /// <summary> + /// Gets or sets the sign-out command. + /// </summary> public RelayCommand SignoutCommand { get; set; } private IAuthenticationProvider _authenticationProvider; + /// <summary> + /// Gets or sets the authentication provider. + /// </summary> public IAuthenticationProvider AuthenticationProvider { get { return _authenticationProvider; } @@ -69,7 +99,9 @@ namespace Tango.MachineStudio.UI.ViewModels } private IStudioModuleLoader _studioModuleLoader; - + /// <summary> + /// Gets or sets the studio module loader. + /// </summary> public IStudioModuleLoader StudioModuleLoader { get { return _studioModuleLoader; } @@ -77,7 +109,9 @@ namespace Tango.MachineStudio.UI.ViewModels } private INotificationProvider _notificationProvider; - + /// <summary> + /// Gets or sets the notification provider. + /// </summary> public INotificationProvider NotificationProvider { get { return _notificationProvider; } @@ -85,15 +119,24 @@ namespace Tango.MachineStudio.UI.ViewModels } private IStudioApplicationManager _applicationManager; - + /// <summary> + /// Gets or sets the application manager. + /// </summary> public IStudioApplicationManager ApplicationManager { get { return _applicationManager; } set { _applicationManager = value; RaisePropertyChangedAuto(); } } - - + /// <summary> + /// Initializes a new instance of the <see cref="MainViewVM"/> class. + /// </summary> + /// <param name="view">The view.</param> + /// <param name="authenticationProvider">The authentication provider.</param> + /// <param name="studioModuleLoader">The studio module loader.</param> + /// <param name="notificationProvider">The notification provider.</param> + /// <param name="applicationManager">The application manager.</param> + /// <param name="navigationManager">The navigation manager.</param> public MainViewVM( IMainView view, IAuthenticationProvider authenticationProvider, @@ -116,6 +159,9 @@ namespace Tango.MachineStudio.UI.ViewModels DisconnectCommand = new RelayCommand(DisconnectFromMachine, (x) => ApplicationManager.IsMachineConnected && !_isDisconnecting); } + /// <summary> + /// Disconnected from the current connected machine. + /// </summary> private async void DisconnectFromMachine() { using (_notificationProvider.PushTaskItem("Disconnecting from machine...")) @@ -129,6 +175,9 @@ namespace Tango.MachineStudio.UI.ViewModels } } + /// <summary> + /// Signs-out the current logged-in user. + /// </summary> private void SignOut() { _authenticationProvider.Logout(); @@ -137,6 +186,9 @@ namespace Tango.MachineStudio.UI.ViewModels IsMenuOpened = false; } + /// <summary> + /// Opens the machine connection dialog to allow the user to scan and connect to remote machines view USB/TCP. + /// </summary> private void ConnectToMachine() { _notificationProvider.ShowModalDialog<MachineConnectionViewVM>(async (x) => @@ -152,17 +204,17 @@ namespace Tango.MachineStudio.UI.ViewModels } } - if (x.SelectedMachine.Type != Integration.Services.ExternalBridgeClientType.USB) + if (x.SelectedMachine.RequiresAuthentication) { _notificationProvider.ShowModalDialog<MachineLoginViewVM>(async (login) => { - using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.SerialNumber + "...")) + using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.ToString() + "...")) { try { await x.SelectedMachine.Connect(); - var authenticated = await x.SelectedMachine.Authenticate(login.Password); + var authenticated = await x.SelectedMachine.As<IExternalBridgeSecureClient>().Authenticate(login.Password); if (!authenticated) { _notificationProvider.ShowError("It seems like you are not authorized to access the selected machine."); @@ -184,7 +236,7 @@ namespace Tango.MachineStudio.UI.ViewModels } else { - using (NotificationProvider.PushTaskItem("Connecting to machine " + x.SelectedMachine.Device + "...")) + using (NotificationProvider.PushTaskItem("Connecting to " + x.SelectedMachine.ToString() + "...")) { try { @@ -208,26 +260,44 @@ namespace Tango.MachineStudio.UI.ViewModels }); } + /// <summary> + /// Navigates to the home screen. + /// </summary> private void Home() { StartModule(null); } - private void StartModule(IStudioModule module) + /// <summary> + /// Starts the specified module. + /// </summary> + /// <param name="module">The module.</param> + internal void StartModule(IStudioModule module) { IsMenuOpened = false; + foreach (var m in StudioModuleLoader.AllModules.Where(x => x != module)) + { + m.IsLoaded = false; + } + if (module != null) { CurrentModule = module; + CurrentModule.IsLoaded = true; IsModuleLoaded = true; + View.NavigateToModule(module); } else { IsModuleLoaded = false; + View.NavigateToModule(null); } } + /// <summary> + /// Called when the <see cref="T:Tango.SharedUI.IView" /> is loaded and attached. + /// </summary> protected override void OnViewAttached() { base.OnViewAttached(); |
