Exemplo n.º 1
0
        private static async Task ReadJson(string wikiClass, HttpClient httpClient, ApiAccessor apiAccessor, string savePath)
        {
            // for items that have the given class ...
            var where = $"{CargoConstants.ItemClass}='{wikiClass}'";
            // ... retrieve name and the icon url
            var task    = apiAccessor.GetItemImageInfosAsync(where);
            var results = (await task).ToList();

            // download the images from the urls and save them
            foreach (var result in results)
            {
                var data = await httpClient.GetByteArrayAsync(result.Url);

                foreach (var name in result.Names)
                {
                    var fileName = name + ".png";
                    WikiApiUtils.SaveImage(data, Path.Combine(savePath, fileName), true);
                }
            }

            Log.Info($"Retrieved {results.Count} images for class {wikiClass}.");
        }