private async Task <PackageMonitoringStatus> GetPackageAsync(CatalogStorage storage, Uri packageUri, CancellationToken token)
        {
            try
            {
                var content = await storage.LoadAsync(packageUri, token);

                string statusString = null;
                using (var stream = content.GetContentStream())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        statusString = await reader.ReadToEndAsync();
                    }
                }

                var status = JsonConvert.DeserializeObject <PackageMonitoringStatus>(statusString, JsonSerializerUtility.SerializerSettings);
                status.AccessCondition = PackageMonitoringStatusAccessConditionHelper.FromContent(content);
                return(status);
            }
            catch (Exception deserializationException)
            {
                _logger.LogWarning(
                    LogEvents.StatusDeserializationFailure,
                    deserializationException,
                    "Unable to deserialize package status from {PackageUri}!",
                    packageUri);

                try
                {
                    /// Construct a <see cref="PackageMonitoringStatus"/> from the <see cref="Uri"/> with this as the exception.
                    return(new PackageMonitoringStatus(ParsePackageUri(packageUri), new StatusDeserializationException(deserializationException)));
                }
                catch (Exception uriParsingException)
                {
                    _logger.LogError(
                        LogEvents.StatusDeserializationFatalFailure,
                        new AggregateException(deserializationException, uriParsingException),
                        "Unable to get package id and version from {PackageUri}!",
                        packageUri);

                    return(null);
                }
            }
        }
Exemple #2
0
 protected override Task <StorageContent> OnLoadAsync(Uri resourceUri, CancellationToken cancellationToken)
 {
     return(_primaryStorage.LoadAsync(resourceUri, cancellationToken));
 }