From 0ea90ef7c62dcdbc68fb250b1066340401c9d450 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sat, 2 Mar 2013 21:47:04 -0500 Subject: added IServerEntryPoint to replace plugin.initialize --- MediaBrowser.Controller/Kernel.cs | 24 +++++++++++++--------- .../MediaBrowser.Controller.csproj | 1 + .../Plugins/IServerEntryPoint.cs | 15 ++++++++++++++ .../Updates/InstallationManager.cs | 6 +++--- 4 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 MediaBrowser.Controller/Plugins/IServerEntryPoint.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 16175783fd..99e0ef783b 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -183,7 +183,7 @@ namespace MediaBrowser.Controller /// /// Composes the parts with ioc container. /// - protected override void FindParts() + protected void FindParts() { // For now there's no real way to inject this properly BaseItem.LibraryManager = ApplicationHost.Resolve(); @@ -194,8 +194,6 @@ namespace MediaBrowser.Controller ProviderManager = (ProviderManager)ApplicationHost.CreateInstance(typeof(ProviderManager)); SecurityManager = (PluginSecurityManager)ApplicationHost.CreateInstance(typeof(PluginSecurityManager)); - base.FindParts(); - UserDataRepositories = ApplicationHost.GetExports(); UserRepositories = ApplicationHost.GetExports(); DisplayPreferencesRepositories = ApplicationHost.GetExports(); @@ -211,15 +209,24 @@ namespace MediaBrowser.Controller /// Performs initializations that can be reloaded at anytime /// /// Task. - protected override async Task ReloadInternal() + protected override async void ReloadInternal() { - await base.ReloadInternal().ConfigureAwait(false); + base.ReloadInternal(); + + FindParts(); + + await LoadRepositories().ConfigureAwait(false); ReloadResourcePools(); ReloadFileSystemManager(); await ApplicationHost.Resolve().RefreshUsersMetadata(CancellationToken.None).ConfigureAwait(false); + + foreach (var entryPoint in ApplicationHost.GetExports()) + { + entryPoint.Run(); + } } /// @@ -263,11 +270,8 @@ namespace MediaBrowser.Controller /// Called when [composable parts loaded]. /// /// Task. - protected override async Task OnComposablePartsLoaded() + protected Task LoadRepositories() { - // The base class will start up all the plugins - await base.OnComposablePartsLoaded().ConfigureAwait(false); - // Get the current item repository ItemRepository = GetRepository(ItemRepositories, Configuration.ItemRepository); var itemRepoTask = ItemRepository.Initialize(); @@ -284,7 +288,7 @@ namespace MediaBrowser.Controller DisplayPreferencesRepository = GetRepository(DisplayPreferencesRepositories, Configuration.DisplayPreferencesRepository); var displayPreferencesRepoTask = DisplayPreferencesRepository.Initialize(); - await Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask, displayPreferencesRepoTask).ConfigureAwait(false); + return Task.WhenAll(itemRepoTask, userRepoTask, userDataRepoTask, displayPreferencesRepoTask); } /// diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 71116881e6..63468a8e80 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -131,6 +131,7 @@ + diff --git a/MediaBrowser.Controller/Plugins/IServerEntryPoint.cs b/MediaBrowser.Controller/Plugins/IServerEntryPoint.cs new file mode 100644 index 0000000000..de6de8f845 --- /dev/null +++ b/MediaBrowser.Controller/Plugins/IServerEntryPoint.cs @@ -0,0 +1,15 @@ +using System; + +namespace MediaBrowser.Controller.Plugins +{ + /// + /// Interface IServerEntryPoint + /// + public interface IServerEntryPoint : IDisposable + { + /// + /// Runs this instance. + /// + void Run(); + } +} diff --git a/MediaBrowser.Controller/Updates/InstallationManager.cs b/MediaBrowser.Controller/Updates/InstallationManager.cs index d616e88984..f67f690aed 100644 --- a/MediaBrowser.Controller/Updates/InstallationManager.cs +++ b/MediaBrowser.Controller/Updates/InstallationManager.cs @@ -287,7 +287,7 @@ namespace MediaBrowser.Controller.Updates { var catalog = await GetAvailablePackages(cancellationToken).ConfigureAwait(false); - var plugins = Kernel.Plugins; + var plugins = ApplicationHost.Plugins; if (withAutoUpdateEnabled) { @@ -424,7 +424,7 @@ namespace MediaBrowser.Controller.Updates if (!(Path.GetExtension(package.targetFilename) ?? "").Equals(".zip", StringComparison.OrdinalIgnoreCase)) { // Set last update time if we were installed before - var plugin = Kernel.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase)); + var plugin = ApplicationHost.Plugins.FirstOrDefault(p => p.Name.Equals(package.name, StringComparison.OrdinalIgnoreCase)); if (plugin != null) { @@ -460,7 +460,7 @@ namespace MediaBrowser.Controller.Updates plugin.OnUninstalling(); // Remove it the quick way for now - Kernel.RemovePlugin(plugin); + ApplicationHost.RemovePlugin(plugin); File.Delete(plugin.AssemblyFilePath); -- cgit v1.2.3