Пример #1
0
        /// 获取存储桶清单任务
        public void GetBucketInventory()
        {
            //.cssg-snippet-body-start:[get-bucket-inventory]
            try
            {
                string inventoryId = "aInventoryId";
                string bucket      = "examplebucket-1250000000"; //格式:BucketName-APPID
                GetBucketInventoryRequest getRequest = new GetBucketInventoryRequest(bucket);
                getRequest.SetInventoryId(inventoryId);

                GetBucketInventoryResult getResult = cosXml.getBucketInventory(getRequest);

                InventoryConfiguration configuration = getResult.inventoryConfiguration;
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                //请求失败
                Console.WriteLine("CosClientException: " + clientEx);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                //请求失败
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }
            //.cssg-snippet-body-end
        }
Пример #2
0
        public void TestBucketInventory()
        {
            try
            {
                string inventoryId = "id1";

                PutBucketInventoryRequest putRequest = new PutBucketInventoryRequest(bucket, inventoryId);

                putRequest.IsEnable(true);
                putRequest.SetScheduleFrequency("Daily");
                putRequest.SetIncludedObjectVersions("All");
                putRequest.SetDestination("CSV", QCloudServer.Instance().uin, QCloudServer.Instance().bucketForObjectTest, region, "list1");
                putRequest.SetFilter("dir/");
                putRequest.SetOptionalFields("SIZE");
                putRequest.SetOptionalFields("ETag");
                putRequest.EnableSSE();
                PutBucketInventoryResult putResult = cosXml.PutBucketInventory(putRequest);

                Assert.IsTrue(putResult.httpCode == 200);

                GetBucketInventoryRequest getRequest = new GetBucketInventoryRequest(bucket);

                getRequest.SetInventoryId(inventoryId);
                GetBucketInventoryResult getResult  = cosXml.GetBucketInventory(getRequest);
                InventoryConfiguration   testConfig = getResult.inventoryConfiguration;

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

                ListBucketInventoryRequest listRequest = new ListBucketInventoryRequest(bucket);
                ListBucketInventoryResult  listResult  = cosXml.ListBucketInventory(listRequest);
                Assert.IsTrue(listResult.httpCode == 200);
                Assert.NotNull(listResult.GetResultInfo());
                Assert.IsEmpty(listResult.listInventoryConfiguration.continuationToken);
                Assert.False(listResult.listInventoryConfiguration.isTruncated);
                Assert.AreEqual(listResult.listInventoryConfiguration.inventoryConfigurations.Count, 1);
                InventoryConfiguration testConfig2 = listResult.listInventoryConfiguration.inventoryConfigurations[0];

                InventoryConfiguration[] configurations = new InventoryConfiguration[] { testConfig, testConfig2 };

                foreach (InventoryConfiguration configuration in configurations)
                {
                    Assert.NotNull(configuration);
                    Assert.NotNull(configuration.destination.cosBucketDestination.accountId);
                    Assert.NotNull(configuration.destination.cosBucketDestination.bucket);
                    Assert.NotNull(configuration.destination.cosBucketDestination.encryption.sSECOS);
                    Assert.NotNull(configuration.destination.cosBucketDestination.format);
                    Assert.NotNull(configuration.destination.cosBucketDestination.prefix);
                    Assert.True(configuration.isEnabled);
                    Assert.NotNull(configuration.schedule.frequency);
                    Assert.NotNull(configuration.includedObjectVersions);
                    Assert.NotNull(configuration.filter.prefix);
                    Assert.AreEqual(configuration.optionalFields.fields.Count, 2);
                }

                DeleteBucketInventoryRequest deleteRequest = new DeleteBucketInventoryRequest(bucket);

                deleteRequest.SetInventoryId(inventoryId);
                DeleteBucketInventoryResult deleteResult = cosXml.DeleteBucketInventory(deleteRequest);
                Assert.IsTrue(putResult.httpCode == 200);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());

                if (serverEx.statusCode != 409 && serverEx.statusCode != 451)
                {
                    Assert.Fail();
                }
            }
        }
Пример #3
0
 public void GetBucketInventoryAsync(GetBucketInventoryRequest request, OnSuccessCallback <CosResult> successCallback, OnFailedCallback failCallback)
 {
     Schedue(request, new Model.Bucket.GetBucketInventoryResult(), successCallback, failCallback);
 }
Пример #4
0
 public GetBucketInventoryResult GetBucketInventory(GetBucketInventoryRequest request)
 {
     return((Model.Bucket.GetBucketInventoryResult)Excute(request, new Model.Bucket.GetBucketInventoryResult()));
 }