private PackageMonitoringStatus()
 {
     AccessCondition = PackageMonitoringStatusAccessConditionHelper.FromUnknown();
     ExistingState   = new Dictionary <PackageState, AccessCondition>();
     foreach (var state in Enum.GetValues(typeof(PackageState)).Cast <PackageState>())
     {
         ExistingState[state] = PackageMonitoringStatusAccessConditionHelper.FromUnknown();
     }
 }
        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);
                }
            }
        }