tweaked http server startup

This commit is contained in:
Luke Pulverenti 2013-04-08 12:45:40 -04:00
parent cfe2c8f1b1
commit 57f082051d
2 changed files with 22 additions and 7 deletions

View file

@ -171,6 +171,7 @@ namespace MediaBrowser.Common.Implementations
Logger = LogManager.GetLogger("App");
LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info);
OnLoggerLoaded();
DiscoverTypes();
@ -183,6 +184,11 @@ namespace MediaBrowser.Common.Implementations
await RunStartupTasks().ConfigureAwait(false);
}
protected virtual void OnLoggerLoaded()
{
}
/// <summary>
/// Runs the startup tasks.
/// </summary>

View file

@ -160,6 +160,8 @@ namespace MediaBrowser.ServerApplication
get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); }
}
private Task<IHttpServer> _httpServerCreationTask;
/// <summary>
/// Runs the startup tasks.
/// </summary>
@ -175,6 +177,16 @@ namespace MediaBrowser.ServerApplication
Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint => entryPoint.Run());
}
/// <summary>
/// Called when [logger loaded].
/// </summary>
protected override void OnLoggerLoaded()
{
base.OnLoggerLoaded();
_httpServerCreationTask = Task.Run(() => ServerFactory.CreateServer(this, Logger, "Media Browser", "index.html"));
}
/// <summary>
/// Registers resources that classes will depend on
/// </summary>
@ -183,12 +195,6 @@ namespace MediaBrowser.ServerApplication
{
ServerKernel = new Kernel(ServerConfigurationManager);
var httpServerTask = Task.Run(() =>
{
HttpServer = ServerFactory.CreateServer(this, Logger, "Media Browser", "index.html");
RegisterSingleInstance(HttpServer, false);
});
await base.RegisterResources().ConfigureAwait(false);
RegisterSingleInstance<IHttpResultFactory>(new HttpResultFactory(LogManager));
@ -230,6 +236,9 @@ namespace MediaBrowser.ServerApplication
MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), ZipClient, ApplicationPaths, JsonSerializer);
RegisterSingleInstance(MediaEncoder);
HttpServer = await _httpServerCreationTask.ConfigureAwait(false);
RegisterSingleInstance(HttpServer, false);
ServerManager = new ServerManager(this, JsonSerializer, Logger, ServerConfigurationManager, ServerKernel);
RegisterSingleInstance(ServerManager);
@ -238,7 +247,7 @@ namespace MediaBrowser.ServerApplication
var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
var userTask = Task.Run(async () => await ConfigureUserRepositories().ConfigureAwait(false));
await Task.WhenAll(httpServerTask, itemsTask, userTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
await Task.WhenAll(itemsTask, userTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
SetKernelProperties();
}