aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-07-26 13:00:53 -0400
committerLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-07-26 13:00:53 -0400
commit77e81432f7ff49fed71677c4f7b0cb8b4acc92e3 (patch)
tree489586b1ddc1098cc16650cc68da36dc941db4b7
parent8d0fede236af0df9b5e8b63b3b2796e3ffd6c7b1 (diff)
Reworked plugin loading to allow on the fly .dll replacement
-rw-r--r--MediaBrowser.Common/Kernel/BaseKernel.cs11
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs16
2 files changed, 12 insertions, 15 deletions
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs
index cd12c2980..3ff07356b 100644
--- a/MediaBrowser.Common/Kernel/BaseKernel.cs
+++ b/MediaBrowser.Common/Kernel/BaseKernel.cs
@@ -96,8 +96,11 @@ namespace MediaBrowser.Common.Kernel
Directory.CreateDirectory(PluginsPath);
}
- var catalog = new AggregateCatalog(Directory.GetDirectories(PluginsPath, "*", SearchOption.TopDirectoryOnly).Select(f => new DirectoryCatalog(f)));
+ // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
+ // This will prevent the .dll file from getting locked, and allow us to replace it when needed
+ IEnumerable<Assembly> pluginAssemblies = Directory.GetFiles(PluginsPath, "*.dll", SearchOption.AllDirectories).Select(f => Assembly.Load(File.ReadAllBytes((f))));
+ var catalog = new AggregateCatalog(pluginAssemblies.Select(a => new AssemblyCatalog(a)));
//catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
//catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly));
@@ -130,6 +133,12 @@ namespace MediaBrowser.Common.Kernel
{
foreach (BasePlugin plugin in Plugins)
{
+ Assembly assembly = plugin.GetType().Assembly;
+ AssemblyName assemblyName = assembly.GetName();
+
+ plugin.Version = assemblyName.Version;
+ plugin.Path = Path.Combine(PluginsPath, assemblyName.Name);
+
plugin.ReloadConfiguration();
if (plugin.Enabled)
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index 44f880fd2..3e10c4c9c 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -44,21 +44,9 @@ namespace MediaBrowser.Common.Plugins
{
public abstract string Name { get; }
- public string Path
- {
- get
- {
- return System.IO.Path.GetDirectoryName(GetType().Assembly.Location);
- }
- }
+ public string Path { get; set; }
- public Version Version
- {
- get
- {
- return GetType().Assembly.GetName().Version;
- }
- }
+ public Version Version { get; set; }
public BasePluginConfiguration Configuration { get; protected set; }