From dbc9beab22a2ec4a9e2680505256cb478550a31f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 12 Jan 2016 15:12:50 -0500 Subject: [PATCH] add error handling to package retrieval --- .../Updates/InstallationManager.cs | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index d155f11c73..8e0df90050 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -193,38 +193,37 @@ namespace MediaBrowser.Common.Implementations.Updates /// The cancellation token. /// Task{List{PackageInfo}}. public async Task> GetAvailablePackagesWithoutRegistrationInfo(CancellationToken cancellationToken) - { - using (var stream = await GetCachedPackages(cancellationToken).ConfigureAwait(false)) - { - var packages = _jsonSerializer.DeserializeFromStream>(stream).ToList(); - - if ((DateTime.UtcNow - _lastPackageUpdateTime) > GetCacheLength()) - { - UpdateCachedPackages(CancellationToken.None, false); - } - - return packages; - } - } - - private string PackageCachePath - { - get { return Path.Combine(_appPaths.CachePath, "serverpackages.json"); } - } - - private async Task GetCachedPackages(CancellationToken cancellationToken) { try { - return _fileSystem.OpenRead(PackageCachePath); + using (var stream = _fileSystem.OpenRead(PackageCachePath)) + { + var packages = _jsonSerializer.DeserializeFromStream>(stream).ToList(); + + if ((DateTime.UtcNow - _lastPackageUpdateTime) > GetCacheLength()) + { + UpdateCachedPackages(CancellationToken.None, false); + } + + return packages; + } } catch (Exception) { } + _lastPackageUpdateTime = DateTime.MinValue; await UpdateCachedPackages(cancellationToken, true).ConfigureAwait(false); - return _fileSystem.OpenRead(PackageCachePath); + using (var stream = _fileSystem.OpenRead(PackageCachePath)) + { + return _jsonSerializer.DeserializeFromStream>(stream).ToList(); + } + } + + private string PackageCachePath + { + get { return Path.Combine(_appPaths.CachePath, "serverpackages.json"); } } private readonly SemaphoreSlim _updateSemaphore = new SemaphoreSlim(1, 1);