public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Byte[]> > DownloadAsync(System.String ContainerName, System.Collections.Generic.Dictionary <System.String, System.String> StorageFileNames) { SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate(); SoftmakeAll.SDK.OperationResult <System.Byte[]> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Byte[]>(); if ((System.String.IsNullOrWhiteSpace(ContainerName)) || (StorageFileNames == null) || (StorageFileNames.Count == 0)) { OperationResult.Message = "The ContainerName and StorageFileName cannot be null."; return(OperationResult); } try { global::Azure.Storage.Blobs.BlobContainerClient BlobContainerClient = new global::Azure.Storage.Blobs.BlobContainerClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, ContainerName); if (StorageFileNames.Count == 1) { global::Azure.Storage.Blobs.BlobClient BlobClient = BlobContainerClient.GetBlobClient(StorageFileNames.First().Key); if (!(await BlobClient.ExistsAsync())) { OperationResult.Message = "The file could not be found."; return(OperationResult); } using (System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream()) { await BlobClient.DownloadToAsync(MemoryStream); OperationResult.Data = MemoryStream.ToArray(); } } else { using (System.Threading.SemaphoreSlim SemaphoreSlim = new System.Threading.SemaphoreSlim(StorageFileNames.Count)) { System.Collections.Generic.List <System.Threading.Tasks.Task> DownloadTasks = new System.Collections.Generic.List <System.Threading.Tasks.Task>(); foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames) { global::Azure.Storage.Blobs.BlobClient BlobClient = BlobContainerClient.GetBlobClient(StorageFileName.Key); if (!(await BlobClient.ExistsAsync())) { continue; } await SemaphoreSlim.WaitAsync(); DownloadTasks.Add(System.Threading.Tasks.Task.Run(async() => { await BlobClient.DownloadToAsync(StorageFileName.Key); SemaphoreSlim.Release(); })); } if (DownloadTasks.Any()) { await System.Threading.Tasks.Task.WhenAll(DownloadTasks); } } OperationResult.Data = SoftmakeAll.SDK.Files.Compression.CreateZipArchive(StorageFileNames); foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames) { if (System.IO.File.Exists(StorageFileName.Key)) { try { System.IO.File.Delete(StorageFileName.Key); } catch { } } } } } catch (System.Exception ex) { if (StorageFileNames.Count > 0) { foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames) { if (System.IO.File.Exists(StorageFileName.Key)) { try { System.IO.File.Delete(StorageFileName.Key); } catch { } } } } OperationResult.Message = ex.Message; return(OperationResult); } OperationResult.ExitCode = 0; return(OperationResult); }