diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-20 13:32:10 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-20 13:32:10 -0400 |
| commit | f3ce127a62714c97747f1e9575aaea1e9cdb3b6a (patch) | |
| tree | d138a473d31b69e8ba59020b0dc1da3c51c2833e /MediaBrowser.ServerApplication/ApplicationHost.cs | |
| parent | e50c29ffca5c4a5865d8b0bf34c2f655387f1d3e (diff) | |
starting point towards running as a service
Diffstat (limited to 'MediaBrowser.ServerApplication/ApplicationHost.cs')
| -rw-r--r-- | MediaBrowser.ServerApplication/ApplicationHost.cs | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 13afb41e72..7288d70d92 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -1,5 +1,4 @@ -using System.Windows.Forms; -using MediaBrowser.Api; +using MediaBrowser.Api; using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Constants; @@ -7,7 +6,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Implementations; using MediaBrowser.Common.Implementations.IO; using MediaBrowser.Common.Implementations.ScheduledTasks; -using MediaBrowser.Common.Implementations.Updates; using MediaBrowser.Common.MediaInfo; using MediaBrowser.Common.Net; using MediaBrowser.Controller; @@ -184,6 +182,13 @@ namespace MediaBrowser.ServerApplication private IItemRepository ItemRepository { get; set; } private INotificationsRepository NotificationsRepository { get; set; } + public bool IsBackgroundService + { + get { return _appInterface != null && _appInterface.IsBackgroundService; } + } + + private readonly IApplicationInterface _appInterface; + /// <summary> /// The full path to our startmenu shortcut /// </summary> @@ -194,6 +199,11 @@ namespace MediaBrowser.ServerApplication private Task<IHttpServer> _httpServerCreationTask; + public ApplicationHost(IApplicationInterface appInterface) + { + _appInterface = appInterface; + } + /// <summary> /// Runs the startup tasks. /// </summary> @@ -505,7 +515,7 @@ namespace MediaBrowser.ServerApplication base.OnConfigurationUpdated(sender, e); HttpServer.EnableHttpRequestLogging = ServerConfigurationManager.Configuration.EnableHttpLevelLogging; - + if (!string.Equals(HttpServer.UrlPrefix, HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase)) { NotifyPendingRestart(); @@ -521,19 +531,18 @@ namespace MediaBrowser.ServerApplication /// <summary> /// Restarts this instance. /// </summary> - public override void Restart() + public override async Task Restart() { try { - var task = ServerManager.SendWebSocketMessageAsync("ServerRestarting", () => string.Empty, CancellationToken.None); - task.Wait(); + await ServerManager.SendWebSocketMessageAsync("ServerRestarting", () => string.Empty, CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) { Logger.ErrorException("Error sending server restart web socket message", ex); } - App.Instance.Restart(); + _appInterface.RestartApplication(); } /// <summary> @@ -618,7 +627,8 @@ namespace MediaBrowser.ServerApplication Id = _systemId, ProgramDataPath = ApplicationPaths.ProgramDataPath, MacAddress = GetMacAddress(), - HttpServerPortNumber = ServerConfigurationManager.Configuration.HttpServerPortNumber + HttpServerPortNumber = ServerConfigurationManager.Configuration.HttpServerPortNumber, + IsBackgroundService = IsBackgroundService }; } @@ -642,19 +652,18 @@ namespace MediaBrowser.ServerApplication /// <summary> /// Shuts down. /// </summary> - public override void Shutdown() + public override async Task Shutdown() { try { - var task = ServerManager.SendWebSocketMessageAsync("ServerShuttingDown", () => string.Empty, CancellationToken.None); - task.Wait(); + await ServerManager.SendWebSocketMessageAsync("ServerShuttingDown", () => string.Empty, CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) { Logger.ErrorException("Error sending server shutdown web socket message", ex); } - App.Instance.Dispatcher.Invoke(App.Instance.Shutdown); + _appInterface.ShutdownApplication(); } /// <summary> |
