aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-12-14 19:48:41 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-12-14 19:48:41 +0200
commitad35c9c2df0001157ea13312382f3cdfdad67f06 (patch)
tree78c4708893f6207ff692f729ac43408823f963e1 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules
parent7887ca0ad2433c4adbb65d96bf926561405ab290 (diff)
downloadTango-ad35c9c2df0001157ea13312382f3cdfdad67f06.tar.gz
Tango-ad35c9c2df0001157ea13312382f3cdfdad67f06.zip
Implemented IAuthenticationProvider, INavigationProvider, IModuleLoader.
LoadingView, LoginView,
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs85
1 files changed, 85 insertions, 0 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
new file mode 100644
index 000000000..689ac7b38
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Core;
+using Tango.MachineStudio.Common;
+using Tango.MachineStudio.Common.Authentication;
+using Tango.MachineStudio.Common.Modules;
+
+namespace Tango.MachineStudio.UI.Modules
+{
+ public class DefaultStudioModuleLoader : ExtendedObject, IStudioModuleLoader
+ {
+ private IAuthenticationProvider _authenticationProvider;
+ private bool _loaded;
+
+ public DefaultStudioModuleLoader(IAuthenticationProvider authenticationProvider)
+ {
+ _authenticationProvider = authenticationProvider;
+ AllModules = new ObservableCollection<IStudioModule>();
+ UserModules = new ObservableCollection<IStudioModule>();
+ _authenticationProvider.CurrentUserChanged += _authenticationProvider_CurrentUserChanged;
+ }
+
+ private void _authenticationProvider_CurrentUserChanged(object sender, DAL.Observables.User e)
+ {
+ LoadModules();
+ }
+
+ private ObservableCollection<IStudioModule> _allModules;
+ public ObservableCollection<IStudioModule> AllModules
+ {
+ get { return _allModules; }
+ private set { _allModules = value; RaisePropertyChangedAuto(); }
+ }
+
+ private ObservableCollection<IStudioModule> _userModules;
+ public ObservableCollection<IStudioModule> UserModules
+ {
+ get { return _userModules; }
+ private set { _userModules = value; RaisePropertyChangedAuto(); }
+ }
+
+ public void LoadModules()
+ {
+ if (!_loaded)
+ {
+ AllModules.Clear();
+ string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+
+ foreach (var file in Directory.GetFiles(assemblyFolder, "*.dll").Where(x => x.Contains("MachineStudio")))
+ {
+ try
+ {
+ Assembly moduleAssembly = null;
+ moduleAssembly = Assembly.LoadFrom(file);
+
+ if (moduleAssembly != null)
+ {
+ foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IStudioModule).IsAssignableFrom(x)))
+ {
+ var module = Activator.CreateInstance(moduleType) as IStudioModule;
+ AllModules.Add(module);
+ }
+ }
+ }
+ catch { }
+ }
+
+ _loaded = true;
+ }
+
+ UserModules.Clear();
+
+ if (_authenticationProvider.CurrentUser != null)
+ {
+ UserModules = AllModules.Where(x => _authenticationProvider.CurrentUser.HasPermission(x.Permission)).ToObservableCollection();
+ }
+ }
+ }
+}