public static async Task <long> CopyFileToBlobAsync( [ActivityTrigger] DirectoryInfo folderInfo, [Inject] ILog log, [Inject] BlobRequestOptionsHelper blobRequestOptionsHelper, [Inject] BackupFolderBlobRepository backupFolderBlobRepository, [Inject] BackupFolderTableStorageRepository backupFolderTableStorageRepository) { log.Info($"Start copying files from '{folderInfo.FullName}'"); log.Info("Initializing repositories"); backupFolderBlobRepository.Initialize(); backupFolderTableStorageRepository.Initialize(); log.Info($"Deleting all records from '{backupFolderBlobRepository.Config.ContainerName}'"); await backupFolderBlobRepository.DeleteContainerAsync(); backupFolderBlobRepository.Initialize(); var folderFiles = await backupFolderTableStorageRepository.GetAllAsync(); log.Info($"Retrieved {folderFiles.Count} records from '{backupFolderTableStorageRepository.Config.TableName}'"); var tasks = new List <Task <long> >(); foreach (var file in folderFiles) { tasks.Add(CopyFileAsync(file.FileName, log, backupFolderBlobRepository, blobRequestOptionsHelper)); } await Task.WhenAll(tasks); var totalBytes = tasks.Sum(t => t.Result); return(totalBytes); }
public static async Task <long> GetFileListAsync( [ActivityTrigger] string rootFolder, [Inject] ILog log, [Inject] IFileHelper fileHelper, [Inject] BackupFolderTableStorageRepository backupFolderTableStorageRepository) { log.Info($"Initializing '{backupFolderTableStorageRepository.Config.TableName}'..."); backupFolderTableStorageRepository.Initialize(); log.Info($"Deleting all records from '{backupFolderTableStorageRepository.Config.TableName}'..."); backupFolderTableStorageRepository.DeleteAllAsync().Wait(); log.Info($"Searching for files under '{rootFolder}'..."); var files = fileHelper.GetAllFilesFromDirectory(rootFolder); log.Info($"Found {files.Count} file(s) under {rootFolder}."); log.Info($"Storing {files.Count} file(s) into {backupFolderTableStorageRepository.Config.TableName}."); foreach (var file in files) { var fileInfo = new FileInformation { FileName = file }; await backupFolderTableStorageRepository.SetAsync(fileInfo).ConfigureAwait(false); } return(files.Count); }