using System; using System.Collections.Generic; using System.Text; using COSXML.CosException; using COSXML.Common; using COSXML.Utils; namespace COSXML.Model.Tag { public sealed class CopySourceStruct { /// /// cos 服务的appid /// public string appid; /// /// 存储桶名称 /// public string bucket; /// /// Bucket所属地域 /// public string region; /// /// 对象键 /// public string key; /// /// 对象的版本ID /// public string versionId; /// /// copy source with versionId /// /// /// /// /// /// public CopySourceStruct(string appid, string bucket, string region, string key, string versionId) { this.appid = appid; this.bucket = bucket; this.region = region; this.key = key; this.versionId = versionId; } /// /// copy source /// /// /// /// /// public CopySourceStruct(string appid, string bucket, string region, string key) : this(appid, bucket, region, key, null) { } /// /// check parameter /// public void CheckParameters() { if (bucket == null) { throw new CosClientException((int)CosClientError.InvalidArgument, "copy source bucket = null"); } if (key == null) { throw new CosClientException((int)CosClientError.InvalidArgument, "copy source cosPath = null"); } // if (appid == null) // { // throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "copy source appid = null"); // } if (region == null) { throw new CosClientException((int)CosClientError.InvalidArgument, "copy source region = null"); } } /// /// get source with urlEncode /// /// public string GetCopySouce() { if (!key.StartsWith("/")) { key = "/" + key; } StringBuilder copySource = new StringBuilder(); copySource.Append(bucket); if (!String.IsNullOrEmpty(appid) && !bucket.EndsWith("-" + appid)) { copySource.Append("-") .Append(appid); } copySource.Append(".").Append("cos").Append(".") .Append(region).Append(".") .Append("myqcloud.com") .Append(URLEncodeUtils.EncodePathOfURL(key)); if (versionId != null) { copySource.Append("?versionId=").Append(versionId); } return copySource.ToString(); } } }