aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common/Kernel')
-rw-r--r--MediaBrowser.Common/Kernel/BaseKernel.cs225
-rw-r--r--MediaBrowser.Common/Kernel/IApplicationHost.cs120
-rw-r--r--MediaBrowser.Common/Kernel/IApplicationPaths.cs82
-rw-r--r--MediaBrowser.Common/Kernel/IKernel.cs46
4 files changed, 14 insertions, 459 deletions
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs
index 489423d9e..cf8133e97 100644
--- a/MediaBrowser.Common/Kernel/BaseKernel.cs
+++ b/MediaBrowser.Common/Kernel/BaseKernel.cs
@@ -1,45 +1,21 @@
-using MediaBrowser.Common.Events;
-using MediaBrowser.Common.Security;
-using MediaBrowser.Model.Configuration;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Events;
using MediaBrowser.Model.Logging;
-using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.System;
using System;
-using System.IO;
-using System.Linq;
-using System.Threading;
namespace MediaBrowser.Common.Kernel
{
/// <summary>
/// Represents a shared base kernel for both the Ui and server apps
/// </summary>
- /// <typeparam name="TConfigurationType">The type of the T configuration type.</typeparam>
- /// <typeparam name="TApplicationPathsType">The type of the T application paths type.</typeparam>
- public abstract class BaseKernel<TConfigurationType, TApplicationPathsType> : IDisposable, IKernel
- where TConfigurationType : BaseApplicationConfiguration, new()
- where TApplicationPathsType : IApplicationPaths
+ public abstract class BaseKernel : IKernel
{
/// <summary>
/// Occurs when [has pending restart changed].
/// </summary>
public event EventHandler HasPendingRestartChanged;
- #region ConfigurationUpdated Event
- /// <summary>
- /// Occurs when [configuration updated].
- /// </summary>
- public event EventHandler<EventArgs> ConfigurationUpdated;
-
- /// <summary>
- /// Called when [configuration updated].
- /// </summary>
- internal void OnConfigurationUpdated()
- {
- EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger);
- }
- #endregion
-
#region ApplicationUpdated Event
/// <summary>
/// Occurs when [application updated].
@@ -58,65 +34,12 @@ namespace MediaBrowser.Common.Kernel
#endregion
/// <summary>
- /// The _configuration loaded
- /// </summary>
- private bool _configurationLoaded;
- /// <summary>
- /// The _configuration sync lock
- /// </summary>
- private object _configurationSyncLock = new object();
- /// <summary>
- /// The _configuration
- /// </summary>
- private TConfigurationType _configuration;
- /// <summary>
- /// Gets the system configuration
- /// </summary>
- /// <value>The configuration.</value>
- public TConfigurationType Configuration
- {
- get
- {
- // Lazy load
- LazyInitializer.EnsureInitialized(ref _configuration, ref _configurationLoaded, ref _configurationSyncLock, () => GetXmlConfiguration<TConfigurationType>(ApplicationPaths.SystemConfigurationFilePath));
- return _configuration;
- }
- protected set
- {
- _configuration = value;
-
- if (value == null)
- {
- _configurationLoaded = false;
- }
- }
- }
-
- /// <summary>
/// Gets or sets a value indicating whether this instance has changes that require the entire application to restart.
/// </summary>
/// <value><c>true</c> if this instance has pending application restart; otherwise, <c>false</c>.</value>
public bool HasPendingRestart { get; private set; }
/// <summary>
- /// Gets the application paths.
- /// </summary>
- /// <value>The application paths.</value>
- public TApplicationPathsType ApplicationPaths { get; private set; }
-
- /// <summary>
- /// Gets or sets the TCP manager.
- /// </summary>
- /// <value>The TCP manager.</value>
- private IServerManager ServerManager { get; set; }
-
- /// <summary>
- /// Gets the plug-in security manager.
- /// </summary>
- /// <value>The plug-in security manager.</value>
- public ISecurityManager SecurityManager { get; set; }
-
- /// <summary>
/// Gets the UDP server port number.
/// This can't be configurable because then the user would have to configure their client to discover the server.
/// </summary>
@@ -141,7 +64,7 @@ namespace MediaBrowser.Common.Kernel
{
get
{
- return "http://+:" + Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/";
+ return "http://+:" + _configurationManager.CommonConfiguration.HttpServerPortNumber + "/" + WebApplicationName + "/";
}
}
@@ -163,25 +86,18 @@ namespace MediaBrowser.Common.Kernel
/// <value>The application host.</value>
protected IApplicationHost ApplicationHost { get; private set; }
- /// <summary>
- /// The _XML serializer
- /// </summary>
- private readonly IXmlSerializer _xmlSerializer;
+ private readonly IConfigurationManager _configurationManager;
/// <summary>
- /// Initializes a new instance of the <see cref="BaseKernel{TApplicationPathsType}" /> class.
+ /// Initializes a new instance of the <see cref="BaseKernel" /> class.
/// </summary>
/// <param name="appHost">The app host.</param>
- /// <param name="appPaths">The app paths.</param>
- /// <param name="xmlSerializer">The XML serializer.</param>
- /// <param name="logger">The logger.</param>
- /// <exception cref="System.ArgumentNullException">isoManager</exception>
- protected BaseKernel(IApplicationHost appHost, TApplicationPathsType appPaths, IXmlSerializer xmlSerializer, ILogger logger)
+ /// <param name="logManager">The log manager.</param>
+ protected BaseKernel(IApplicationHost appHost, ILogManager logManager, IConfigurationManager configurationManager)
{
- ApplicationPaths = appPaths;
ApplicationHost = appHost;
- _xmlSerializer = xmlSerializer;
- Logger = logger;
+ _configurationManager = configurationManager;
+ Logger = logManager.GetLogger("Kernel");
}
/// <summary>
@@ -201,7 +117,6 @@ namespace MediaBrowser.Common.Kernel
/// <returns>Task.</returns>
protected virtual void ReloadInternal()
{
- ServerManager = ApplicationHost.Resolve<IServerManager>();
}
/// <summary>
@@ -215,24 +130,6 @@ namespace MediaBrowser.Common.Kernel
}
/// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- /// </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 virtual void Dispose(bool dispose)
- {
-
- }
-
- /// <summary>
/// Performs the pending restart.
/// </summary>
/// <returns>Task.</returns>
@@ -261,108 +158,10 @@ namespace MediaBrowser.Common.Kernel
HasPendingRestart = HasPendingRestart,
Version = ApplicationHost.ApplicationVersion.ToString(),
IsNetworkDeployed = ApplicationHost.CanSelfUpdate,
- WebSocketPortNumber = ServerManager.WebSocketPortNumber,
- SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket,
+ WebSocketPortNumber = ApplicationHost.Resolve<IServerManager>().WebSocketPortNumber,
+ SupportsNativeWebSocket = ApplicationHost.Resolve<IServerManager>().SupportsNativeWebSocket,
FailedPluginAssemblies = ApplicationHost.FailedAssemblies.ToArray()
};
}
-
- /// <summary>
- /// The _save lock
- /// </summary>
- private readonly object _configurationSaveLock = new object();
-
- /// <summary>
- /// Saves the current configuration
- /// </summary>
- public void SaveConfiguration()
- {
- lock (_configurationSaveLock)
- {
- _xmlSerializer.SerializeToFile(Configuration, ApplicationPaths.SystemConfigurationFilePath);
- }
-
- OnConfigurationUpdated();
- }
-
- /// <summary>
- /// Gets the application paths.
- /// </summary>
- /// <value>The application paths.</value>
- IApplicationPaths IKernel.ApplicationPaths
- {
- get { return ApplicationPaths; }
- }
- /// <summary>
- /// Gets the configuration.
- /// </summary>
- /// <value>The configuration.</value>
- BaseApplicationConfiguration IKernel.Configuration
- {
- get { return Configuration; }
- }
-
- /// <summary>
- /// Reads an xml configuration file from the file system
- /// It will immediately re-serialize and save if new serialization data is available due to property changes
- /// </summary>
- /// <param name="type">The type.</param>
- /// <param name="path">The path.</param>
- /// <returns>System.Object.</returns>
- public object GetXmlConfiguration(Type type, string path)
- {
- Logger.Info("Loading {0} at {1}", type.Name, path);
-
- object configuration;
-
- byte[] buffer = null;
-
- // Use try/catch to avoid the extra file system lookup using File.Exists
- try
- {
- buffer = File.ReadAllBytes(path);
-
- configuration = _xmlSerializer.DeserializeFromBytes(type, buffer);
- }
- catch (FileNotFoundException)
- {
- configuration = Activator.CreateInstance(type);
- }
-
- // Take the object we just got and serialize it back to bytes
- var newBytes = _xmlSerializer.SerializeToBytes(configuration);
-
- // If the file didn't exist before, or if something has changed, re-save
- if (buffer == null || !buffer.SequenceEqual(newBytes))
- {
- Logger.Info("Saving {0} to {1}", type.Name, path);
-
- // Save it after load in case we got new items
- File.WriteAllBytes(path, newBytes);
- }
-
- return configuration;
- }
-
-
- /// <summary>
- /// Reads an xml configuration file from the file system
- /// It will immediately save the configuration after loading it, just
- /// in case there are new serializable properties
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="path">The path.</param>
- /// <returns>``0.</returns>
- private T GetXmlConfiguration<T>(string path)
- where T : class
- {
- return GetXmlConfiguration(typeof(T), path) as T;
- }
-
- /// <summary>
- /// Limits simultaneous access to various resources
- /// </summary>
- /// <value>The resource pools.</value>
- public ResourcePool ResourcePools { get; set; }
}
}
diff --git a/MediaBrowser.Common/Kernel/IApplicationHost.cs b/MediaBrowser.Common/Kernel/IApplicationHost.cs
deleted file mode 100644
index 38a1cb318..000000000
--- a/MediaBrowser.Common/Kernel/IApplicationHost.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-using MediaBrowser.Common.Plugins;
-using MediaBrowser.Model.Updates;
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace MediaBrowser.Common.Kernel
-{
- /// <summary>
- /// An interface to be implemented by the applications hosting a kernel
- /// </summary>
- public interface IApplicationHost
- {
- /// <summary>
- /// Restarts this instance.
- /// </summary>
- void Restart();
-
- /// <summary>
- /// Configures the auto run at startup.
- /// </summary>
- /// <param name="autorun">if set to <c>true</c> [autorun].</param>
- void ConfigureAutoRunAtStartup(bool autorun);
-
- /// <summary>
- /// Gets the application version.
- /// </summary>
- /// <value>The application version.</value>
- Version ApplicationVersion { get; }
-
- /// <summary>
- /// Gets or sets a value indicating whether this instance can self update.
- /// </summary>
- /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
- bool CanSelfUpdate { get; }
-
- /// <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; }
-
- /// <summary>
- /// Gets the failed assemblies.
- /// </summary>
- /// <value>The failed assemblies.</value>
- List<string> FailedAssemblies { get; }
-
- /// <summary>
- /// Gets all concrete types.
- /// </summary>
- /// <value>All concrete types.</value>
- Type[] AllConcreteTypes { get; }
-
- /// <summary>
- /// Gets the exports.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="manageLiftime">if set to <c>true</c> [manage liftime].</param>
- /// <returns>IEnumerable{``0}.</returns>
- IEnumerable<T> GetExports<T>(bool manageLiftime = true);
-
- /// <summary>
- /// Checks for update.
- /// </summary>
- /// <returns>Task{CheckForUpdateResult}.</returns>
- Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress);
-
- /// <summary>
- /// Updates the application.
- /// </summary>
- /// <returns>Task.</returns>
- Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress);
-
- /// <summary>
- /// Creates an instance of type and resolves all constructor dependancies
- /// </summary>
- /// <param name="type">The type.</param>
- /// <returns>System.Object.</returns>
- object CreateInstance(Type type);
-
- /// <summary>
- /// Resolves this instance.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns>``0.</returns>
- T Resolve<T>();
-
- /// <summary>
- /// Resolves this instance.
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns>``0.</returns>
- T TryResolve<T>();
-
- /// <summary>
- /// 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);
-
- /// <summary>
- /// Inits this instance.
- /// </summary>
- /// <returns>Task.</returns>
- Task Init();
- }
-}
diff --git a/MediaBrowser.Common/Kernel/IApplicationPaths.cs b/MediaBrowser.Common/Kernel/IApplicationPaths.cs
deleted file mode 100644
index 52c3b199d..000000000
--- a/MediaBrowser.Common/Kernel/IApplicationPaths.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-
-namespace MediaBrowser.Common.Kernel
-{
- /// <summary>
- /// Interface IApplicationPaths
- /// </summary>
- public interface IApplicationPaths
- {
- /// <summary>
- /// Gets the path to the program data folder
- /// </summary>
- /// <value>The program data path.</value>
- string ProgramDataPath { get; }
-
- /// <summary>
- /// Gets the path to the program system folder
- /// </summary>
- /// <value>The program data path.</value>
- string ProgramSystemPath { get; }
-
- /// <summary>
- /// Gets the folder path to the data directory
- /// </summary>
- /// <value>The data directory.</value>
- string DataPath { get; }
-
- /// <summary>
- /// Gets the image cache path.
- /// </summary>
- /// <value>The image cache path.</value>
- string ImageCachePath { get; }
-
- /// <summary>
- /// Gets the path to the plugin directory
- /// </summary>
- /// <value>The plugins path.</value>
- string PluginsPath { get; }
-
- /// <summary>
- /// Gets the path to the plugin configurations directory
- /// </summary>
- /// <value>The plugin configurations path.</value>
- string PluginConfigurationsPath { get; }
-
- /// <summary>
- /// Gets the path to where temporary update files will be stored
- /// </summary>
- /// <value>The plugin configurations path.</value>
- string TempUpdatePath { get; }
-
- /// <summary>
- /// Gets the path to the log directory
- /// </summary>
- /// <value>The log directory path.</value>
- string LogDirectoryPath { get; }
-
- /// <summary>
- /// Gets the path to the application configuration root directory
- /// </summary>
- /// <value>The configuration directory path.</value>
- string ConfigurationDirectoryPath { get; }
-
- /// <summary>
- /// Gets the path to the system configuration file
- /// </summary>
- /// <value>The system configuration file path.</value>
- string SystemConfigurationFilePath { get; }
-
- /// <summary>
- /// Gets the folder path to the cache directory
- /// </summary>
- /// <value>The cache directory.</value>
- string CachePath { get; }
-
- /// <summary>
- /// Gets the folder path to the temp directory within the cache folder
- /// </summary>
- /// <value>The temp directory.</value>
- string TempDirectory { get; }
- }
-
-}
diff --git a/MediaBrowser.Common/Kernel/IKernel.cs b/MediaBrowser.Common/Kernel/IKernel.cs
index 1a2d86d7f..51677677a 100644
--- a/MediaBrowser.Common/Kernel/IKernel.cs
+++ b/MediaBrowser.Common/Kernel/IKernel.cs
@@ -1,17 +1,12 @@
-using MediaBrowser.Common.Plugins;
-using MediaBrowser.Common.Security;
-using MediaBrowser.Model.Configuration;
-using MediaBrowser.Model.System;
+using MediaBrowser.Model.System;
using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
namespace MediaBrowser.Common.Kernel
{
/// <summary>
/// Interface IKernel
/// </summary>
- public interface IKernel : IDisposable
+ public interface IKernel
{
/// <summary>
/// Occurs when [has pending restart changed].
@@ -19,18 +14,6 @@ namespace MediaBrowser.Common.Kernel
event EventHandler HasPendingRestartChanged;
/// <summary>
- /// Gets the application paths.
- /// </summary>
- /// <value>The application paths.</value>
- IApplicationPaths ApplicationPaths { get; }
-
- /// <summary>
- /// Gets the configuration.
- /// </summary>
- /// <value>The configuration.</value>
- BaseApplicationConfiguration Configuration { get; }
-
- /// <summary>
/// Gets the kernel context.
/// </summary>
/// <value>The kernel context.</value>
@@ -84,33 +67,8 @@ namespace MediaBrowser.Common.Kernel
string HttpServerUrlPrefix { get; }
/// <summary>
- /// Gets the plug-in security manager.
- /// </summary>
- /// <value>The plug-in security manager.</value>
- ISecurityManager SecurityManager { get; set; }
-
- /// <summary>
- /// Occurs when [configuration updated].
- /// </summary>
- event EventHandler<EventArgs> ConfigurationUpdated;
-
- /// <summary>
/// Notifies the pending restart.
/// </summary>
void NotifyPendingRestart();
-
- /// <summary>
- /// Gets the XML configuration.
- /// </summary>
- /// <param name="type">The type.</param>
- /// <param name="path">The path.</param>
- /// <returns>System.Object.</returns>
- object GetXmlConfiguration(Type type, string path);
-
- /// <summary>
- /// Limits simultaneous access to various resources
- /// </summary>
- /// <value>The resource pools.</value>
- ResourcePool ResourcePools { get; set; }
}
}