Example #1
0
        public static void AsynGetBucketLifeCycle(COSXML.CosXml cosXml, string bucket)
        {
            GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);

            //设置签名有效时长
            request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

            ///执行请求
            cosXml.GetBucketLifecycle(request,
                                      delegate(CosResult cosResult)
            {
                GetBucketLifecycleResult result = cosResult as GetBucketLifecycleResult;
                Console.WriteLine(result.GetResultInfo());
            },
                                      delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    QLog.D("XIAO", clientEx.Message);
                    Console.WriteLine("CosClientException: " + clientEx.Message);
                }
                if (serverEx != null)
                {
                    QLog.D("XIAO", serverEx.Message);
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }
            });
        }
Example #2
0
        private void GetBucketLifeCycle()
        {
            try
            {
                GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);


                //执行请求
                GetBucketLifecycleResult result = cosXml.GetBucketLifecycle(request);
                var lifecycle = result.lifecycleConfiguration;

                // Console.WriteLine(result.GetResultInfo());
                Assert.IsNotEmpty((result.GetResultInfo()));

                Assert.AreEqual(result.httpCode, 200);

                Assert.NotNull(lifecycle);
                Assert.AreEqual(lifecycle.rules.Count, 6);


                Assert.AreEqual(lifecycle.rules[0].status, "Enabled");
                Assert.NotNull(lifecycle.rules[0].filter);
                Assert.NotNull(lifecycle.rules[0].filter.filterAnd);
                Assert.NotNull(lifecycle.rules[0].filter.filterAnd.prefix);
                Assert.NotNull(lifecycle.rules[0].filter.filterAnd.tags);
                Assert.NotNull(lifecycle.rules[0].filter.filterAnd.tags[0].key);
                Assert.NotNull(lifecycle.rules[0].filter.filterAnd.tags[0].value);
                Assert.NotNull(lifecycle.rules[0].transition);
                Assert.NotZero(lifecycle.rules[0].transition.days);
                Assert.NotNull(lifecycle.rules[0].transition.storageClass);

                Assert.NotNull(lifecycle.rules[1].expiration);
                Assert.NotNull(lifecycle.rules[1].expiration.date);

                Assert.NotNull(lifecycle.rules[2].expiration);
                Assert.True(lifecycle.rules[2].expiration.expiredObjectDeleteMarker);

                Assert.NotNull(lifecycle.rules[3].abortIncompleteMultiUpload);
                Assert.NotZero(lifecycle.rules[3].abortIncompleteMultiUpload.daysAfterInitiation);

                Assert.NotNull(lifecycle.rules[4].noncurrentVersionExpiration);
                Assert.NotZero(lifecycle.rules[4].noncurrentVersionExpiration.noncurrentDays);

                Assert.NotNull(lifecycle.rules[5].noncurrentVersionTransition);
                Assert.NotZero(lifecycle.rules[5].noncurrentVersionTransition.noncurrentDays);
                Assert.NotNull(lifecycle.rules[5].noncurrentVersionTransition.storageClass);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.Fail();
            }
        }
Example #3
0
        public static void GetBucketLifeCycle(COSXML.CosXml cosXml, string bucket)
        {
            try
            {
                GetBucketLifecycleRequest request = new GetBucketLifecycleRequest(bucket);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
                //执行请求
                GetBucketLifecycleResult result = cosXml.GetBucketLifecycle(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                QLog.D("XIAO", clientEx.Message);
                Console.WriteLine("CosClientException: " + clientEx.Message);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                QLog.D("XIAO", serverEx.Message);
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }
        }