diff options
| author | Roy <roy.mail.net@gmail.com> | 2018-02-14 22:52:00 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2018-02-14 22:52:00 +0200 |
| commit | d5018576f325fb85983c4ad34c169d4b4e8d1a55 (patch) | |
| tree | 57e83d678e2221083b73a5289b506773868e1c63 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs | |
| parent | b934b152eea671fa06678baa0cdf7f8811e6d2d9 (diff) | |
| parent | b7b277736c7e3ec9258915cdd5a54e7b33ba1123 (diff) | |
| download | Tango-d5018576f325fb85983c4ad34c169d4b4e8d1a55.tar.gz Tango-d5018576f325fb85983c4ad34c169d4b4e8d1a55.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs | 27 |
1 files changed, 23 insertions, 4 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 e08ee9b08..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; @@ -8,6 +9,7 @@ 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; @@ -95,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); + } } } } @@ -120,5 +129,15 @@ namespace Tango.MachineStudio.UI.Modules 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(); + } } } |
