aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultPPCModuleLoader.cs
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultPPCModuleLoader.cs
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d93733d4625ad329b2ba8237f445364b3f.tar.gz
Tango-00a491d93733d4625ad329b2ba8237f445364b3f.zip
merge
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultPPCModuleLoader.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultPPCModuleLoader.cs156
1 files changed, 0 insertions, 156 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultPPCModuleLoader.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultPPCModuleLoader.cs
deleted file mode 100644
index bbabed225..000000000
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Modules/DefaultPPCModuleLoader.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-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.BL.Entities;
-using Tango.Logging;
-using Tango.PPC.Common.Authentication;
-using Tango.PPC.Common.Modules;
-using Tango.PPC.Common;
-using Tango.PPC.Jobs;
-using System.Windows.Data;
-using Tango.Core.DI;
-
-namespace Tango.PPC.UI.Modules
-{
- /// <summary>
- /// Represents the default PPC <see cref="IPPCModuleLoader"></see>.
- /// </summary>
- /// <seealso cref="Tango.Core.ExtendedObject" />
- /// <seealso cref="Tango.PPC.Common.Modules.IPPCModuleLoader" />
- public class DefaultPPCModuleLoader : ExtendedObject, IPPCModuleLoader
- {
- private static object _syncObject = new object();
- private IAuthenticationProvider _authenticationProvider;
- private bool _loaded;
-
- /// <summary>
- /// Occurs when the user has logged in and user modules are loaded.
- /// </summary>
- public event EventHandler ModulesLoaded;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="DefaultPPCModuleLoader"/> class.
- /// </summary>
- /// <param name="authenticationProvider">The authentication provider.</param>
- public DefaultPPCModuleLoader(IAuthenticationProvider authenticationProvider)
- {
- _authenticationProvider = authenticationProvider;
- AllModules = new ObservableCollection<IPPCModule>();
- UserModules = new ObservableCollection<IPPCModule>();
-
- BindingOperations.EnableCollectionSynchronization(UserModules, _syncObject);
-
- _authenticationProvider.CurrentUserChanged += _authenticationProvider_CurrentUserChanged;
- }
-
- /// <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<IPPCModule> _allModules;
- /// <summary>
- /// Gets all loaded modules.
- /// </summary>
- public ObservableCollection<IPPCModule> AllModules
- {
- get { return _allModules; }
- private set { _allModules = value; RaisePropertyChangedAuto(); }
- }
-
- private ObservableCollection<IPPCModule> _userModules;
- /// <summary>
- /// Gets all the user permitted modules.
- /// </summary>
- public ObservableCollection<IPPCModule> UserModules
- {
- get { return _userModules; }
- private set { _userModules = value; RaisePropertyChangedAuto(); }
- }
-
- /// <summary>
- /// Loads all available PPC modules.
- /// </summary>
- public void LoadModules()
- {
- if (!_loaded)
- {
- //Preloaded
- LogManager.Log(String.Format("Loading module '{0}'...", nameof(JobsModule)));
- AllModules.Add(new JobsModule());
- //Preloaded
-
- AllModules.Clear();
- string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
-
- foreach (var file in Directory.GetFiles(assemblyFolder, "*.dll").Where(x => x.Contains("Tango.PPC")))
- {
- try
- {
- Assembly moduleAssembly = null;
- moduleAssembly = Assembly.LoadFrom(file);
-
- if (moduleAssembly != null)
- {
- foreach (var moduleType in moduleAssembly.GetLoadableTypes().Where(x => !x.IsInterface && typeof(IPPCModule).IsAssignableFrom(x) && !x.IsAbstract))
- {
- if (!AllModules.ToList().Exists(x => x.GetType() == moduleType))
- {
- try
- {
- LogManager.Log(String.Format("Loading module '{0}'...", moduleType.Name));
- var module = Activator.CreateInstance(moduleType) as IPPCModule;
- AllModules.Add(module);
- }
- catch (Exception ex)
- {
- LogManager.Log(ex, "Could not load module " + moduleType.Name);
- }
- }
- }
- }
- }
- catch { }
- }
-
- _loaded = true;
- }
-
- AllModules = AllModules.OrderBy(x => x.GetType().GetCustomAttribute<PPCModuleAttribute>().Index).ToObservableCollection();
-
- UserModules.Clear();
-
- if (_authenticationProvider.AuthenticationRequired && _authenticationProvider.CurrentUser != null)
- {
- UserModules = AllModules.Where(x => _authenticationProvider.CurrentUser.HasPermission(x.Permission)).ToObservableCollection();
- }
- else if (!_authenticationProvider.AuthenticationRequired)
- {
- UserModules = AllModules.ToObservableCollection();
- }
-
- ModulesLoaded?.Invoke(this, new EventArgs());
- }
-
- /// <summary>
- /// Gets the PPC module of type T if loaded.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- public T GetPPCModule<T>() where T : IPPCModule
- {
- return UserModules.OfType<T>().FirstOrDefault();
- }
- }
-}