Ejemplo n.º 1
0
 private static void Process(ActionConfiguration actions, string url)
 {
     Parallel.ForEach(actions.Files(), file =>
     {
         Console.ForegroundColor = ConsoleColor.DarkGray;
         Console.WriteLine($"{DateTime.UtcNow.Millisecond} > Started converting {file} [{url}]");
         using var client = new HttpClient();
         client.DefaultRequestHeaders.Add("Api-Key", "3ccc6de8-0e16-4e36-810a-d90fb52d2ffe");
         var formData = new MultipartFormDataContent
         {
             { new StreamContent(new MemoryStream(File.ReadAllBytes(file))), "image", $"{file}" }
         };
         var response = client.PostAsync($"https://api.deepai.org/api/{url}",
                                         formData).GetAwaiter().GetResult();
         var res   = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
         var model = JsonConvert.DeserializeObject <ApiResponse>(res);
         DownloadAndSaveFile(model, file, actions);
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine($"{DateTime.UtcNow.Millisecond} > Finished converting {file} [{url}]");
     });
 }