aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Kernel/BaseKernel.cs80
-rw-r--r--MediaBrowser.Common/Kernel/IApplicationHost.cs15
-rw-r--r--MediaBrowser.Common/Kernel/IKernel.cs15
-rw-r--r--MediaBrowser.Common/Plugins/BasePlugin.cs96
-rw-r--r--MediaBrowser.Common/Plugins/IPlugin.cs34
-rw-r--r--MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs2
6 files changed, 45 insertions, 197 deletions
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs
index 78277ed2f..d35ee42c9 100644
--- a/MediaBrowser.Common/Kernel/BaseKernel.cs
+++ b/MediaBrowser.Common/Kernel/BaseKernel.cs
@@ -1,16 +1,13 @@
using MediaBrowser.Common.Events;
-using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.Security;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.System;
using System;
-using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
-using System.Threading.Tasks;
namespace MediaBrowser.Common.Kernel
{
@@ -122,12 +119,6 @@ namespace MediaBrowser.Common.Kernel
public TApplicationPathsType ApplicationPaths { get; private set; }
/// <summary>
- /// Gets the list of currently loaded plugins
- /// </summary>
- /// <value>The plugins.</value>
- public IEnumerable<IPlugin> Plugins { get; protected set; }
-
- /// <summary>
/// Gets or sets the TCP manager.
/// </summary>
/// <value>The TCP manager.</value>
@@ -211,9 +202,9 @@ namespace MediaBrowser.Common.Kernel
/// Initializes the Kernel
/// </summary>
/// <returns>Task.</returns>
- public async Task Init()
+ public void Init()
{
- await ReloadInternal().ConfigureAwait(false);
+ ReloadInternal();
OnReloadCompleted();
@@ -224,65 +215,12 @@ namespace MediaBrowser.Common.Kernel
/// Performs initializations that can be reloaded at anytime
/// </summary>
/// <returns>Task.</returns>
- protected virtual async Task ReloadInternal()
+ protected virtual void ReloadInternal()
{
- // Set these to null so that they can be lazy loaded again
- Configuration = null;
-
- await OnConfigurationLoaded().ConfigureAwait(false);
-
- FindParts();
-
- await OnComposablePartsLoaded().ConfigureAwait(false);
-
ServerManager = ApplicationHost.Resolve<IServerManager>();
}
/// <summary>
- /// Called when [configuration loaded].
- /// </summary>
- /// <returns>Task.</returns>
- protected virtual Task OnConfigurationLoaded()
- {
- return Task.FromResult<object>(null);
- }
-
- /// <summary>
- /// Composes the parts with ioc container.
- /// </summary>
- protected virtual void FindParts()
- {
- Plugins = ApplicationHost.GetExports<IPlugin>();
- }
-
- /// <summary>
- /// Fires after MEF finishes finding composable parts within plugin assemblies
- /// </summary>
- /// <returns>Task.</returns>
- protected virtual Task OnComposablePartsLoaded()
- {
- return Task.Run(() =>
- {
- // Start-up each plugin
- Parallel.ForEach(Plugins, plugin =>
- {
- Logger.Info("Initializing {0} {1}", plugin.Name, plugin.Version);
-
- try
- {
- plugin.Initialize(this, _xmlSerializer, Logger);
-
- Logger.Info("{0} {1} initialized.", plugin.Name, plugin.Version);
- }
- catch (Exception ex)
- {
- Logger.ErrorException("Error initializing {0}", ex, plugin.Name);
- }
- });
- });
- }
-
- /// <summary>
/// Notifies that the kernel that a change has been made that requires a restart
/// </summary>
public void NotifyPendingRestart()
@@ -442,17 +380,5 @@ namespace MediaBrowser.Common.Kernel
/// </summary>
/// <value>The resource pools.</value>
public ResourcePool ResourcePools { get; set; }
-
- /// <summary>
- /// Removes the plugin.
- /// </summary>
- /// <param name="plugin">The plugin.</param>
- public void RemovePlugin(IPlugin plugin)
- {
- var list = Plugins.ToList();
- list.Remove(plugin);
- Plugins = list;
- }
-
}
}
diff --git a/MediaBrowser.Common/Kernel/IApplicationHost.cs b/MediaBrowser.Common/Kernel/IApplicationHost.cs
index bb007ddff..29934988a 100644
--- a/MediaBrowser.Common/Kernel/IApplicationHost.cs
+++ b/MediaBrowser.Common/Kernel/IApplicationHost.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Model.Updates;
+using MediaBrowser.Common.Plugins;
+using MediaBrowser.Model.Updates;
using System;
using System.Collections.Generic;
using System.Threading;
@@ -97,5 +98,17 @@ namespace MediaBrowser.Common.Kernel
/// Shuts down.
/// </summary>
void Shutdown();
+
+ /// <summary>
+ /// Gets the plugins.
+ /// </summary>
+ /// <value>The plugins.</value>
+ IEnumerable<IPlugin> Plugins { get; }
+
+ /// <summary>
+ /// Removes the plugin.
+ /// </summary>
+ /// <param name="plugin">The plugin.</param>
+ void RemovePlugin(IPlugin plugin);
}
}
diff --git a/MediaBrowser.Common/Kernel/IKernel.cs b/MediaBrowser.Common/Kernel/IKernel.cs
index d02f0af20..0d123476c 100644
--- a/MediaBrowser.Common/Kernel/IKernel.cs
+++ b/MediaBrowser.Common/Kernel/IKernel.cs
@@ -40,7 +40,7 @@ namespace MediaBrowser.Common.Kernel
/// Inits this instance.
/// </summary>
/// <returns>Task.</returns>
- Task Init();
+ void Init();
/// <summary>
/// Gets or sets a value indicating whether this instance has pending kernel reload.
@@ -72,12 +72,6 @@ namespace MediaBrowser.Common.Kernel
void PerformPendingRestart();
/// <summary>
- /// Gets the plugins.
- /// </summary>
- /// <value>The plugins.</value>
- IEnumerable<IPlugin> Plugins { get; }
-
- /// <summary>
/// Gets the UDP server port number.
/// </summary>
/// <value>The UDP server port number.</value>
@@ -123,12 +117,5 @@ namespace MediaBrowser.Common.Kernel
/// </summary>
/// <value>The resource pools.</value>
ResourcePool ResourcePools { get; set; }
-
- /// <summary>
- /// Removes the plugin.
- /// </summary>
- /// <param name="plugin">The plugin.</param>
- void RemovePlugin(IPlugin plugin);
-
}
}
diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs
index 0d7c5c060..c968a65c8 100644
--- a/MediaBrowser.Common/Plugins/BasePlugin.cs
+++ b/MediaBrowser.Common/Plugins/BasePlugin.cs
@@ -1,5 +1,4 @@
using MediaBrowser.Common.Kernel;
-using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using System;
@@ -14,7 +13,7 @@ namespace MediaBrowser.Common.Plugins
/// Provides a common base class for all plugins
/// </summary>
/// <typeparam name="TConfigurationType">The type of the T configuration type.</typeparam>
- public abstract class BasePlugin<TConfigurationType> : IDisposable, IPlugin
+ public abstract class BasePlugin<TConfigurationType> : IPlugin
where TConfigurationType : BasePluginConfiguration
{
/// <summary>
@@ -24,6 +23,12 @@ namespace MediaBrowser.Common.Plugins
protected IKernel Kernel { get; private set; }
/// <summary>
+ /// Gets the XML serializer.
+ /// </summary>
+ /// <value>The XML serializer.</value>
+ protected IXmlSerializer XmlSerializer { get; private set; }
+
+ /// <summary>
/// Gets or sets the plugin's current context
/// </summary>
/// <value>The context.</value>
@@ -57,6 +62,12 @@ namespace MediaBrowser.Common.Plugins
}
/// <summary>
+ /// Gets a value indicating whether this instance is first run.
+ /// </summary>
+ /// <value><c>true</c> if this instance is first run; otherwise, <c>false</c>.</value>
+ public bool IsFirstRun { get; private set; }
+
+ /// <summary>
/// Gets the type of configuration this plugin uses
/// </summary>
/// <value>The type of the configuration.</value>
@@ -252,87 +263,14 @@ namespace MediaBrowser.Common.Plugins
}
/// <summary>
- /// Gets the logger.
- /// </summary>
- /// <value>The logger.</value>
- public ILogger Logger { get; private set; }
-
- /// <summary>
- /// Gets the XML serializer.
- /// </summary>
- /// <value>The XML serializer.</value>
- protected IXmlSerializer XmlSerializer { get; private set; }
-
- /// <summary>
- /// Starts the plugin.
+ /// Initializes a new instance of the <see cref="BasePlugin{TConfigurationType}" /> class.
/// </summary>
/// <param name="kernel">The kernel.</param>
/// <param name="xmlSerializer">The XML serializer.</param>
- /// <param name="logger">The logger.</param>
- /// <exception cref="System.ArgumentNullException">kernel</exception>
- public void Initialize(IKernel kernel, IXmlSerializer xmlSerializer, ILogger logger)
+ protected BasePlugin(IKernel kernel, IXmlSerializer xmlSerializer)
{
- if (kernel == null)
- {
- throw new ArgumentNullException("kernel");
- }
-
- if (xmlSerializer == null)
- {
- throw new ArgumentNullException("xmlSerializer");
- }
-
- if (logger == null)
- {
- throw new ArgumentNullException("logger");
- }
-
- XmlSerializer = xmlSerializer;
- Logger = logger;
Kernel = kernel;
-
- if (kernel.KernelContext == KernelContext.Server)
- {
- InitializeOnServer(!File.Exists(ConfigurationFilePath));
- }
- }
-
- /// <summary>
- /// Starts the plugin on the server
- /// </summary>
- /// <param name="isFirstRun">if set to <c>true</c> [is first run].</param>
- protected virtual void InitializeOnServer(bool isFirstRun)
- {
- }
-
- /// <summary>
- /// Disposes the plugins. Undos all actions performed during Init.
- /// </summary>
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources.
- /// </summary>
- /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected void Dispose(bool dispose)
- {
- if (Kernel.KernelContext == KernelContext.Server)
- {
- DisposeOnServer(dispose);
- }
- }
-
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources.
- /// </summary>
- /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected virtual void DisposeOnServer(bool dispose)
- {
-
+ XmlSerializer = xmlSerializer;
}
/// <summary>
@@ -351,8 +289,6 @@ namespace MediaBrowser.Common.Plugins
throw new InvalidOperationException("Cannot call Plugin.SaveConfiguration from the UI.");
}
- Logger.Info("Saving configuration");
-
lock (_configurationSaveLock)
{
XmlSerializer.SerializeToFile(Configuration, ConfigurationFilePath);
diff --git a/MediaBrowser.Common/Plugins/IPlugin.cs b/MediaBrowser.Common/Plugins/IPlugin.cs
index 7d5fddb9a..ace82d83f 100644
--- a/MediaBrowser.Common/Plugins/IPlugin.cs
+++ b/MediaBrowser.Common/Plugins/IPlugin.cs
@@ -1,11 +1,11 @@
-using MediaBrowser.Common.Kernel;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.Model.Plugins;
-using MediaBrowser.Model.Serialization;
+using MediaBrowser.Model.Plugins;
using System;
namespace MediaBrowser.Common.Plugins
{
+ /// <summary>
+ /// Interface IPlugin
+ /// </summary>
public interface IPlugin
{
/// <summary>
@@ -93,26 +93,6 @@ namespace MediaBrowser.Common.Plugins
string DataFolderPath { get; }
/// <summary>
- /// Gets the logger.
- /// </summary>
- /// <value>The logger.</value>
- ILogger Logger { get; }
-
- /// <summary>
- /// Starts the plugin.
- /// </summary>
- /// <param name="kernel">The kernel.</param>
- /// <param name="xmlSerializer">The XML serializer.</param>
- /// <param name="logger">The logger.</param>
- /// <exception cref="System.ArgumentNullException">kernel</exception>
- void Initialize(IKernel kernel, IXmlSerializer xmlSerializer, ILogger logger);
-
- /// <summary>
- /// Disposes the plugins. Undos all actions performed during Init.
- /// </summary>
- void Dispose();
-
- /// <summary>
/// Saves the current configuration to the file system
/// </summary>
/// <exception cref="System.InvalidOperationException">Cannot call Plugin.SaveConfiguration from the UI.</exception>
@@ -136,5 +116,11 @@ namespace MediaBrowser.Common.Plugins
/// Called when just before the plugin is uninstalled from the server.
/// </summary>
void OnUninstalling();
+
+ /// <summary>
+ /// Gets a value indicating whether this instance is first run.
+ /// </summary>
+ /// <value><c>true</c> if this instance is first run; otherwise, <c>false</c>.</value>
+ bool IsFirstRun { get; }
}
} \ No newline at end of file
diff --git a/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs b/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs
index e48551425..6dc5c6b38 100644
--- a/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs
+++ b/MediaBrowser.Common/ScheduledTasks/StartupTrigger.cs
@@ -16,7 +16,7 @@ namespace MediaBrowser.Common.ScheduledTasks
{
if (isApplicationStartup)
{
- await Task.Delay(2000).ConfigureAwait(false);
+ await Task.Delay(3000).ConfigureAwait(false);
OnTriggered();
}