コード例 #1
0
ファイル: CopyObjectRequest.cs プロジェクト: jweissBHG/Amazon
        public CopyObjectRequest(string host, S3ObjectLocation source, S3ObjectLocation target)
            : base(HttpMethod.Put, host, target.BucketName, target.Key)
        {
            Headers.Add("x-amz-copy-source", $"/{source.BucketName}/{source.Key}");

            CompletionOption = HttpCompletionOption.ResponseContentRead;
        }
コード例 #2
0
        public async Task <CopyObjectResult> PutAsync(
            string name,
            S3ObjectLocation sourceLocation,
            IReadOnlyDictionary <string, string> metadata = null)
        {
            #region Preconditions

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            #endregion

            var       retryCount    = 0;
            Exception lastException = null;

            while (retryPolicy.ShouldRetry(retryCount))
            {
                try
                {
                    return(await PutInternalAsync(name, sourceLocation, metadata).ConfigureAwait(false));
                }
                catch (S3Exception ex) when(ex.IsTransient)
                {
                    lastException = ex;
                }

                retryCount++;

                await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false);
            }

            throw new S3Exception($"Unrecoverable exception copying '{sourceLocation}' to '{name}'", lastException);
        }
コード例 #3
0
        private Task <CopyObjectResult> PutInternalAsync(
            string name,
            S3ObjectLocation sourceLocation,
            IReadOnlyDictionary <string, string> metadata = null)
        {
            var request = new CopyObjectRequest(
                host: client.Host,
                source: sourceLocation,
                target: new S3ObjectLocation(bucketName, name)
                );

            SetHeaders(request, metadata);

            return(client.CopyObjectAsync(request));
        }
コード例 #4
0
ファイル: S3Bucket.cs プロジェクト: jweissBHG/Amazon
        public async Task <CopyObjectResult> PutAsync(
            string destinationKey,
            S3ObjectLocation sourceLocation,
            IReadOnlyDictionary <string, string>?metadata = null)
        {
            if (destinationKey is null)
            {
                throw new ArgumentNullException(nameof(destinationKey));
            }

            int       retryCount = 0;
            Exception lastException;

            do
            {
                if (retryCount > 0)
                {
                    await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false);
                }

                var request = new CopyObjectRequest(
                    host: client.Host,
                    source: sourceLocation,
                    target: new S3ObjectLocation(bucketName, destinationKey)
                    );

                if (metadata != null)
                {
                    request.MetadataDirective = MetadataDirectiveValue.Replace;

                    SetHeaders(request, metadata);
                }

                try
                {
                    return(await client.CopyObjectAsync(request).ConfigureAwait(false));
                }
                catch (S3Exception ex) when(ex.IsTransient)
                {
                    lastException = ex;
                }

                retryCount++;
            }while (retryPolicy.ShouldRetry(retryCount));

            throw new S3Exception($"Error copying '{sourceLocation}' to '{destinationKey}'", lastException);
        }