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)); }
public static ListPartsCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, ListPartsRequest listPartsRequest) { return(new ListPartsCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateListPartsResultDeserializer(), listPartsRequest)); }
public static ListBucketInventoryConfigurationCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, ListBucketInventoryConfigurationRequest request) { return(new ListBucketInventoryConfigurationCommand(client, endpoint, context, request, DeserializerFactory.GetFactory().CreateListBucketInventoryConfigurationResultDeserializer())); }
public static GetObjectAclCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, string bucketName, string key) { return(new GetObjectAclCommand(client, endpoint, context, bucketName, key, DeserializerFactory.GetFactory().CreateGetAclResultDeserializer())); }
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)); }
public static GetObjectAclCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, GetObjectAclRequest request) { return(new GetObjectAclCommand(client, endpoint, context, request, DeserializerFactory.GetFactory().CreateGetAclResultDeserializer())); }
public static GetObjectMetadataCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, GetObjectMetadataRequest request, bool simplifiedMetadata) { return(new GetObjectMetadataCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateGetObjectMetadataResultDeserializer(), request, simplifiedMetadata)); }
public async Task <ObjectListing> ListObjects(ListObjectsRequest listObjectsRequest) { ObjectListing result = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { Dictionary <string, string> parameters = new Dictionary <string, string>(); if (listObjectsRequest.Prefix != null) { parameters.Add("prefix", listObjectsRequest.Prefix); } if (listObjectsRequest.Delimiter != null) { parameters.Add("delimiter", listObjectsRequest.Delimiter); } if (listObjectsRequest.Marker != null) { parameters.Add("marker", listObjectsRequest.Marker); } if (listObjectsRequest.MaxKeys != null) { parameters.Add("maxKeys", listObjectsRequest.MaxKeys.ToString()); } httpRequestMessage = new OssHttpRequestMessage(listObjectsRequest.BucketName, null, parameters); httpRequestMessage.Method = HttpMethod.Get; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); response = await httpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var temp = DeserializerFactory.GetFactory().CreateListObjectsResultDeserializer(); result = await temp.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } if (response != null) { response.Dispose(); } } return(result); }
public static CreateSymlinkCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, CreateSymlinkRequest request) { return(new CreateSymlinkCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateCreateSymlinkResultDeserializer(), request, request.ObjectMetadata)); }
public static DeleteObjectCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, DeleteObjectRequest request) { return(new DeleteObjectCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateDeleteObjectResultDeserializer(), request)); }
public static InitiateBucketWormCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, InitiateBucketWormRequest request) { return(new InitiateBucketWormCommand(client, endpoint, context, request, DeserializerFactory.GetFactory().CreateInitiateBucketWormResultDeserializer())); }
public static GetBucketLifecycleCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, string bucketName) { return(new GetBucketLifecycleCommand(client, endpoint, context, bucketName, DeserializerFactory.GetFactory().CreateGetBucketLifecycleDeserializer())); }
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 GetBucketMetadataCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, string bucketName) { return(new GetBucketMetadataCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateGetBucketMetadataResultDeserializer(), bucketName)); }
public static DeleteObjectsCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, DeleteObjectsRequest deleteObjectsRequest) { OssUtils.CheckBucketName(deleteObjectsRequest.BucketName); return(new DeleteObjectsCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateDeleteObjectsResultDeserializer(), deleteObjectsRequest)); }
public static GetLiveChannelInfoCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, GetLiveChannelInfoRequest request) { OssUtils.CheckBucketName(request.BucketName); return(new GetLiveChannelInfoCommand(client, endpoint, context, DeserializerFactory.GetFactory().CreateGetLiveChannelInfoResultDeserializer(), request)); }
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)); }
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)); }
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)); }
public async Task <CompleteMultipartUploadResult> CompleteMultipartUpload(CompleteMultipartUploadModel completeMultipartUploadModel) { CompleteMultipartUploadResult result = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("uploadId", completeMultipartUploadModel.UploadId); httpRequestMessage = new OssHttpRequestMessage(completeMultipartUploadModel.Bucket, completeMultipartUploadModel.Key, parameters); httpRequestMessage.Method = HttpMethod.Post; httpRequestMessage.Headers.Date = DateTime.UtcNow; XmlStreamSerializer <CompleteMultipartUploadModel> serializer = new XmlStreamSerializer <CompleteMultipartUploadModel>(); // FileStream fileStream = new FileStream("1.xml", FileMode.Open); //httpRequestMessage.Content = new StreamContent(fileStream); httpRequestMessage.Content = new StreamContent(serializer.Serialize(completeMultipartUploadModel)); OssRequestSigner.Sign(httpRequestMessage, networkCredential); response = await httpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var temp = DeserializerFactory.GetFactory().CreateCompMultiUploadDeserializer(); result = await temp.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } if (response != null) { response.Dispose(); } } return(result); }
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)); }
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)); }
public override void Handle(ServiceResponse response) { base.Handle(response); if (response.IsSuccessful()) { return; } // Treats NotModified(Http status code) specially. if (response.StatusCode == HttpStatusCode.NotModified) { throw ExceptionFactory.CreateException(HttpStatusCode.NotModified.ToString(), response.Failure.Message, null, null); } ErrorResult errorResult = null; try { var deserializer = DeserializerFactory.GetFactory().CreateErrorResultDeserializer(); if (deserializer == null) { // Re-throw the web exception if the response cannot be parsed. response.EnsureSuccessful(); } else { errorResult = deserializer.Deserialize(response); } } catch (XmlException) { // Re-throw the web exception if the response cannot be parsed. response.EnsureSuccessful(); } catch (InvalidOperationException) { // Re-throw the web exception if the response cannot be parsed. response.EnsureSuccessful(); } // This throw must be out of the try block because otherwise // the exception would be caught be the following catch. Debug.Assert(errorResult != null); throw ExceptionFactory.CreateException(errorResult.Code, errorResult.Message, errorResult.RequestId, errorResult.HostId); }
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)); }
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)); }
public async Task <ListPartsResult> ListMultiUploadParts(string buketName, string key, string uploadId) { ListPartsResult result = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("uploadId", uploadId); httpRequestMessage = new OssHttpRequestMessage(buketName, key, parameters); httpRequestMessage.Method = HttpMethod.Get; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); response = await httpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var temp = DeserializerFactory.GetFactory().CreateListPartsDeserialzer(); result = await temp.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } if (response != null) { response.Dispose(); } } return(result); }
public async Task <IEnumerable <Bucket> > ListBuckets() { IEnumerable <Bucket> result = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { httpRequestMessage = new OssHttpRequestMessage(OssHttpRequestMessage.NONEEDBUKETNAME, null); httpRequestMessage.Method = HttpMethod.Get; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); response = await httpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var temp = DeserializerFactory.GetFactory().CreateListBucketResultDeserializer(); result = await temp.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } if (response != null) { response.Dispose(); } } return(result); }
public async Task <ObjectMetadata> GetObjectMetadata(string bucketName, string key) { ObjectMetadata result = null; OssHttpRequestMessage httpRequestMessage = null; HttpResponseMessage response = null; try { httpRequestMessage = new OssHttpRequestMessage(bucketName, key); httpRequestMessage.Method = HttpMethod.Head; httpRequestMessage.Headers.Date = DateTime.UtcNow; OssRequestSigner.Sign(httpRequestMessage, networkCredential); response = await httpClient.SendAsync(httpRequestMessage); if (response.IsSuccessStatusCode == false) { await ErrorResponseHandler.Handle(response); } var temp = DeserializerFactory.GetFactory().CreateGetObjectMetadataResultDeserializer(); result = temp.Deserialize(response); } catch (Exception ex) { throw ex; } finally { if (httpRequestMessage != null) { httpRequestMessage.Dispose(); } if (response != null) { response.Dispose(); } } return(result); }
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)); }