Example #1
0
        /// <summary>
        /// Creates an instance with bucket name, keys and quiet flag.
        /// </summary>
        /// <param name="bucketName">bucket name</param>
        /// <param name="keys">object keys to delete</param>
        /// <param name="quiet">true: quiet mode; false: detail mode</param>
        public DeleteObjectsRequest(string bucketName, IList <string> keys, bool quiet)
        {
            if (keys == null)
            {
                throw new ArgumentException("The list of keys to be deleted should not be null");
            }

            if (keys.Count <= 0)
            {
                throw new ArgumentException("No any keys specified.");
            }

            if (keys.Count > OssUtils.DeleteObjectsUpperLimit)
            {
                throw new ArgumentException("Count of objects to be deleted exceeds upper limit");
            }

            BucketName = bucketName;

            foreach (var key in keys)
            {
                OssUtils.CheckObjectKey(key);
                Keys.Add(key);
            }

            Quiet = quiet;
        }
        public static UploadPartCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                               UploadPartRequest uploadPartRequest)
        {
            OssUtils.CheckBucketName(uploadPartRequest.BucketName);
            OssUtils.CheckObjectKey(uploadPartRequest.Key);

            if (string.IsNullOrEmpty(uploadPartRequest.UploadId))
            {
                throw new ArgumentException("uploadId should be specified");
            }
            if (!uploadPartRequest.PartNumber.HasValue)
            {
                throw new ArgumentException("partNumber should be specified");
            }
            if (!uploadPartRequest.PartSize.HasValue)
            {
                throw new ArgumentException("partSize should be specified");
            }
            if (uploadPartRequest.InputStream == null)
            {
                throw new ArgumentException("inputStream should be specified");
            }

            if (uploadPartRequest.PartSize < 0 || uploadPartRequest.PartSize > OssUtils.MaxFileSize)
            {
                throw new ArgumentException("partSize not live in valid range");
            }
            if (!OssUtils.IsPartNumberInRange(uploadPartRequest.PartNumber))
            {
                throw new ArgumentException("partNumber not live in valid range");
            }

            var conf           = OssUtils.GetClientConfiguration(client);
            var originalStream = uploadPartRequest.InputStream;
            var streamLength   = uploadPartRequest.PartSize.Value;

            // wrap input stream in PartialWrapperStream
            originalStream = new PartialWrapperStream(originalStream, streamLength);

            // setup progress
            var callback = uploadPartRequest.StreamTransferProgress;

            if (callback != null)
            {
                originalStream = OssUtils.SetupProgressListeners(originalStream, conf.ProgressUpdateInterval, client, callback);
                uploadPartRequest.InputStream = originalStream;
            }

            // wrap input stream in MD5Stream
            if (conf.EnalbeMD5Check)
            {
                var hashStream = new MD5Stream(originalStream, null, streamLength);
                uploadPartRequest.InputStream = hashStream;
                context.ResponseHandlers.Add(new MD5DigestCheckHandler(hashStream));
            }

            return(new UploadPartCommand(client, endpoint, context,
                                         DeserializerFactory.GetFactory().CreateUploadPartResultDeserializer(uploadPartRequest.PartNumber.Value),
                                         uploadPartRequest));
        }
        public static CompleteMultipartUploadCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                                            CompleteMultipartUploadRequest completeMultipartUploadRequest)
        {
            OssUtils.CheckBucketName(completeMultipartUploadRequest.BucketName);
            OssUtils.CheckObjectKey(completeMultipartUploadRequest.Key);

            if (string.IsNullOrEmpty(completeMultipartUploadRequest.UploadId))
            {
                throw new ArgumentException("The parameter is empty or null.", "uploadId");
            }

            // handle upload callback error 203
            if (completeMultipartUploadRequest.IsCallbackRequest())
            {
                context.ResponseHandlers.Add(new CallbackResponseHandler());
            }

            var conf = OssUtils.GetClientConfiguration(client);

            if (conf.EnableCrcCheck)
            {
                context.ResponseHandlers.Add(new CompleteMultipartUploadCrc64Handler(completeMultipartUploadRequest));
            }

            return(new CompleteMultipartUploadCommand(client, endpoint, context,
                                                      DeserializerFactory.GetFactory().CreateCompleteUploadResultDeserializer(completeMultipartUploadRequest),
                                                      completeMultipartUploadRequest));
        }
