rework hosting options

This commit is contained in:
Luke Pulverenti
2015-01-18 23:29:57 -05:00
parent 1316994324
commit de76156391
23 changed files with 231 additions and 163 deletions

View File

@@ -78,7 +78,7 @@ namespace MediaBrowser.Server.Implementations.Connect
if (!ip.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
!ip.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
ip = (_config.Configuration.UseHttps ? "https://" : "http://") + ip;
ip = (_appHost.EnableHttps ? "https://" : "http://") + ip;
}
return ip + ":" + _config.Configuration.PublicPort.ToString(CultureInfo.InvariantCulture);
@@ -90,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.Connect
private string XApplicationValue
{
get { return "Media Browser Server/" + _appHost.ApplicationVersion; }
get { return _appHost.Name + "/" + _appHost.ApplicationVersion; }
}
public ConnectManager(ILogger logger,
@@ -112,6 +112,7 @@ namespace MediaBrowser.Server.Implementations.Connect
_providerManager = providerManager;
_userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated;
_config.ConfigurationUpdated += _config_ConfigurationUpdated;
LoadCachedData();
}
@@ -164,8 +165,7 @@ namespace MediaBrowser.Server.Implementations.Connect
}
catch (HttpException ex)
{
if (!ex.StatusCode.HasValue ||
!new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
if (!ex.StatusCode.HasValue || !new[] { HttpStatusCode.NotFound, HttpStatusCode.Unauthorized }.Contains(ex.StatusCode.Value))
{
throw;
}
@@ -179,6 +179,8 @@ namespace MediaBrowser.Server.Implementations.Connect
await CreateServerRegistration(wanApiAddress, localAddress).ConfigureAwait(false);
}
_lastReportedIdentifier = GetConnectReportingIdentifier(localAddress, wanApiAddress);
await RefreshAuthorizationsInternal(true, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
@@ -187,6 +189,27 @@ namespace MediaBrowser.Server.Implementations.Connect
}
}
private string _lastReportedIdentifier;
private string GetConnectReportingIdentifier()
{
return GetConnectReportingIdentifier(_appHost.GetSystemInfo().LocalAddress, WanApiAddress);
}
private string GetConnectReportingIdentifier(string localAddress, string remoteAddress)
{
return (remoteAddress ?? string.Empty) + (localAddress ?? string.Empty);
}
void _config_ConfigurationUpdated(object sender, EventArgs e)
{
// If info hasn't changed, don't report anything
if (string.Equals(_lastReportedIdentifier, GetConnectReportingIdentifier(), StringComparison.OrdinalIgnoreCase))
{
return;
}
UpdateConnectInfo();
}
private async Task CreateServerRegistration(string wanApiAddress, string localAddress)
{
if (string.IsNullOrWhiteSpace(wanApiAddress))