diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-12 02:55:27 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-12 02:55:27 -0400 |
| commit | b50f78e5da6f3fdfc59e577ca61b88771da7d211 (patch) | |
| tree | 644ba93dc04bb8837a19a9cd5c3dfa8c6d62a91d /MediaBrowser.Common/Plugins/BasePlugin.cs | |
Initial check-in
Diffstat (limited to 'MediaBrowser.Common/Plugins/BasePlugin.cs')
| -rw-r--r-- | MediaBrowser.Common/Plugins/BasePlugin.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs new file mode 100644 index 000000000..fb37afa08 --- /dev/null +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -0,0 +1,58 @@ +using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using MediaBrowser.Common.Json;
+
+namespace MediaBrowser.Common.Plugins
+{
+ public abstract class BasePlugin<TConfigurationType> : IDisposable, IPlugin
+ where TConfigurationType : BasePluginConfiguration, new()
+ {
+ public string Path { get; set; }
+ public TConfigurationType Configuration { get; private set; }
+
+ private string ConfigurationPath
+ {
+ get
+ {
+ return System.IO.Path.Combine(Path, "config.js");
+ }
+ }
+
+ public void Init()
+ {
+ Configuration = GetConfiguration();
+
+ if (Configuration.Enabled)
+ {
+ InitInternal();
+ }
+ }
+
+ protected abstract void InitInternal();
+
+ public virtual void Dispose()
+ {
+ }
+
+ private TConfigurationType GetConfiguration()
+ {
+ if (!File.Exists(ConfigurationPath))
+ {
+ return new TConfigurationType();
+ }
+
+ return JsonSerializer.Deserialize<TConfigurationType>(ConfigurationPath);
+ }
+ }
+
+ public interface IPlugin
+ {
+ string Path { get; set; }
+
+ void Init();
+ void Dispose();
+ }
+}
|
