private static async Task DownloadBingDailyImage(string saveDir) { var jsonHttpClient = BuildJsonHttpClient(); var metadataTask = jsonHttpClient.GetStringAsync($"{BaseUrl}/{ImageMetadataUrl}"); var metadataStr = await metadataTask; var metadata = JsonSerializer.Deserialize <RootObject>(metadataStr, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); var imageHttpClient = BuildImageHttpClient(); if (metadata.Images.Length == 0) { return; } var cache = new StringCache(Path.Combine(CurrentExeDirectory, "cache.txt")); cache.Load(); try { foreach (var metadataImage in metadata.Images) { var uri = new Uri(BaseUrl + metadataImage.Url); var queryDictionary = HttpUtility.ParseQueryString(uri.Query); var id = queryDictionary["id"]; if (cache.Contains(id)) { continue; } var imgStream = await imageHttpClient.GetStreamAsync(uri); var directoryInfo = Directory.CreateDirectory(saveDir); await using var fileStream = File.Create(Path.Combine(directoryInfo.FullName, id)); await imgStream.CopyToAsync(fileStream); cache.Add(id); } } finally { cache.Flush(); } }