diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-25 22:43:04 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-25 22:43:04 -0500 |
| commit | 2d06095447b972c8c7239277428e2c67c8b7ca86 (patch) | |
| tree | 14278bd4c0732ee962b73ff4845e5022e157a0a3 /MediaBrowser.Common/Kernel | |
| parent | 364fbb9e0c7586afa296ddd7d739df086f4c3533 (diff) | |
plugin security fixes and other abstractions
Diffstat (limited to 'MediaBrowser.Common/Kernel')
| -rw-r--r-- | MediaBrowser.Common/Kernel/BaseKernel.cs | 60 | ||||
| -rw-r--r-- | MediaBrowser.Common/Kernel/IApplicationHost.cs | 42 | ||||
| -rw-r--r-- | MediaBrowser.Common/Kernel/IKernel.cs | 18 | ||||
| -rw-r--r-- | MediaBrowser.Common/Kernel/TcpManager.cs | 6 |
4 files changed, 21 insertions, 105 deletions
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index eb5381e20..5b8da5d09 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -40,9 +40,6 @@ namespace MediaBrowser.Common.Kernel internal void OnConfigurationUpdated() { EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger); - - // Notify connected clients - TcpManager.SendWebSocketMessage("ConfigurationUpdated", Configuration); } #endregion @@ -141,12 +138,6 @@ namespace MediaBrowser.Common.Kernel } /// <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 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> @@ -177,12 +168,6 @@ namespace MediaBrowser.Common.Kernel public TcpManager TcpManager { get; private set; } /// <summary> - /// Gets the rest services. - /// </summary> - /// <value>The rest services.</value> - public IEnumerable<IRestfulService> RestServices { get; private 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> @@ -280,19 +265,7 @@ namespace MediaBrowser.Common.Kernel /// Initializes the Kernel /// </summary> /// <returns>Task.</returns> - public Task Init() - { - IsFirstRun = !File.Exists(ApplicationPaths.SystemConfigurationFilePath); - - // Performs initializations that can be reloaded at anytime - return Reload(); - } - - /// <summary> - /// Performs initializations that can be reloaded at anytime - /// </summary> - /// <returns>Task.</returns> - public async Task Reload() + public async Task Init() { OnReloadBeginning(); @@ -312,8 +285,6 @@ namespace MediaBrowser.Common.Kernel // Set these to null so that they can be lazy loaded again Configuration = null; - Logger.Info("Version {0} initializing", ApplicationVersion); - await OnConfigurationLoaded().ConfigureAwait(false); FindParts(); @@ -348,7 +319,6 @@ namespace MediaBrowser.Common.Kernel /// </summary> protected virtual void FindParts() { - RestServices = ApplicationHost.GetExports<IRestfulService>(); WebSocketListeners = ApplicationHost.GetExports<IWebSocketListener>(); Plugins = ApplicationHost.GetExports<IPlugin>(); } @@ -426,18 +396,6 @@ namespace MediaBrowser.Common.Kernel } /// <summary> - /// Gets the current application version - /// </summary> - /// <value>The application version.</value> - public Version ApplicationVersion - { - get - { - return GetType().Assembly.GetName().Version; - } - } - - /// <summary> /// Performs the pending restart. /// </summary> /// <returns>Task.</returns> @@ -445,7 +403,9 @@ namespace MediaBrowser.Common.Kernel { if (HasPendingRestart) { - RestartApplication(); + Logger.Info("Restarting the application"); + + ApplicationHost.Restart(); } else { @@ -454,16 +414,6 @@ namespace MediaBrowser.Common.Kernel } /// <summary> - /// Restarts the application. - /// </summary> - protected void RestartApplication() - { - Logger.Info("Restarting the application"); - - ApplicationHost.Restart(); - } - - /// <summary> /// Gets the system status. /// </summary> /// <returns>SystemInfo.</returns> @@ -472,7 +422,7 @@ namespace MediaBrowser.Common.Kernel return new SystemInfo { HasPendingRestart = HasPendingRestart, - Version = ApplicationVersion.ToString(), + Version = ApplicationHost.ApplicationVersion.ToString(), IsNetworkDeployed = ApplicationHost.CanSelfUpdate, WebSocketPortNumber = TcpManager.WebSocketPortNumber, SupportsNativeWebSocket = TcpManager.SupportsNativeWebSocket, diff --git a/MediaBrowser.Common/Kernel/IApplicationHost.cs b/MediaBrowser.Common/Kernel/IApplicationHost.cs index 4b564581b..af9b039bc 100644 --- a/MediaBrowser.Common/Kernel/IApplicationHost.cs +++ b/MediaBrowser.Common/Kernel/IApplicationHost.cs @@ -22,6 +22,12 @@ namespace MediaBrowser.Common.Kernel void ReloadLogger(); /// <summary> + /// Gets the application version. + /// </summary> + /// <value>The application version.</value> + Version ApplicationVersion { get; } + + /// <summary> /// Gets the log file path. /// </summary> /// <value>The log file path.</value> @@ -34,10 +40,16 @@ namespace MediaBrowser.Common.Kernel 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> - IEnumerable<string> FailedAssemblies { get; } + List<string> FailedAssemblies { get; } /// <summary> /// Gets all concrete types. @@ -73,34 +85,6 @@ namespace MediaBrowser.Common.Kernel object CreateInstance(Type type); /// <summary> - /// Registers a service that other classes can use as a dependancy. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="obj">The obj.</param> - void RegisterSingleInstance<T>(T obj) where T : class; - - /// <summary> - /// Registers the single instance. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="func">The func.</param> - void RegisterSingleInstance<T>(Func<T> func) where T : class; - - /// <summary> - /// Registers the specified func. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="func">The func.</param> - void Register<T>(Func<T> func) where T : class; - - /// <summary> - /// Registers the specified service type. - /// </summary> - /// <param name="serviceType">Type of the service.</param> - /// <param name="implementation">Type of the implementation.</param> - void Register(Type serviceType, Type implementation); - - /// <summary> /// Resolves this instance. /// </summary> /// <typeparam name="T"></typeparam> diff --git a/MediaBrowser.Common/Kernel/IKernel.cs b/MediaBrowser.Common/Kernel/IKernel.cs index fb629a24d..06c2e7b64 100644 --- a/MediaBrowser.Common/Kernel/IKernel.cs +++ b/MediaBrowser.Common/Kernel/IKernel.cs @@ -38,12 +38,6 @@ namespace MediaBrowser.Common.Kernel Task Init(); /// <summary> - /// Reloads this instance. - /// </summary> - /// <returns>Task.</returns> - Task Reload(); - - /// <summary> /// Gets or sets a value indicating whether this instance has pending kernel reload. /// </summary> /// <value><c>true</c> if this instance has pending kernel reload; otherwise, <c>false</c>.</value> @@ -107,12 +101,6 @@ namespace MediaBrowser.Common.Kernel string HttpServerUrlPrefix { 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 TCP manager. /// </summary> /// <value>The TCP manager.</value> @@ -140,12 +128,6 @@ namespace MediaBrowser.Common.Kernel event EventHandler<EventArgs> ConfigurationUpdated; /// <summary> - /// Gets the rest services. - /// </summary> - /// <value>The rest services.</value> - IEnumerable<IRestfulService> RestServices { get; } - - /// <summary> /// Notifies the pending restart. /// </summary> void NotifyPendingRestart(); diff --git a/MediaBrowser.Common/Kernel/TcpManager.cs b/MediaBrowser.Common/Kernel/TcpManager.cs index 1c76b42f9..2dfed501a 100644 --- a/MediaBrowser.Common/Kernel/TcpManager.cs +++ b/MediaBrowser.Common/Kernel/TcpManager.cs @@ -39,7 +39,7 @@ namespace MediaBrowser.Common.Kernel /// </summary> /// <value>The json serializer.</value> private readonly IJsonSerializer _jsonSerializer; - + /// <summary> /// This subscribes to HttpListener requests and finds the appropriate BaseHandler to process it /// </summary> @@ -133,7 +133,7 @@ namespace MediaBrowser.Common.Kernel _applicationHost = applicationHost; _networkManager = networkManager; - if (kernel.IsFirstRun) + if (applicationHost.IsFirstRun) { RegisterServerWithAdministratorAccess(); } @@ -215,7 +215,7 @@ namespace MediaBrowser.Common.Kernel /// <param name="e">The <see cref="WebSocketConnectEventArgs" /> instance containing the event data.</param> void HttpServer_WebSocketConnected(object sender, WebSocketConnectEventArgs e) { - var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, ProcessWebSocketMessageReceived, _jsonSerializer, _logger); + var connection = new WebSocketConnection(e.WebSocket, e.Endpoint, _jsonSerializer, _logger) { OnReceive = ProcessWebSocketMessageReceived }; _webSocketConnections.Add(connection); } |
