Esempio n. 1
0
        public void DirectoryTesting()
        {
            var directory     = TransferUtilityTests.CreateTestDirectory(10 * TransferUtilityTests.KILO_SIZE);
            var keyPrefix     = directory.Name;
            var directoryPath = directory.FullName;

            using (var transferUtility = new Amazon.S3.Transfer.TransferUtility(s3EncryptionClientFileMode))
            {
                TransferUtilityUploadDirectoryRequest uploadRequest = CreateUploadDirRequest(directoryPath, keyPrefix);
                transferUtility.UploadDirectory(uploadRequest);

                var newDir = TransferUtilityTests.GenerateDirectoryPath();
                transferUtility.DownloadDirectory(bucketName, keyPrefix, newDir);
                TransferUtilityTests.ValidateDirectoryContents(s3EncryptionClientFileMode, bucketName, keyPrefix, directory);
            }

            using (var transferUtility = new Amazon.S3.Transfer.TransferUtility(s3EncryptionClientMetadataMode))
            {
                TransferUtilityUploadDirectoryRequest uploadRequest = CreateUploadDirRequest(directoryPath, keyPrefix);
                transferUtility.UploadDirectory(uploadRequest);

                var newDir = TransferUtilityTests.GenerateDirectoryPath();
                transferUtility.DownloadDirectory(bucketName, keyPrefix, newDir);
                TransferUtilityTests.ValidateDirectoryContents(s3EncryptionClientMetadataMode, bucketName, keyPrefix, directory);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
            }
        }