Esempio n. 1
0
        public static void GetBucketLifecycle(string bucketName)
        {
            try
            {
                var rules = client.GetBucketLifecycle(bucketName);

                Console.WriteLine("Get bucket:{0} Lifecycle succeeded ", bucketName);

                foreach (var rule in rules)
                {
                    Console.WriteLine("ID: {0}", rule.ID);
                    Console.WriteLine("Prefix: {0}", rule.Prefix);
                    Console.WriteLine("Status: {0}", rule.Status);
                    if (rule.ExpriationDays.HasValue)
                    {
                        Console.WriteLine("ExpirationDays: {0}", rule.ExpriationDays);
                    }
                    if (rule.ExpirationTime.HasValue)
                    {
                        Console.WriteLine("ExpirationTime: {0}", FormatIso8601Date(rule.ExpirationTime.Value));
                    }
                }
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
        //
        public static void GetBucketLifecycle()
        {
            var client = new OssClient("oss-cn-shenzhen.aliyuncs.com", "LTAId7dsrQHujhU5", "O3nQOqai4yXrvGCKNbvgrKuU8f7U7p");

            try
            {
                var rules = client.GetBucketLifecycle("igets");

                Console.WriteLine("Get bucket:{0} Lifecycle succeeded ", "igets");

                foreach (var rule in rules)
                {
                    Console.WriteLine("ID: {0}", rule.ID);
                    Console.WriteLine("Prefix: {0}", rule.Prefix);
                    Console.WriteLine("Status: {0}", rule.Status);
                    if (rule.ExpriationDays.HasValue)
                    {
                        Console.WriteLine("ExpirationDays: {0}", rule.ExpriationDays);
                    }
                    if (rule.ExpirationTime.HasValue)
                    {
                        Console.WriteLine("ExpirationTime: {0}", FormatIso8601Date(rule.ExpirationTime.Value));
                    }
                }
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }