diff options
3 files changed, 25 insertions, 99 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 37db80ee3..b6b956602 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -282,7 +282,7 @@ namespace MediaBrowser.Common.Implementations SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths); RegisterSingleInstance(SecurityManager); - InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager); + InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager); RegisterSingleInstance(InstallationManager); }); } @@ -560,8 +560,6 @@ namespace MediaBrowser.Common.Implementations /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value> public abstract bool CanSelfUpdate { get; } - private Tuple<CheckForUpdateResult, DateTime> _lastUpdateCheckResult; - /// <summary> /// Checks for update. /// </summary> @@ -571,24 +569,9 @@ namespace MediaBrowser.Common.Implementations public async Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress) { - if (_lastUpdateCheckResult != null) - { - // Let dev users get results more often for testing purposes - var cacheLength = ConfigurationManager.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev - ? TimeSpan.FromHours(1) - : TimeSpan.FromHours(12); - - if ((DateTime.UtcNow - _lastUpdateCheckResult.Item2) < cacheLength) - { - return _lastUpdateCheckResult.Item1; - } - } - var result = await CheckForApplicationUpdateInternal(cancellationToken, progress).ConfigureAwait(false); - _lastUpdateCheckResult = new Tuple<CheckForUpdateResult, DateTime>(result, DateTime.UtcNow); - - return _lastUpdateCheckResult.Item1; + return result; } /// <summary> @@ -600,7 +583,7 @@ namespace MediaBrowser.Common.Implementations private async Task<CheckForUpdateResult> CheckForApplicationUpdateInternal(CancellationToken cancellationToken, IProgress<double> progress) { - var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(CancellationToken.None).ConfigureAwait(false); + var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false); var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, ApplicationUpdatePackageName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel); diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index 4913dd5a1..4edc1e8cb 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -1,5 +1,4 @@ -using System.Security.Cryptography; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Events; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; @@ -14,6 +13,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; @@ -104,6 +104,7 @@ namespace MediaBrowser.Common.Implementations.Updates private readonly IJsonSerializer _jsonSerializer; private readonly ISecurityManager _securityManager; private readonly INetworkManager _networkManager; + private readonly IConfigurationManager _config; /// <summary> /// Gets the application host. @@ -111,7 +112,7 @@ namespace MediaBrowser.Common.Implementations.Updates /// <value>The application host.</value> private readonly IApplicationHost _applicationHost; - public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, INetworkManager networkManager) + public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, INetworkManager networkManager, IConfigurationManager config) { if (logger == null) { @@ -127,6 +128,7 @@ namespace MediaBrowser.Common.Implementations.Updates _jsonSerializer = jsonSerializer; _securityManager = securityManager; _networkManager = networkManager; + _config = config; _logger = logger; } @@ -153,6 +155,8 @@ namespace MediaBrowser.Common.Implementations.Updates } } + private Tuple<List<PackageInfo>, DateTime> _lastPackageListResult; + /// <summary> /// Gets all available packages. /// </summary> @@ -164,12 +168,27 @@ namespace MediaBrowser.Common.Implementations.Updates PackageType? packageType = null, Version applicationVersion = null) { + if (_lastPackageListResult != null) + { + // Let dev users get results more often for testing purposes + var cacheLength = _config.CommonConfiguration.SystemUpdateLevel == PackageVersionClass.Dev + ? TimeSpan.FromMinutes(10) + : TimeSpan.FromHours(12); + + if ((DateTime.UtcNow - _lastPackageListResult.Item2) < cacheLength) + { + return _lastPackageListResult.Item1; + } + } + using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false)) { cancellationToken.ThrowIfCancellationRequested(); var packages = _jsonSerializer.DeserializeFromStream<List<PackageInfo>>(json).ToList(); + _lastPackageListResult = new Tuple<List<PackageInfo>, DateTime>(packages, DateTime.UtcNow); + return FilterPackages(packages, packageType, applicationVersion); } } diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs index db008c3d9..362dd4bc0 100644 --- a/MediaBrowser.ServerApplication/App.xaml.cs +++ b/MediaBrowser.ServerApplication/App.xaml.cs @@ -291,81 +291,5 @@ namespace MediaBrowser.ServerApplication Dispatcher.Invoke(Shutdown); } - - /// <summary> - /// Gets the image. - /// </summary> - /// <param name="uri">The URI.</param> - /// <returns>Image.</returns> - /// <exception cref="System.ArgumentNullException">uri</exception> - public Image GetImage(string uri) - { - if (string.IsNullOrEmpty(uri)) - { - throw new ArgumentNullException("uri"); - } - - return GetImage(new Uri(uri)); - } - - /// <summary> - /// Gets the image. - /// </summary> - /// <param name="uri">The URI.</param> - /// <returns>Image.</returns> - /// <exception cref="System.ArgumentNullException">uri</exception> - public Image GetImage(Uri uri) - { - if (uri == null) - { - throw new ArgumentNullException("uri"); - } - - return new Image { Source = GetBitmapImage(uri) }; - } - - /// <summary> - /// Gets the bitmap image. - /// </summary> - /// <param name="uri">The URI.</param> - /// <returns>BitmapImage.</returns> - /// <exception cref="System.ArgumentNullException">uri</exception> - public BitmapImage GetBitmapImage(string uri) - { - if (string.IsNullOrEmpty(uri)) - { - throw new ArgumentNullException("uri"); - } - - return GetBitmapImage(new Uri(uri)); - } - - /// <summary> - /// Gets the bitmap image. - /// </summary> - /// <param name="uri">The URI.</param> - /// <returns>BitmapImage.</returns> - /// <exception cref="System.ArgumentNullException">uri</exception> - public BitmapImage GetBitmapImage(Uri uri) - { - if (uri == null) - { - throw new ArgumentNullException("uri"); - } - - var bitmap = new BitmapImage - { - CreateOptions = BitmapCreateOptions.DelayCreation, - CacheOption = BitmapCacheOption.OnDemand, - UriCachePolicy = new RequestCachePolicy(RequestCacheLevel.CacheIfAvailable) - }; - - bitmap.BeginInit(); - bitmap.UriSource = uri; - bitmap.EndInit(); - - RenderOptions.SetBitmapScalingMode(bitmap, BitmapScalingMode.Fant); - return bitmap; - } } } |
