예제 #1
0
        private async Task <ExtensionQueryResponseMetadata> ProcessResponseContent(HttpContent content)
        {
            using (var s = await content.ReadAsStreamAsync())
                using (var sr = new StreamReader(s))
                    using (var reader = new JsonTextReader(sr))
                    {
                        var jObject = await JObject.LoadAsync(reader);

                        var requestResultCount = Convert.ToInt32(
                            jObject.SelectToken("results[0].resultMetadata[0].metadataItems[0].count"),
                            CultureInfo.InvariantCulture
                            );

                        var metadata = new ExtensionQueryResponseMetadata
                        {
                            RequestResultTotalCount = requestResultCount
                        };

                        foreach (var jExt in (JArray)jObject.SelectToken("results[0].extensions"))
                        {
                            try
                            {
                                metadata.Items.Add(ParseExtensionMetadata((JObject)jExt));
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex, $"Error while parsing json: '{jExt}'");
                            }
                        }

                        return(metadata);
                    }
        }
 private async Task RefreshGalleryInfo(ExtensionQueryResponseMetadata metadata)
 {
     await Task.WhenAll(
         metadata.Items
         .Select(m => RefreshExtensionMetadata(m))
         .ToArray()
         );
 }