Exemple #1
0
        public AwsManager(IAmazonS3 amazonS3, IPathManager pathManager)
        {
            if (null == amazonS3)
                throw new ArgumentNullException(nameof(amazonS3));
            if (null == pathManager)
                throw new ArgumentNullException(nameof(pathManager));

            _pathManager = pathManager;
            _amazonS3 = amazonS3;

            var storageClass = S3StorageClass.Standard;
            var storageClassString = ConfigurationManager.AppSettings["AwsStorageClass"];

            if (!string.IsNullOrWhiteSpace(storageClassString))
                storageClass = S3StorageClass.FindValue(storageClassString);

            var blobStorageClass = storageClass;
            var blobStorageClassString = ConfigurationManager.AppSettings["AwsBlobStorageClass"];

            if (!string.IsNullOrWhiteSpace(blobStorageClassString))
                blobStorageClass = S3StorageClass.FindValue(blobStorageClassString);

            var linkStorageClass = storageClass;
            var linkStorageClassString = ConfigurationManager.AppSettings["AwsLinkStorageClass"];

            if (!string.IsNullOrWhiteSpace(linkStorageClassString))
                linkStorageClass = S3StorageClass.FindValue(linkStorageClassString);

            _s3Blobs = new S3Blobs(amazonS3, pathManager, blobStorageClass);
            _s3Links = new S3Links(amazonS3, pathManager, linkStorageClass);
        }
        async Task UploadBlobAsync(AwsManager awsManager, S3Blobs.IUploadBlobRequest uploadBlobRequest, CancellationToken cancellationToken)
        {
            if (null == uploadBlobRequest)
                return;

            Console.WriteLine("Upload {0} as {1}",
                uploadBlobRequest.FileFingerprint.FullFilePath,
                uploadBlobRequest.FileFingerprint.Fingerprint.Key().Substring(0, 12));

            if (!_s3Settings.ActuallyWrite)
                return;

            try
            {
                await awsManager.UploadBlobAsync(uploadBlobRequest, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Upload of {0} failed: {1}", uploadBlobRequest.FileFingerprint.FullFilePath, ex.Message);
            }
        }
Exemple #3
0
 public Task UploadBlobAsync(S3Blobs.IUploadBlobRequest uploadBlobRequest, CancellationToken cancellationToken)
 {
     return _s3Blobs.UploadBlobAsync(uploadBlobRequest, cancellationToken);
 }