plugin security fixes and other abstractions

This commit is contained in:
LukePulverenti
2013-02-25 22:43:04 -05:00
parent 364fbb9e0c
commit 2d06095447
79 changed files with 1271 additions and 1388 deletions

View File

@@ -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
@@ -140,12 +137,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>
@@ -176,12 +167,6 @@ namespace MediaBrowser.Common.Kernel
/// <value>The TCP manager.</value>
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.
@@ -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>();
}
@@ -425,18 +395,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>
@@ -445,7 +403,9 @@ namespace MediaBrowser.Common.Kernel
{
if (HasPendingRestart)
{
RestartApplication();
Logger.Info("Restarting the application");
ApplicationHost.Restart();
}
else
{
@@ -453,16 +413,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>
@@ -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,

View File

@@ -21,6 +21,12 @@ namespace MediaBrowser.Common.Kernel
/// </summary>
void ReloadLogger();
/// <summary>
/// Gets the application version.
/// </summary>
/// <value>The application version.</value>
Version ApplicationVersion { get; }
/// <summary>
/// Gets the log file path.
/// </summary>
@@ -33,11 +39,17 @@ namespace MediaBrowser.Common.Kernel
/// <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>
IEnumerable<string> FailedAssemblies { get; }
List<string> FailedAssemblies { get; }
/// <summary>
/// Gets all concrete types.
@@ -72,34 +84,6 @@ namespace MediaBrowser.Common.Kernel
/// <returns>System.Object.</returns>
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>

View File

@@ -37,12 +37,6 @@ namespace MediaBrowser.Common.Kernel
/// <returns>Task.</returns>
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>
@@ -106,12 +100,6 @@ namespace MediaBrowser.Common.Kernel
/// <value>The HTTP server URL prefix.</value>
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>
@@ -139,12 +127,6 @@ namespace MediaBrowser.Common.Kernel
/// </summary>
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>

View File

@@ -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);
}