Example #4
0
        public static UploadPartCopyCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                                   UploadPartCopyRequest uploadPartCopyRequest)
        {
            OssUtils.CheckBucketName(uploadPartCopyRequest.SourceBucket);
            OssUtils.CheckObjectKey(uploadPartCopyRequest.SourceKey);
            OssUtils.CheckBucketName(uploadPartCopyRequest.TargetBucket);
            OssUtils.CheckObjectKey(uploadPartCopyRequest.TargetKey);

            if (!uploadPartCopyRequest.PartNumber.HasValue)
            {
                throw new ArgumentException("partNumber should be specfied");
            }
            if (!uploadPartCopyRequest.PartSize.HasValue)
            {
                throw new ArgumentException("partSize should be specfied");
            }
            if (!uploadPartCopyRequest.BeginIndex.HasValue)
            {
                throw new ArgumentException("beginIndex should be specfied");
            }

            if (uploadPartCopyRequest.PartSize < 0 || uploadPartCopyRequest.PartSize > OssUtils.MaxFileSize)
            {
                throw new ArgumentException("partSize not live in valid range");
            }
            if (!OssUtils.IsPartNumberInRange(uploadPartCopyRequest.PartNumber))
            {
                throw new ArgumentException("partNumber not live in valid range");
            }

            return(new UploadPartCopyCommand(client, endpoint, context,
                                             DeserializerFactory.GetFactory().CreateUploadPartCopyResultDeserializer(uploadPartCopyRequest.PartNumber.Value),
                                             uploadPartCopyRequest));
        }
Example #5
0
 public static SetObjectAclCommand Create(IServiceClient client, Uri endpoint,
                                          ExecutionContext context,
                                          SetObjectAclRequest request)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     return(new SetObjectAclCommand(client, endpoint, context, request));
 }
 public static DeleteObjectTaggingCommand Create(IServiceClient client, Uri endpoint,
                                                 ExecutionContext context,
                                                 DeleteObjectTaggingRequest request)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     return(new DeleteObjectTaggingCommand(client, endpoint, context, request));
 }
 private GetSymlinkCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                           IDeserializer <ServiceResponse, OssSymlink> deserializer,
                           GetSymlinkRequest request)
     : base(client, endpoint, context, deserializer)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     _request = request;
 }
Example #8
0
 public static GetObjectCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                       GetObjectRequest getObjectRequest)
 {
     OssUtils.CheckBucketName(getObjectRequest.BucketName);
     OssUtils.CheckObjectKey(getObjectRequest.Key);
     return(new GetObjectCommand(client, endpoint, context,
                                 DeserializerFactory.GetFactory().CreateGetObjectResultDeserializer(getObjectRequest),
                                 getObjectRequest));
 }
Example #9
0
 private RestoreObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                              RestoreObjectRequest request, IDeserializer <ServiceResponse, RestoreObjectResult> deserializer)
     : base(client, endpoint, context, deserializer)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     _request             = request;
     this.ParametersInUri = true; // in restore request, the parameter restore needs to be in uri
 }
 private GetObjectAclCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                             GetObjectAclRequest request,
                             IDeserializer <ServiceResponse, AccessControlList> deserializer)
     : base(client, endpoint, context, deserializer)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     _request = request;
 }
Example #11
0
        public static CopyObjectCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, CopyObjectRequest copyObjectRequest)
        {
            OssUtils.CheckBucketName(copyObjectRequest.SourceBucketName);
            OssUtils.CheckObjectKey(copyObjectRequest.SourceKey);
            OssUtils.CheckBucketName(copyObjectRequest.DestinationBucketName);
            OssUtils.CheckObjectKey(copyObjectRequest.DestinationKey);

            return(new CopyObjectCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateCopyObjectResultDeserializer(), copyObjectRequest));
        }
Example #12
0
        private DeleteObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context, string bucketName, string key)
            : base(client, endpoint, context)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(key);

            _bucketName = bucketName;
            _key        = key;
        }
