From 507beb76f634eb5d3e84056d9c635bfc9188f41b Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 6 Sep 2012 10:18:54 -0400 Subject: [PATCH] Added context-sensitive init/dispose methods for plugins --- MediaBrowser.Api/Plugin.cs | 2 +- MediaBrowser.Common/Plugins/BasePlugin.cs | 44 ++++++++++++++++++++--- MediaBrowser.TV/Plugin.cs | 4 +-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index 7005b8f8a9..e83f366dfd 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -18,7 +18,7 @@ namespace MediaBrowser.Api get { return "Media Browser API"; } } - protected override void InitializeInternal() + protected override void InitializeOnServer() { var httpServer = Kernel.Instance.HttpServer; diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index 55f0926662..705e15f173 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -184,22 +184,58 @@ namespace MediaBrowser.Common.Plugins if (Enabled) { - InitializeInternal(); + if (kernel.KernelContext == KernelContext.Server) + { + InitializeOnServer(); + } + else if (kernel.KernelContext == KernelContext.UI) + { + InitializeInUI(); + } } } } /// - /// Starts the plugin. + /// Starts the plugin on the server /// - protected virtual void InitializeInternal() + protected virtual void InitializeOnServer() + { + } + + /// + /// Starts the plugin in the UI + /// + protected virtual void InitializeInUI() { } /// /// Disposes the plugins. Undos all actions performed during Init. /// - public virtual void Dispose() + public void Dispose() + { + if (Context == KernelContext.Server) + { + DisposeOnServer(); + } + else if (Context == KernelContext.UI) + { + InitializeInUI(); + } + } + + /// + /// Disposes the plugin on the server + /// + protected virtual void DisposeOnServer() + { + } + + /// + /// Disposes the plugin in the UI + /// + protected virtual void DisposeInUI() { } diff --git a/MediaBrowser.TV/Plugin.cs b/MediaBrowser.TV/Plugin.cs index 75a108b2d0..c4ae87cae4 100644 --- a/MediaBrowser.TV/Plugin.cs +++ b/MediaBrowser.TV/Plugin.cs @@ -16,12 +16,12 @@ namespace MediaBrowser.TV get { return "TV"; } } - protected override void InitializeInternal() + protected override void InitializeOnServer() { Kernel.Instance.ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath; } - public override void Dispose() + protected override void DisposeOnServer() { Kernel.Instance.ItemController.PreBeginResolvePath -= ItemController_PreBeginResolvePath; }