Ejemplo n.º 1
0
        private static void SetBucketLifecycle()
        {
            try
            {
                SetBucketLifecycleRequest request = new SetBucketLifecycleRequest()
                {
                    BucketName    = bucketName,
                    Configuration = new LifecycleConfiguration(),
                };

                LifecycleRule rule1 = new LifecycleRule();
                rule1.Id     = "rule1";
                rule1.Prefix = "prefix";
                rule1.Status = RuleStatusEnum.Enabled;

                rule1.Expiration.Days = 30;

                Transition transition = new Transition()
                {
                    Date         = new DateTime(2018, 12, 30, 0, 0, 0),
                    StorageClass = StorageClassEnum.Warm
                };
                rule1.Transitions.Add(transition);

                NoncurrentVersionTransition noncurrentVersionTransition = new NoncurrentVersionTransition()
                {
                    NoncurrentDays = 30,
                    StorageClass   = StorageClassEnum.Cold,
                };
                rule1.NoncurrentVersionTransitions.Add(noncurrentVersionTransition);

                rule1.NoncurrentVersionExpiration.NoncurrentDays = 30;

                request.Configuration.Rules.Add(rule1);

                SetBucketLifecycleResponse response = client.SetBucketLifecycle(request);

                Console.WriteLine("Set bucket lifecycle response: {0}", response.StatusCode);
            }
            catch (ObsException ex)
            {
                Console.WriteLine("Exception errorcode: {0}, when set bucket lifecycle.", ex.ErrorCode);
                Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage);
            }
        }
Ejemplo n.º 2
0
 public LifecycleRule(AbortIncompleteMultipartUpload abortIncompleteMultipartUpload, string id,
                      Expiration expiration, Transition transition, RuleFilter filter,
                      NoncurrentVersionExpiration noncurrentVersionExpiration,
                      NoncurrentVersionTransition noncurrentVersionTransition,
                      string status)
 {
     if (!status.Equals(LIFECYCLE_RULE_STATUS_ENABLED) && !status.Equals(LIFECYCLE_RULE_STATUS_DISABLED))
     {
         throw new ArgumentException("Wrong value assignment for " + nameof(Status));
     }
     AbortIncompleteMultipartUploadObject = abortIncompleteMultipartUpload;
     ID               = id;
     Expiration       = expiration;
     TransitionObject = transition;
     Filter           = filter;
     NoncurrentVersionExpirationObject = noncurrentVersionExpiration;
     NoncurrentVersionTransitionObject = noncurrentVersionTransition;
     Status = status;
 }