private async void button2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textFolder.Text)) { MessageBox.Show("You need to enter the folder address !"); } else { var results = new List <DataFolder>(); string[] subDirs = Directory.GetDirectories(textFolder.Text); var taskUploadImageVarions = new List <Task <DataFolder> >(); foreach (var sub in subDirs) { var extension = Path.GetExtension(sub); string directionTo = ""; if (!string.IsNullOrEmpty(extension)) { directionTo = DeleteExtension(sub, extension); Directory.Move(sub, directionTo); } else { directionTo = sub; } var directories = Directory.GetDirectories(directionTo); var subList = Directory.GetFiles(directionTo); var customImage = new ImageVariation(); customImage.RootImage = subList.FirstOrDefault(); var subList2 = Directory.GetFiles(directories.FirstOrDefault()); customImage.VarionImages.AddRange(subList2); try { var result = await UploadStream(customImage, sender, e); results.Add(result); } catch (Exception ex) { Export(results); break; } } Export(results); } }
private async Task <DataFolder> UploadStream(ImageVariation url, object sender, EventArgs e) { var response = new DataFolder(); if (url != null) { foreach (var _url in url.VarionImages) { var urlImage = await UploadEachFile(_url, true); response.VariationImages.Add(urlImage); } var imageRoot = string.IsNullOrEmpty(url.RootImage) ? new PropertyImage() : await UploadEachFile(url.RootImage, false); response.RootImage = imageRoot; } return(response); }