123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
-
- using System;
- using System.Collections.Generic;
- using Aliyun.OSS.Util;
- namespace Aliyun.OSS
- {
- #pragma warning disable 618, 3005
-
-
-
- public class CopyObjectRequest
- {
- private readonly IList<string> _matchingETagConstraints = new List<string>();
- private readonly IList<string> _nonmatchingETagConstraints = new List<string>();
-
-
-
- public string SourceBucketName { get; set; }
-
-
-
-
- public string SourceKey { get; set; }
-
-
-
-
- public string DestinationBucketName { get; set; }
-
-
-
-
- public string DestinationKey { get; set; }
-
-
-
- public ObjectMetadata NewObjectMetadata { get; set; }
-
-
-
- public IList<string> MatchingETagConstraints
- {
- get { return _matchingETagConstraints; }
- }
-
-
-
- public IList<string> NonmatchingETagConstraints
- {
- get { return _nonmatchingETagConstraints; }
- }
-
-
-
-
- public DateTime? UnmodifiedSinceConstraint { get; set; }
-
-
-
-
- public DateTime? ModifiedSinceConstraint { get; set; }
-
-
-
-
-
-
-
-
- public CopyObjectRequest(string sourceBucketName, string sourceKey,
- string destinationBucketName, string destinationKey)
- {
- OssUtils.CheckBucketName(destinationBucketName);
- OssUtils.CheckObjectKey(destinationKey);
- SourceBucketName = sourceBucketName;
- SourceKey = sourceKey;
- DestinationBucketName = destinationBucketName;
- DestinationKey = destinationKey;
- }
-
- internal void Populate(IDictionary<string, string> headers)
- {
- var copyHeaderValue = OssUtils.BuildCopyObjectSource(SourceBucketName, SourceKey);
- headers.Add(OssHeaders.CopyObjectSource, copyHeaderValue);
- if (ModifiedSinceConstraint != null)
- {
- headers.Add(OssHeaders.CopySourceIfModifedSince,
- DateUtils.FormatRfc822Date(ModifiedSinceConstraint.Value));
- }
- if (UnmodifiedSinceConstraint != null)
- {
- headers.Add(OssHeaders.CopySourceIfUnmodifiedSince,
- DateUtils.FormatRfc822Date(UnmodifiedSinceConstraint.Value));
- }
- if (_matchingETagConstraints.Count > 0)
- {
- headers.Add(OssHeaders.CopySourceIfMatch, OssUtils.JoinETag(_matchingETagConstraints));
- }
- if (_nonmatchingETagConstraints.Count > 0)
- {
- headers.Add(OssHeaders.CopySourceIfNoneMatch,
- OssUtils.JoinETag(_nonmatchingETagConstraints));
- }
-
- if (NewObjectMetadata != null)
- {
- headers.Add(OssHeaders.CopyObjectMetaDataDirective, "REPLACE");
- NewObjectMetadata.Populate(headers);
- }
-
-
- headers.Remove(HttpHeaders.ContentLength);
- }
- }
- #pragma warning restore 618, 3005
- }
|