diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs
index e49593779..30a364d7f 100644
--- a/MediaBrowser.Api/ApiService.cs
+++ b/MediaBrowser.Api/ApiService.cs
@@ -29,7 +29,8 @@ namespace MediaBrowser.Api
{
Item = item,
UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id),
- ItemType = item.GetType()
+ Type = item.GetType().Name,
+ IsFolder = (item is Folder)
};
if (includeChildren)
diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs
index ebc2ffcae..b6b1c8095 100644
--- a/MediaBrowser.Api/Plugin.cs
+++ b/MediaBrowser.Api/Plugin.cs
@@ -18,7 +18,7 @@ namespace MediaBrowser.Api
get { return "WebAPI"; }
}
- public override void InitInServer()
+ public override void Init()
{
var httpServer = Kernel.Instance.HttpServer;
diff --git a/MediaBrowser.Common/Configuration/BaseConfiguration.cs b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs
similarity index 79%
rename from MediaBrowser.Common/Configuration/BaseConfiguration.cs
rename to MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs
index fe6c1f278..7ed782bdb 100644
--- a/MediaBrowser.Common/Configuration/BaseConfiguration.cs
+++ b/MediaBrowser.Common/Configuration/BaseApplicationConfiguration.cs
@@ -5,12 +5,12 @@ namespace MediaBrowser.Common.Configuration
///
/// Serves as a common base class for the Server and UI application Configurations
///
- public class BaseConfiguration
+ public class BaseApplicationConfiguration
{
public LogSeverity LogSeverity { get; set; }
public int HttpServerPortNumber { get; set; }
- public BaseConfiguration()
+ public BaseApplicationConfiguration()
{
LogSeverity = LogSeverity.Info;
HttpServerPortNumber = 8096;
diff --git a/MediaBrowser.Common/Json/JsonSerializer.cs b/MediaBrowser.Common/Json/JsonSerializer.cs
index a88233489..b7db1d900 100644
--- a/MediaBrowser.Common/Json/JsonSerializer.cs
+++ b/MediaBrowser.Common/Json/JsonSerializer.cs
@@ -1,5 +1,5 @@
-using System.IO;
-using System;
+using System;
+using System.IO;
namespace MediaBrowser.Common.Json
{
@@ -22,6 +22,16 @@ namespace MediaBrowser.Common.Json
}
}
+ public static object DeserializeFromFile(Type type, string file)
+ {
+ Configure();
+
+ using (Stream stream = File.OpenRead(file))
+ {
+ return ServiceStack.Text.JsonSerializer.DeserializeFromStream(type, stream);
+ }
+ }
+
public static T DeserializeFromFile(string file)
{
Configure();
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs
index 3ff07356b..291c67156 100644
--- a/MediaBrowser.Common/Kernel/BaseKernel.cs
+++ b/MediaBrowser.Common/Kernel/BaseKernel.cs
@@ -18,7 +18,7 @@ namespace MediaBrowser.Common.Kernel
/// Represents a shared base kernel for both the UI and server apps
///
public abstract class BaseKernel
- where TConfigurationType : BaseConfiguration, new()
+ where TConfigurationType : BaseApplicationConfiguration, new()
{
///
/// Gets the path to the program data folder
@@ -139,18 +139,13 @@ namespace MediaBrowser.Common.Kernel
plugin.Version = assemblyName.Version;
plugin.Path = Path.Combine(PluginsPath, assemblyName.Name);
+ plugin.Context = KernelContext;
+
plugin.ReloadConfiguration();
if (plugin.Enabled)
{
- if (KernelContext == KernelContext.Server)
- {
- plugin.InitInServer();
- }
- else
- {
- plugin.InitInUI();
- }
+ plugin.Init();
}
}
}
diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj
index 26c850d5f..65c001889 100644
--- a/MediaBrowser.Common/MediaBrowser.Common.csproj
+++ b/MediaBrowser.Common/MediaBrowser.Common.csproj
@@ -48,7 +48,7 @@
-
+
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index 3e10c4c9c..61ecffc75 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -2,6 +2,7 @@
using System.IO;
using MediaBrowser.Common.Json;
using MediaBrowser.Model.Plugins;
+using MediaBrowser.Common.Kernel;
namespace MediaBrowser.Common.Plugins
{
@@ -23,31 +24,45 @@ namespace MediaBrowser.Common.Plugins
}
}
- public override void ReloadConfiguration()
+ protected override Type ConfigurationType
{
- if (!File.Exists(ConfigurationPath))
- {
- Configuration = new TConfigurationType();
- }
- else
- {
- Configuration = JsonSerializer.DeserializeFromFile(ConfigurationPath);
- Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationPath);
- }
+ get { return typeof(TConfigurationType); }
}
}
///
/// Provides a common base class for all plugins
///
- public abstract class BasePlugin
+ public abstract class BasePlugin : IDisposable
{
+ ///
+ /// Gets or sets the plugin's current context
+ ///
+ public KernelContext Context { get; set; }
+
+ ///
+ /// Gets the name of the plugin
+ ///
public abstract string Name { get; }
+ ///
+ /// Gets the type of configuration this plugin uses
+ ///
+ protected abstract Type ConfigurationType { get; }
+
+ ///
+ /// Gets or sets the path to the plugin's folder
+ ///
public string Path { get; set; }
+ ///
+ /// Gets or sets the plugin version
+ ///
public Version Version { get; set; }
+ ///
+ /// Gets or sets the current plugin configuration
+ ///
public BasePluginConfiguration Configuration { get; protected set; }
protected string ConfigurationPath
@@ -85,15 +100,31 @@ namespace MediaBrowser.Common.Plugins
}
}
- public abstract void ReloadConfiguration();
+ public void ReloadConfiguration()
+ {
+ if (!File.Exists(ConfigurationPath))
+ {
+ Configuration = Activator.CreateInstance(ConfigurationType) as BasePluginConfiguration;
+ }
+ else
+ {
+ Configuration = JsonSerializer.DeserializeFromFile(ConfigurationType, ConfigurationPath) as BasePluginConfiguration;
+ Configuration.DateLastModified = File.GetLastWriteTime(ConfigurationPath);
+ }
+ }
- public virtual void InitInServer()
+ ///
+ /// Starts the plugin.
+ ///
+ public virtual void Init()
{
}
- public virtual void InitInUI()
+ ///
+ /// Disposes the plugins. Undos all actions performed during Init.
+ ///
+ public virtual void Dispose()
{
}
-
}
}
diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs
index 818c69eed..56f3a854f 100644
--- a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs
+++ b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs
@@ -4,7 +4,7 @@ using MediaBrowser.Model.Configuration;
namespace MediaBrowser.Controller.Configuration
{
- public class ServerConfiguration : BaseConfiguration
+ public class ServerConfiguration : BaseApplicationConfiguration
{
public string ImagesByNamePath { get; set; }
diff --git a/MediaBrowser.HtmlBrowser/Plugin.cs b/MediaBrowser.HtmlBrowser/Plugin.cs
index 815423480..b5ec26e06 100644
--- a/MediaBrowser.HtmlBrowser/Plugin.cs
+++ b/MediaBrowser.HtmlBrowser/Plugin.cs
@@ -13,7 +13,7 @@ namespace MediaBrowser.HtmlBrowser
get { return "Html Library Browser"; }
}
- public override void InitInServer()
+ public override void Init()
{
var httpServer = Kernel.Instance.HttpServer;
diff --git a/MediaBrowser.Model/Entities/ApiBaseItem.cs b/MediaBrowser.Model/Entities/ApiBaseItem.cs
index bdab9239a..665a2f6c6 100644
--- a/MediaBrowser.Model/Entities/ApiBaseItem.cs
+++ b/MediaBrowser.Model/Entities/ApiBaseItem.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
+using System.Collections.Generic;
using MediaBrowser.Model.Users;
namespace MediaBrowser.Model.Entities
@@ -25,15 +23,8 @@ namespace MediaBrowser.Model.Entities
public IEnumerable> Children { get; set; }
- [IgnoreDataMember]
- public Type ItemType { get; set; }
+ public bool IsFolder { get; set; }
- public string Type
- {
- get
- {
- return ItemType.Name;
- }
- }
+ public string Type { get; set; }
}
}
diff --git a/MediaBrowser.TV/Plugin.cs b/MediaBrowser.TV/Plugin.cs
index ecc5a17f1..bf03b473d 100644
--- a/MediaBrowser.TV/Plugin.cs
+++ b/MediaBrowser.TV/Plugin.cs
@@ -16,11 +16,16 @@ namespace MediaBrowser.TV
get { return "TV"; }
}
- public override void InitInServer()
+ public override void Init()
{
Kernel.Instance.ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath;
}
+ public override void Dispose()
+ {
+ Kernel.Instance.ItemController.PreBeginResolvePath -= ItemController_PreBeginResolvePath;
+ }
+
void ItemController_PreBeginResolvePath(object sender, PreBeginResolveEventArgs e)
{
if (e.IsFolder && System.IO.Path.GetFileName(e.Path).Equals("metadata", StringComparison.OrdinalIgnoreCase))