Exemplo n.º 1
0
        public async Task <Uri> PrepareResourceAsync(string containerId, string fileName, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNullOrEmpty(containerId, nameof(containerId));
            EnsureArg.IsNotNullOrEmpty(fileName, nameof(fileName));

            try
            {
                return(await _integrationStoreRetryExceptionPolicyFactory
                       .RetryPolicy
                       .ExecuteAsync(async() =>
                {
                    CloudBlobClient cloudBlobClient = await _integrationDataStoreClientInitializer.GetAuthorizedClientAsync(cancellationToken);
                    CloudBlobContainer container = cloudBlobClient.GetContainerReference(containerId);

                    await container.CreateIfNotExistsAsync(cancellationToken);

                    CloudBlob blob = container.GetBlobReference(fileName);

                    return blob.Uri;
                }));
            }
            catch (StorageException storageEx)
            {
                _logger.LogInformation(storageEx, "Failed to create container for {0}:{1}", containerId, fileName);

                HttpStatusCode statusCode = StorageExceptionParser.ParseStorageException(storageEx);
                throw new IntegrationDataStoreException(storageEx.Message, statusCode);
            }
        }
Exemplo n.º 2
0
        public async Task <Dictionary <string, object> > GetPropertiesAsync(Uri resourceUri, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(resourceUri, nameof(resourceUri));

            try
            {
                return(await _integrationStoreRetryExceptionPolicyFactory
                       .RetryPolicy
                       .ExecuteAsync(async() =>
                {
                    CloudBlobClient cloudBlobClient = await _integrationDataStoreClientInitializer.GetAuthorizedClientAsync(cancellationToken);
                    ICloudBlob blob = await cloudBlobClient.GetBlobReferenceFromServerAsync(resourceUri);

                    Dictionary <string, object> result = new Dictionary <string, object>();
                    result[IntegrationDataStoreClientConstants.BlobPropertyETag] = blob.Properties.ETag;
                    result[IntegrationDataStoreClientConstants.BlobPropertyLength] = blob.Properties.Length;

                    return result;
                }));
            }
            catch (StorageException storageEx)
            {
                _logger.LogInformation(storageEx, "Failed to get properties of blob {0}", resourceUri);

                HttpStatusCode statusCode = StorageExceptionParser.ParseStorageException(storageEx);
                throw new IntegrationDataStoreException(storageEx.Message, statusCode);
            }
        }
        public void GivenNoRequestInformationAndUnknownHostMessage_WhenParseStorageException_ThenReturnsBadRequest()
        {
            StorageException ex = new StorageException("No such host is known");

            var resultCode = StorageExceptionParser.ParseStorageException(ex);

            Assert.Equal(HttpStatusCode.BadRequest, resultCode);
        }
        public void GivenInValidStatusCode_WhenParseStorageException_ThenReturnsInternalServerError(int statusCode)
        {
            RequestResult requestResult = new RequestResult {
                HttpStatusCode = statusCode
            };
            StorageException ex = new StorageException(requestResult, "exception message", new Exception("inner exception message"));

            var resultCode = StorageExceptionParser.ParseStorageException(ex);

            Assert.Equal(HttpStatusCode.InternalServerError, resultCode);
        }
        public void GivenValidErrorStatusCode_WhenParseStorageException_ThenCorrespondingHttpStatusCode(HttpStatusCode statusCode)
        {
            RequestResult requestResult = new RequestResult {
                HttpStatusCode = (int)statusCode
            };
            StorageException ex = new StorageException(requestResult, "exception message", new Exception("inner exception message"));

            var resultCode = StorageExceptionParser.ParseStorageException(ex);

            Assert.Equal(statusCode, resultCode);
        }
Exemplo n.º 6
0
        public async Task AppendCommitAsync(Uri resourceUri, string[] blockIds, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(resourceUri, nameof(resourceUri));
            EnsureArg.IsNotNull(blockIds, nameof(blockIds));

            try
            {
                await _integrationStoreRetryExceptionPolicyFactory
                .RetryPolicy
                .ExecuteAsync(async() =>
                {
                    CloudBlockBlob blob = await GetCloudBlobClientAsync(resourceUri, cancellationToken);
                    await AppendCommitInternalAsync(blob, blockIds, cancellationToken);
                });
            }
            catch (StorageException storageEx)
            {
                _logger.LogInformation(storageEx, "Failed to append commit for {0}", resourceUri);

                HttpStatusCode statusCode = StorageExceptionParser.ParseStorageException(storageEx);
                throw new IntegrationDataStoreException(storageEx.Message, statusCode);
            }
        }
Exemplo n.º 7
0
        public async Task UploadBlockAsync(Uri resourceUri, Stream stream, string blockId, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(resourceUri, nameof(resourceUri));
            EnsureArg.IsNotNull(stream, nameof(stream));
            EnsureArg.IsNotNullOrEmpty(blockId, nameof(blockId));

            try
            {
                await _integrationStoreRetryExceptionPolicyFactory
                .RetryPolicy
                .ExecuteAsync(async() =>
                {
                    CloudBlockBlob blob = await GetCloudBlobClientAsync(resourceUri, cancellationToken);
                    await UploadBlockInternalAsync(blob, stream, blockId, cancellationToken);
                });
            }
            catch (StorageException storageEx)
            {
                _logger.LogInformation(storageEx, "Failed to upload data for {0}", resourceUri);

                HttpStatusCode statusCode = StorageExceptionParser.ParseStorageException(storageEx);
                throw new IntegrationDataStoreException(storageEx.Message, statusCode);
            }
        }