aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Startup.Common
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2016-01-19 14:54:07 -0500
committerLuke <luke.pulverenti@gmail.com>2016-01-19 14:54:07 -0500
commit236b5caee2797d4a8af857cea2f3859bc94d3948 (patch)
tree210242ec629d84baa9811dacdad3931a4e5c7b35 /MediaBrowser.Server.Startup.Common
parente951dd20d95c81da29d4f9d8a2cb927e7639518b (diff)
parenta5d54256ffb79dd1d0a06df0536f772bbeff9d3d (diff)
Merge pull request #1409 from MediaBrowser/beta
merge from beta
Diffstat (limited to 'MediaBrowser.Server.Startup.Common')
-rw-r--r--MediaBrowser.Server.Startup.Common/ApplicationHost.cs124
-rw-r--r--MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj2
-rw-r--r--MediaBrowser.Server.Startup.Common/packages.config2
3 files changed, 84 insertions, 44 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
index 99a7f0a152..21731a3a60 100644
--- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
+++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs
@@ -91,14 +91,17 @@ using MediaBrowser.Server.Startup.Common.Migrations;
using MediaBrowser.WebDashboard.Api;
using MediaBrowser.XbmcMetadata.Providers;
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
+using System.Net;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
+using MediaBrowser.Common.Implementations.Updates;
namespace MediaBrowser.Server.Startup.Common
{
@@ -204,9 +207,10 @@ namespace MediaBrowser.Server.Startup.Common
private IPlaylistManager PlaylistManager { get; set; }
private readonly StartupOptions _startupOptions;
- private readonly string _remotePackageName;
+ private readonly string _releaseAssetFilename;
internal INativeApp NativeApp { get; set; }
+ private Timer _ipAddressCacheTimer;
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
@@ -215,21 +219,23 @@ namespace MediaBrowser.Server.Startup.Common
/// <param name="logManager">The log manager.</param>
/// <param name="options">The options.</param>
/// <param name="fileSystem">The file system.</param>
- /// <param name="remotePackageName">Name of the remote package.</param>
+ /// <param name="releaseAssetFilename">The release asset filename.</param>
/// <param name="nativeApp">The native application.</param>
public ApplicationHost(ServerApplicationPaths applicationPaths,
ILogManager logManager,
StartupOptions options,
IFileSystem fileSystem,
- string remotePackageName,
+ string releaseAssetFilename,
INativeApp nativeApp)
: base(applicationPaths, logManager, fileSystem)
{
_startupOptions = options;
- _remotePackageName = remotePackageName;
+ _releaseAssetFilename = releaseAssetFilename;
NativeApp = nativeApp;
SetBaseExceptionMessage();
+
+ _ipAddressCacheTimer = new Timer(OnCacheClearTimerFired, null, TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(3));
}
private Version _version;
@@ -316,6 +322,7 @@ namespace MediaBrowser.Server.Startup.Common
{
await base.RunStartupTasks().ConfigureAwait(false);
+ Logger.Info("ServerId: {0}", SystemId);
Logger.Info("Core startup complete");
HttpServer.GlobalResponse = null;
@@ -436,7 +443,7 @@ namespace MediaBrowser.Server.Startup.Common
RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LogManager, LibraryManager, UserManager));
- HttpServer = ServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, "Emby", "web/index.html");
+ HttpServer = ServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, "Emby", "web/index.html");
HttpServer.GlobalResponse = LocalizationManager.GetLocalizedString("StartupEmbyServerIsLoading");
RegisterSingleInstance(HttpServer, false);
progress.Report(10);
@@ -515,7 +522,7 @@ namespace MediaBrowser.Server.Startup.Common
SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, LibraryManager, MediaSourceManager);
RegisterSingleInstance(SubtitleManager);
- RegisterSingleInstance<IDeviceDiscovery>(new DeviceDiscovery(LogManager.GetLogger("IDeviceDiscovery"), ServerConfigurationManager, this));
+ RegisterSingleInstance<IDeviceDiscovery>(new DeviceDiscovery(LogManager.GetLogger("IDeviceDiscovery"), ServerConfigurationManager, this, NetworkManager));
ChapterManager = new ChapterManager(LibraryManager, LogManager.GetLogger("ChapterManager"), ServerConfigurationManager, ItemRepository);
RegisterSingleInstance(ChapterManager);
@@ -963,6 +970,10 @@ namespace MediaBrowser.Server.Startup.Common
{
get
{
+ if (!ServerConfigurationManager.Configuration.EnableAutoUpdate)
+ {
+ return false;
+ }
#if DEBUG
return false;
#endif
@@ -1108,14 +1119,14 @@ namespace MediaBrowser.Server.Startup.Common
try
{
// Return the first matched address, if found, or the first known local address
- var address = LocalIpAddress;
+ var address = LocalIpAddresses.FirstOrDefault(i => !IPAddress.IsLoopback(i));
- if (!string.IsNullOrWhiteSpace(address))
+ if (address != null)
{
- address = GetLocalApiUrl(address);
+ return GetLocalApiUrl(address.ToString());
}
- return address;
+ return null;
}
catch (Exception ex)
{
@@ -1133,40 +1144,71 @@ namespace MediaBrowser.Server.Startup.Common
HttpPort.ToString(CultureInfo.InvariantCulture));
}
- public string LocalIpAddress
+ public List<IPAddress> LocalIpAddresses
{
get
{
- return HttpServerIpAddresses.FirstOrDefault();
+ var localAddresses = NetworkManager.GetLocalIpAddresses()
+ .Where(IsIpAddressValid)
+ .ToList();
+
+ return localAddresses;
}
}
- private IEnumerable<string> HttpServerIpAddresses
+ private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
+ private bool IsIpAddressValid(IPAddress address)
{
- get
+ if (IPAddress.IsLoopback(address))
{
- var localAddresses = NetworkManager.GetLocalIpAddresses()
- .ToList();
+ return true;
+ }
- var httpServerAddresses = HttpServer.LocalEndPoints
- .Select(i => i.Split(':').FirstOrDefault())
- .Where(i => !string.IsNullOrEmpty(i))
- .ToList();
+ var apiUrl = GetLocalApiUrl(address.ToString());
+ apiUrl += "/system/ping";
- // Cross-check the local ip addresses with addresses that have been received on with the http server
- var matchedAddresses = httpServerAddresses
- .Where(i => localAddresses.Contains(i, StringComparer.OrdinalIgnoreCase))
- .ToList();
+ bool cachedResult;
+ if (_validAddressResults.TryGetValue(apiUrl, out cachedResult))
+ {
+ return cachedResult;
+ }
+
+ try
+ {
+ using (var response = HttpClient.SendAsync(new HttpRequestOptions
+ {
+ Url = apiUrl,
+ LogErrorResponseBody = false,
+ LogErrors = false,
+ LogRequest = false
- if (matchedAddresses.Count == 0)
+ }, "POST").Result)
{
- return localAddresses;
+ using (var reader = new StreamReader(response.Content))
+ {
+ var result = reader.ReadToEnd();
+ var valid = string.Equals(Name, result, StringComparison.OrdinalIgnoreCase);
+
+ _validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid);
+ Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, valid);
+ return valid;
+ }
}
+ }
+ catch
+ {
+ Logger.Debug("Ping test result to {0}. Success: {1}", apiUrl, false);
- return matchedAddresses;
+ _validAddressResults.AddOrUpdate(apiUrl, false, (k, v) => false);
+ return false;
}
}
+ private void OnCacheClearTimerFired(object state)
+ {
+ _validAddressResults.Clear();
+ }
+
public string FriendlyName
{
get
@@ -1263,25 +1305,23 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>Task{CheckForUpdateResult}.</returns>
public override async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
{
- var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false);
-
- var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, _remotePackageName, null, ApplicationVersion, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
+ var cacheLength = TimeSpan.FromHours(3);
+ var updateLevel = ConfigurationManager.CommonConfiguration.SystemUpdateLevel;
- var versionObject = version == null || string.IsNullOrWhiteSpace(version.versionStr) ? null : new Version(version.versionStr);
-
- var isUpdateAvailable = versionObject != null && versionObject > ApplicationVersion;
+ if (updateLevel == PackageVersionClass.Beta)
+ {
+ cacheLength = TimeSpan.FromHours(1);
+ }
+ else if (updateLevel == PackageVersionClass.Dev)
+ {
+ cacheLength = TimeSpan.FromMinutes(5);
+ }
- var result = versionObject != null ?
- new CheckForUpdateResult { AvailableVersion = versionObject.ToString(), IsUpdateAvailable = isUpdateAvailable, Package = version } :
- new CheckForUpdateResult { AvailableVersion = ApplicationVersion.ToString(), IsUpdateAvailable = false };
+ var result = await new GithubUpdater(HttpClient, JsonSerializer, cacheLength).CheckForUpdateResult("MediaBrowser", "Emby", ApplicationVersion, updateLevel, _releaseAssetFilename,
+ "MBServer", "Mbserver.zip", cancellationToken).ConfigureAwait(false);
HasUpdateAvailable = result.IsUpdateAvailable;
- if (result.IsUpdateAvailable)
- {
- Logger.Info("New application version is available: {0}", result.AvailableVersion);
- }
-
return result;
}
@@ -1294,7 +1334,7 @@ namespace MediaBrowser.Server.Startup.Common
/// <returns>Task.</returns>
public override async Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress)
{
- await InstallationManager.InstallPackage(package, progress, cancellationToken).ConfigureAwait(false);
+ await InstallationManager.InstallPackage(package, false, progress, cancellationToken).ConfigureAwait(false);
HasUpdateAvailable = false;
diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
index 13b782e406..6dd2066bbc 100644
--- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
+++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj
@@ -33,7 +33,7 @@
<ItemGroup>
<Reference Include="CommonIO, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\CommonIO.1.0.0.5\lib\net45\CommonIO.dll</HintPath>
+ <HintPath>..\packages\CommonIO.1.0.0.7\lib\net45\CommonIO.dll</HintPath>
</Reference>
<Reference Include="Mono.Posix, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
diff --git a/MediaBrowser.Server.Startup.Common/packages.config b/MediaBrowser.Server.Startup.Common/packages.config
index 6a2a6c1e5e..2956d69c6b 100644
--- a/MediaBrowser.Server.Startup.Common/packages.config
+++ b/MediaBrowser.Server.Startup.Common/packages.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="CommonIO" version="1.0.0.5" targetFramework="net45" />
+ <package id="CommonIO" version="1.0.0.7" targetFramework="net45" />
<package id="Mono.Posix" version="4.0.0.0" targetFramework="net45" />
<package id="Patterns.Logging" version="1.0.0.2" targetFramework="net45" />
</packages> \ No newline at end of file