From f8263b8b69bac872f5b821e32f52fb502665976b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 7 May 2013 15:07:51 -0400 Subject: [PATCH] improve restart code after port change --- .../BaseApplicationHost.cs | 4 ++-- .../ServerManager/ServerManager.cs | 14 ++----------- .../ApplicationHost.cs | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index c0959de85..386da0ffa 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -201,7 +201,7 @@ namespace MediaBrowser.Common.Implementations Task.Run(() => ConfigureAutoRunAtStartup()); - ConfigurationManager.ConfigurationUpdated += ConfigurationManager_ConfigurationUpdated; + ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated; }); } @@ -459,7 +459,7 @@ namespace MediaBrowser.Common.Implementations /// The source of the event. /// The instance containing the event data. /// - void ConfigurationManager_ConfigurationUpdated(object sender, EventArgs e) + protected virtual void OnConfigurationUpdated(object sender, EventArgs e) { ConfigureAutoRunAtStartup(); } diff --git a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs b/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs index 6b33f1145..a45804f69 100644 --- a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs +++ b/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs @@ -114,6 +114,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager _applicationHost = applicationHost; ConfigurationManager = configurationManager; _kernel = kernel; + + ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated; } /// @@ -127,8 +129,6 @@ namespace MediaBrowser.Server.Implementations.ServerManager { ReloadExternalWebSocketServer(); } - - ConfigurationManager.ConfigurationUpdated += ConfigurationUpdated; } /// @@ -352,16 +352,6 @@ namespace MediaBrowser.Server.Implementations.ServerManager void ConfigurationUpdated(object sender, EventArgs e) { HttpServer.EnableHttpRequestLogging = ConfigurationManager.Configuration.EnableHttpLevelLogging; - - if (!string.Equals(HttpServer.UrlPrefix, _kernel.HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase)) - { - _applicationHost.NotifyPendingRestart(); - } - - else if (!SupportsNativeWebSocket && ExternalWebSocketServer != null && ExternalWebSocketServer.Port != ConfigurationManager.Configuration.LegacyWebSocketPortNumber) - { - _applicationHost.NotifyPendingRestart(); - } } /// diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index 309a2c351..37e6d1b8d 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -431,6 +431,27 @@ namespace MediaBrowser.ServerApplication } } + /// + /// Called when [configuration updated]. + /// + /// The sender. + /// The instance containing the event data. + protected override void OnConfigurationUpdated(object sender, EventArgs e) + { + base.OnConfigurationUpdated(sender, e); + + if (!string.Equals(HttpServer.UrlPrefix, ServerKernel.HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase)) + { + NotifyPendingRestart(); + } + + else if (!ServerManager.SupportsNativeWebSocket && ServerManager.WebSocketPortNumber != ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber) + { + NotifyPendingRestart(); + } + + } + /// /// Restarts this instance. ///