void UploadDirectory(string directoryName, long size, TransferUtilityTests.DirectoryProgressValidator <UploadDirectoryProgressArgs> progressValidator, bool validate = true) { var directoryPath = Path.Combine(basePath, directoryName); for (int i = 0; i < 5; i++) { var filePath = Path.Combine(Path.Combine(directoryPath, i.ToString()), "file.txt"); UtilityMethods.GenerateFile(filePath, size); } var config = new TransferUtilityConfig { ConcurrentServiceRequests = 10, }; var transferUtility = new TransferUtility(Client, config); var request = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = directoryPath, KeyPrefix = directoryName, SearchPattern = "*", SearchOption = SearchOption.AllDirectories, }; if (progressValidator != null) { request.UploadDirectoryProgressEvent += progressValidator.OnProgressEvent; } HashSet <string> files = new HashSet <string>(); request.UploadDirectoryProgressEvent += (s, e) => { files.Add(e.CurrentFile); Console.WriteLine("Progress callback = " + e.ToString()); }; request.UploadDirectoryFileRequestEvent += (s, e) => { var uploadRequest = e.UploadRequest; var key = uploadRequest.Key; keysToValidate.Add(key); SetMetadataAndHeaders(uploadRequest); }; transferUtility.UploadDirectory(request); Assert.AreEqual(5, files.Count); if (validate) { TransferUtilityTests.ValidateDirectoryContents(bucketName, directoryName, directoryPath); } }
void UploadDirectory(long size, TransferUtilityTests.DirectoryProgressValidator <UploadDirectoryProgressArgs> progressValidator, bool validate = true) { var directory = TransferUtilityTests.CreateTestDirectory(size); var directoryPath = directory.FullName; var keyPrefix = directory.Name; var config = new TransferUtilityConfig { ConcurrentServiceRequests = 10, }; var transferUtility = new TransferUtility(Client, config); var request = new TransferUtilityUploadDirectoryRequest { BucketName = bucketName, Directory = directoryPath, KeyPrefix = keyPrefix, SearchPattern = "*", SearchOption = SearchOption.AllDirectories, }; if (progressValidator != null) { request.UploadDirectoryProgressEvent += progressValidator.OnProgressEvent; } HashSet <string> files = new HashSet <string>(); request.UploadDirectoryProgressEvent += (s, e) => { files.Add(e.CurrentFile); Console.WriteLine("Progress callback = " + e.ToString()); }; request.UploadDirectoryFileRequestEvent += (s, e) => { var uploadRequest = e.UploadRequest; var key = uploadRequest.Key; keysToValidate.Add(key); SetMetadataAndHeaders(uploadRequest); }; transferUtility.UploadDirectory(request); Assert.AreEqual(5, files.Count); if (validate) { TransferUtilityTests.ValidateDirectoryContents(Client, bucketName, keyPrefix, directory); } }
public void TestDirectoryUploads() { var progressValidator = new TransferUtilityTests.DirectoryProgressValidator <UploadDirectoryProgressArgs>(); TransferUtilityTests.ConfigureProgressValidator(progressValidator); keysToValidate.Clear(); UploadDirectory(10 * TransferUtilityTests.MEG_SIZE, progressValidator, validate: true); progressValidator.AssertOnCompletion(); foreach (var key in keysToValidate) { ValidateObjectMetadataAndHeaders(key); } }