using System; using System.Collections.Generic; using System.Text; using COSXML.Common; using COSXML.Model.Tag; using COSXML.CosException; namespace COSXML.Model.Object { /// /// 分片复制 /// /// public sealed class UploadPartCopyRequest : ObjectRequest { /// /// 拷贝的数据源 /// /// private CopySourceStruct copySourceStruct; /**Specified part number*/ private int partNumber = -1; /**init upload generate' s uploadId by service*/ private String uploadId = null; public UploadPartCopyRequest(string bucket, string key, int partNumber, string uploadId) : base(bucket, key) { this.method = CosRequestMethod.PUT; this.partNumber = partNumber; this.uploadId = uploadId; } /// /// 设置拷贝数据源 /// /// /// public void SetCopySource(CopySourceStruct copySource) { this.copySourceStruct = copySource; } /// /// 设置拷贝的分片范围 /// /// /// public void SetCopyRange(long start, long end) { if (start >= 0 && end >= start) { string bytes = String.Format("bytes={0}-{1}", start, end); SetRequestHeader(CosRequestHeaderKey.X_COS_COPY_SOURCE_RANGE, bytes); } } /// /// 当 Object 在指定时间后被修改,则执行操作,否则返回 412。 /// 可与 x-cos-copy-source-If-None-Match 一起使用,与其他条件联合使用返回冲突 /// /// public void SetCopyIfModifiedSince(string sourceIfModifiedSince) { if (sourceIfModifiedSince != null) { SetRequestHeader(CosRequestHeaderKey.X_COS_COPY_SOURCE_IF_MODIFIED_SINCE, sourceIfModifiedSince); } } /// /// 当 Object 在指定时间后未被修改,则执行操作,否则返回 412。 /// 可与 x-cos-copy-source-If-Match 一起使用,与其他条件联合使用返回冲突。 /// /// public void SetCopyIfUnmodifiedSince(string sourceIfUnmodifiedSince) { if (sourceIfUnmodifiedSince != null) { SetRequestHeader(CosRequestHeaderKey.X_COS_COPY_SOURCE_IF_UNMODIFIED_SINCE, sourceIfUnmodifiedSince); } } /// /// Object 的 Etag 和给定一致时,则执行操作,否则返回 412。 /// 可与 x-cos-copy-source-If-Unmodified-Since 一起使用,与其他条件联合使用返回冲突。 /// /// public void SetCopyIfMatch(string eTag) { if (eTag != null) { SetRequestHeader(CosRequestHeaderKey.X_COS_COPY_SOURCE_IF_MATCH, eTag); } } /// /// 当 Object 的 Etag 和给定不一致时,则执行操作,否则返回 412。 /// 可与 x-cos-copy-source-If-Modified-Since 一起使用,与其他条件联合使用返回冲突 /// /// public void SetCopyIfNoneMatch(string eTag) { if (eTag != null) { SetRequestHeader(CosRequestHeaderKey.X_COS_COPY_SOURCE_IF_NONE_MATCH, eTag); } } public override void CheckParameters() { if (copySourceStruct == null) { throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "copy source = null"); } else { copySourceStruct.CheckParameters(); } if (requestUrlWithSign != null) return; base.CheckParameters(); if (partNumber <= 0) { throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "partNumber < 1"); } if (uploadId == null) { throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "uploadID = null"); } } protected override void InternalUpdateQueryParameters() { try { this.queryParameters.Add("partNumber", partNumber.ToString()); } catch (ArgumentException) { this.queryParameters["partNumber"] = partNumber.ToString(); } try { this.queryParameters.Add("uploadId", uploadId); } catch (ArgumentException) { this.queryParameters["uploadId"] = uploadId; } } protected override void InteranlUpdateHeaders() { try { this.headers.Add(CosRequestHeaderKey.X_COS_COPY_SOURCE, copySourceStruct.GetCopySouce()); } catch (ArgumentException) { this.headers[CosRequestHeaderKey.X_COS_COPY_SOURCE] = copySourceStruct.GetCopySouce(); } } } }