From 0a48b5e31aa712acd988626a88c52c47467945b2 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sat, 21 Jul 2012 14:39:47 -0400 Subject: Added a BaseKernel for the UI and Server to share, and made some other minor re-organizations. --- MediaBrowser.Common/Plugins/PluginController.cs | 38 +++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'MediaBrowser.Common/Plugins/PluginController.cs') diff --git a/MediaBrowser.Common/Plugins/PluginController.cs b/MediaBrowser.Common/Plugins/PluginController.cs index 9ce741ba1..1f83d485b 100644 --- a/MediaBrowser.Common/Plugins/PluginController.cs +++ b/MediaBrowser.Common/Plugins/PluginController.cs @@ -3,23 +3,45 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Threading.Tasks; +using MediaBrowser.Common.Kernel; namespace MediaBrowser.Common.Plugins { + /// + /// Manages Plugins within the PluginsPath directory + /// public class PluginController { public string PluginsPath { get; set; } - public PluginController(string pluginFolderPath) + /// + /// Gets the list of currently loaded plugins + /// + public IEnumerable Plugins { get; private set; } + + /// + /// Initializes the controller + /// + public void Init(KernelContext context) { - PluginsPath = pluginFolderPath; + AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve); + AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); + + Plugins = GetAllPlugins(); + + Parallel.For(0, Plugins.Count(), i => + { + Plugins.ElementAt(i).Init(); + }); } - public IEnumerable GetAllPlugins() + /// + /// Gets all plugins within PluginsPath + /// + /// + private IEnumerable GetAllPlugins() { - AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(CurrentDomain_AssemblyResolve); - AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); - if (!Directory.Exists(PluginsPath)) { Directory.CreateDirectory(PluginsPath); @@ -56,10 +78,10 @@ namespace MediaBrowser.Common.Plugins private IPlugin GetPluginFromDll(string path) { - return FindPlugin(Assembly.Load(File.ReadAllBytes(path))); + return GetPluginFromDll(Assembly.Load(File.ReadAllBytes(path))); } - private IPlugin FindPlugin(Assembly assembly) + private IPlugin GetPluginFromDll(Assembly assembly) { var plugin = assembly.GetTypes().Where(type => typeof(IPlugin).IsAssignableFrom(type)).FirstOrDefault(); -- cgit v1.2.3