Example #13
0
        /// <summary>
        /// Creates a new <see cref="CopyObjectRequest" /> instance
        /// </summary>
        /// <param name="sourceBucketName">source object's bucket name</param>
        /// <param name="sourceKey">source object key</param>
        /// <param name="destinationBucketName">destination object's bucket name</param>
        /// <param name="destinationKey">destination object key</param>
        public CopyObjectRequest(string sourceBucketName, string sourceKey, string destinationBucketName, string destinationKey)
        {
            OssUtils.CheckBucketName(destinationBucketName);
            OssUtils.CheckObjectKey(destinationKey);

            SourceBucketName      = sourceBucketName;
            SourceKey             = sourceKey;
            DestinationBucketName = destinationBucketName;
            DestinationKey        = destinationKey;
        }
Example #14
0
        private DeleteObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                    IDeserializer <ServiceResponse, DeleteObjectResult> deserialize,
                                    DeleteObjectRequest request)
            : base(client, endpoint, context, deserialize)
        {
            OssUtils.CheckBucketName(request.BucketName);
            OssUtils.CheckObjectKey(request.Key);

            _request = request;
        }
Example #15
0
        public static InitiateMultipartUploadCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                                            InitiateMultipartUploadRequest initiateMultipartUploadRequest)
        {
            OssUtils.CheckBucketName(initiateMultipartUploadRequest.BucketName);
            OssUtils.CheckObjectKey(initiateMultipartUploadRequest.Key);

            return(new InitiateMultipartUploadCommand(client, endpoint, context,
                                                      DeserializerFactory.GetFactory().CreateInitiateMultipartUploadResultDeserializer(),
                                                      initiateMultipartUploadRequest));
        }
 private GetObjectMetadataCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                  IDeserializer <ServiceResponse, ObjectMetadata> deserializer,
                                  GetObjectMetadataRequest request, bool simplifiedMetadata)
     : base(client, endpoint, context, deserializer)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     _request            = request;
     _simplifiedMetadata = simplifiedMetadata;
 }
Example #17
0
        private GetSymlinkCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                  IDeserializer <ServiceResponse, OssSymlink> deserializer,
                                  string bucketName, string symlink)
            : base(client, endpoint, context, deserializer)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(symlink);

            _bucketName = bucketName;
            _symlink    = symlink;
        }
        public GeneratePresignedUriRequest(string bucketName, string key, SignHttpMethod httpMethod)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(key);

            BucketName = bucketName;
            Key        = key;
            Method     = httpMethod;
            // Default expiration(15 minutes from now) for signed url.
            Expiration = DateTime.Now.AddMinutes(15);
        }
        private GetObjectAclCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                    string bucketName, string key,
                                    IDeserializer <ServiceResponse, AccessControlList> deserializer)
            : base(client, endpoint, context, deserializer)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(key);

            _bucketName = bucketName;
            _key        = key;
        }
        public static AbortMultipartUploadCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                                         AbortMultipartUploadRequest abortMultipartUploadRequest)
        {
            OssUtils.CheckBucketName(abortMultipartUploadRequest.BucketName);
            OssUtils.CheckObjectKey(abortMultipartUploadRequest.Key);

            if (string.IsNullOrEmpty(abortMultipartUploadRequest.UploadId))
            {
                throw new ArgumentException("ExceptionIfArgumentStringIsNullOrEmpty" /*Resources.ExceptionIfArgumentStringIsNullOrEmpty*/, "uploadId");
            }

            return(new AbortMultipartUploadCommand(client, endpoint, context, abortMultipartUploadRequest));
        }
