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/Modules | |
| 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/Modules')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs index 473e66d38..5951137e3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.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,8 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Tango.Core; +using Tango.Integration.Observables; +using Tango.Logging; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Authentication; using Tango.MachineStudio.Common.Modules; @@ -16,11 +19,21 @@ using Tango.MachineStudio.Stubs; namespace Tango.MachineStudio.UI.Modules { + /// <summary> + /// Represents the Machine Studio default <see cref="IStudioModuleLoader">module loader</see>. + /// </summary> + /// <seealso cref="Tango.Core.ExtendedObject" /> + /// <seealso cref="Tango.MachineStudio.Common.Modules.IStudioModuleLoader" /> public class DefaultStudioModuleLoader : ExtendedObject, IStudioModuleLoader { private IAuthenticationProvider _authenticationProvider; private bool _loaded; + public event EventHandler ModulesLoaded; + /// <summary> + /// Initializes a new instance of the <see cref="DefaultStudioModuleLoader"/> class. + /// </summary> + /// <param name="authenticationProvider">The authentication provider.</param> public DefaultStudioModuleLoader(IAuthenticationProvider authenticationProvider) { _authenticationProvider = authenticationProvider; @@ -29,12 +42,20 @@ namespace Tango.MachineStudio.UI.Modules _authenticationProvider.CurrentUserChanged += _authenticationProvider_CurrentUserChanged; } - private void _authenticationProvider_CurrentUserChanged(object sender, DAL.Observables.User e) + /// <summary> + /// Handles the authentication provider user changed event. + /// </summary> + /// <param name="sender">The sender.</param> + /// <param name="e">The e.</param> + private void _authenticationProvider_CurrentUserChanged(object sender, User e) { LoadModules(); } private ObservableCollection<IStudioModule> _allModules; + /// <summary> + /// Gets all loaded modules. + /// </summary> public ObservableCollection<IStudioModule> AllModules { get { return _allModules; } @@ -42,12 +63,18 @@ namespace Tango.MachineStudio.UI.Modules } private ObservableCollection<IStudioModule> _userModules; + /// <summary> + /// Gets all the user permitted modules. + /// </summary> public ObservableCollection<IStudioModule> UserModules { get { return _userModules; } private set { _userModules = value; RaisePropertyChangedAuto(); } } + /// <summary> + /// Loads all available Machine Studio modules. + /// </summary> public void LoadModules() { if (!_loaded) @@ -70,12 +97,19 @@ namespace Tango.MachineStudio.UI.Modules if (moduleAssembly != null) { - foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IStudioModule).IsAssignableFrom(x))) + foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IStudioModule).IsAssignableFrom(x) && !x.IsAbstract)) { if (!AllModules.ToList().Exists(x => x.GetType() == moduleType)) { - var module = Activator.CreateInstance(moduleType) as IStudioModule; - AllModules.Add(module); + try + { + var module = Activator.CreateInstance(moduleType) as IStudioModule; + AllModules.Add(module); + } + catch (Exception ex) + { + LogManager.Log(ex, "Could not load module " + moduleType.Name); + } } } } @@ -92,6 +126,18 @@ namespace Tango.MachineStudio.UI.Modules { UserModules = AllModules.Where(x => _authenticationProvider.CurrentUser.HasPermission(x.Permission)).ToObservableCollection(); } + + ModulesLoaded?.Invoke(this, new EventArgs()); + } + + /// <summary> + /// Gets the studio module of type T if loaded. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public T GetStudioModule<T>() where T : IStudioModule + { + return UserModules.OfType<T>().FirstOrDefault(); } } } |
