From 56763c08a2be6594457e1fffea1eda791c187f9c 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 0142753314..6d68b968be 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);