Example #21
0
        private ProcessObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                     string bucketName, string key, string style, string o, string b = null)
            : base(client, endpoint, context)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(key);

            _bucketName          = bucketName;
            _key                 = key;
            _style               = style;
            _o                   = o;
            _b                   = b;
            this.ParametersInUri = true;
        }
        public static PutObjectCommand Create(IServiceClient client, Uri endpoint,
                                              ExecutionContext context,
                                              PutObjectRequest putObjectRequest)
        {
            OssUtils.CheckBucketName(putObjectRequest.BucketName);
            OssUtils.CheckObjectKey(putObjectRequest.Key);

            if (putObjectRequest.Content == null)
            {
                throw new ArgumentNullException("content");
            }

            // handle upload callback error 203
            if (putObjectRequest.IsCallbackRequest())
            {
                context.ResponseHandlers.Add(new CallbackResponseHandler());
            }

            var conf           = OssUtils.GetClientConfiguration(client);
            var originalStream = putObjectRequest.Content;

            // setup progress
            var callback = putObjectRequest.StreamTransferProgress;

            if (callback != null)
            {
                originalStream           = OssUtils.SetupProgressListeners(originalStream, conf.ProgressUpdateInterval, client, callback);
                putObjectRequest.Content = originalStream;
            }

            // wrap input stream in MD5Stream
            if (conf.EnalbeMD5Check)
            {
                var streamLength = originalStream.CanSeek ? originalStream.Length : -1;
                var hashStream   = new MD5Stream(originalStream, null, streamLength);
                putObjectRequest.Content = hashStream;
                context.ResponseHandlers.Add(new MD5DigestCheckHandler(hashStream));
            }
            else if (conf.EnableCrcCheck)
            {
                var streamLength = originalStream.CanSeek ? originalStream.Length : -1;
                var hashStream   = new Crc64Stream(originalStream, null, streamLength);
                putObjectRequest.Content = hashStream;
                context.ResponseHandlers.Add(new Crc64CheckHandler(hashStream));
            }

            return(new PutObjectCommand(client, endpoint, context,
                                        DeserializerFactory.GetFactory().CreatePutObjectReusltDeserializer(putObjectRequest),
                                        putObjectRequest));
        }
Example #23
0
 public static CreateSelectObjectMetaCommand Create(IServiceClient client, Uri endpoint,
                                                    ExecutionContext context,
                                                    CreateSelectObjectMetaRequest request)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     if (request.InputFormat == null)
     {
         throw new ArgumentException("InputFormat should not be null");
     }
     return(new CreateSelectObjectMetaCommand(client, endpoint, context,
                                              DeserializerFactory.GetFactory().CreateSelectObjectMetaRequestDeserializer(),
                                              request));
 }
Example #24
0
        public static CompleteMultipartUploadCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                                            CompleteMultipartUploadRequest completeMultipartUploadRequest)
        {
            OssUtils.CheckBucketName(completeMultipartUploadRequest.BucketName);
            OssUtils.CheckObjectKey(completeMultipartUploadRequest.Key);

            if (string.IsNullOrEmpty(completeMultipartUploadRequest.UploadId))
            {
                throw new ArgumentException(Resources.ExceptionIfArgumentStringIsNullOrEmpty, "uploadId");
            }

            return(new CompleteMultipartUploadCommand(client, endpoint, context,
                                                      DeserializerFactory.GetFactory().CreateCompleteUploadResultDeserializer(),
                                                      completeMultipartUploadRequest));
        }
Example #25
0
        private CreateSymlinkCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                     IDeserializer <ServiceResponse, CreateSymlinkResult> deserializer,
                                     CreateSymlinkRequest request)
            : base(client, endpoint, context, deserializer)
        {
            OssUtils.CheckBucketName(request.BucketName);
            OssUtils.CheckObjectKey(request.Symlink);
            OssUtils.CheckObjectKey(request.Target);

            if (request.Symlink == request.Target)
            {
                throw new ArgumentException("Symlink file name must be different with its target.");
            }
            _request = request;
        }
        private ListPartsCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                 IDeserializer <ServiceResponse, PartListing> deserializeMethod,
                                 ListPartsRequest listPartsRequest)
            : base(client, endpoint, context, deserializeMethod)
        {
            OssUtils.CheckBucketName(listPartsRequest.BucketName);
            OssUtils.CheckObjectKey(listPartsRequest.Key);

            if (string.IsNullOrEmpty(listPartsRequest.UploadId))
            {
                throw new ArgumentException(Resources.ExceptionIfArgumentStringIsNullOrEmpty, "uploadId");
            }

            _listPartsRequest = listPartsRequest;
        }
        public static AppendObjectCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                                 AppendObjectRequest request)
        {
            OssUtils.CheckBucketName(request.BucketName);
            OssUtils.CheckObjectKey(request.Key);

            if (request.Content == null)
            {
                throw new ArgumentNullException("request.Content");
            }

            request.ObjectMetadata = request.ObjectMetadata ?? new ObjectMetadata();
            if (request.ObjectMetadata.ContentType == null)
            {
                request.ObjectMetadata.ContentType = HttpUtils.GetContentType(request.Key, null);
            }

            var conf           = OssUtils.GetClientConfiguration(client);
            var originalStream = request.Content;
            var streamLength   = request.Content.Length;

            // setup progress
            var callback = request.StreamTransferProgress;

            if (callback != null)
            {
                originalStream  = OssUtils.SetupProgressListeners(originalStream, conf.ProgressUpdateInterval, client, callback);
                request.Content = originalStream;
            }

            // wrap input stream in MD5Stream
            if (conf.EnalbeMD5Check)
            {
                var hashStream = new MD5Stream(originalStream, null, streamLength);
                request.Content = hashStream;
                context.ResponseHandlers.Add(new MD5DigestCheckHandler(hashStream));
            }
            else if (conf.EnableCrcCheck && request.InitCrc != null)
            {
                var hashStream = new Crc64Stream(originalStream, null, streamLength, request.InitCrc.Value);
                request.Content = hashStream;
                context.ResponseHandlers.Add(new Crc64CheckHandler(hashStream));
            }

            return(new AppendObjectCommand(client, endpoint, context,
                                           DeserializerFactory.GetFactory().CreateAppendObjectReusltDeserializer(),
                                           request));
        }
Example #28
0
        private CreateSymlinkCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                     string bucketName, string symlink, string target)
            : base(client, endpoint, context)
        {
            OssUtils.CheckBucketName(bucketName);
            OssUtils.CheckObjectKey(symlink);
            OssUtils.CheckObjectKey(target);

            if (symlink == target)
            {
                throw new ArgumentException("Symlink file name must be different with its target.");
            }

            _bucketName = bucketName;
            _symlink    = symlink;
            _target     = target;
        }
        public static UploadPartCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                               UploadPartRequest uploadPartRequest)
        {
            OssUtils.CheckBucketName(uploadPartRequest.BucketName);
            OssUtils.CheckObjectKey(uploadPartRequest.Key);

            if (string.IsNullOrEmpty(uploadPartRequest.UploadId))
            {
                throw new ArgumentException("uploadId should be specified");
            }
            if (!uploadPartRequest.PartNumber.HasValue)
            {
                throw new ArgumentException("partNumber should be specified");
            }
            if (!uploadPartRequest.PartSize.HasValue)
            {
                throw new ArgumentException("partSize should be specified");
            }
            if (uploadPartRequest.InputStream == null)
            {
                throw new ArgumentException("inputStream should be specified");
            }

            if (uploadPartRequest.PartSize < 0 || uploadPartRequest.PartSize > OssUtils.MaxFileSize)
            {
                throw new ArgumentException("partSize not live in valid range");
            }
            if (!OssUtils.IsPartNumberInRange(uploadPartRequest.PartNumber))
            {
                throw new ArgumentException("partNumber not live in valid range");
            }

            if (uploadPartRequest.Md5Digest == null && uploadPartRequest.PartSize != null)
            {
                uploadPartRequest.Md5Digest = OssUtils.ComputeContentMd5(uploadPartRequest.InputStream,
                                                                         (long)uploadPartRequest.PartSize);
            }

            return(new UploadPartCommand(client, endpoint, context,
                                         DeserializerFactory.GetFactory().CreateUploadPartResultDeserializer(uploadPartRequest.PartNumber.Value),
                                         uploadPartRequest));
        }
        public static CompleteMultipartUploadCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
                                                            CompleteMultipartUploadRequest completeMultipartUploadRequest)
        {
            OssUtils.CheckBucketName(completeMultipartUploadRequest.BucketName);
            OssUtils.CheckObjectKey(completeMultipartUploadRequest.Key);

            if (string.IsNullOrEmpty(completeMultipartUploadRequest.UploadId))
            {
                throw new ArgumentException("ExceptionIfArgumentStringIsNullOrEmpty" /*Resources.ExceptionIfArgumentStringIsNullOrEmpty*/, "uploadId");
            }

            // handle upload callback error 203
            if (completeMultipartUploadRequest.IsCallbackRequest())
            {
                context.ResponseHandlers.Add(new CallbackResponseHandler());
            }

            return(new CompleteMultipartUploadCommand(client, endpoint, context,
                                                      DeserializerFactory.GetFactory().CreateCompleteUploadResultDeserializer(completeMultipartUploadRequest),
                                                      completeMultipartUploadRequest));
        }