/// 设置存储桶清单任务 public void PutBucketInventory() { //.cssg-snippet-body-start:[put-bucket-inventory] try { string inventoryId = "aInventoryId"; string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID PutBucketInventoryRequest putRequest = new PutBucketInventoryRequest(bucket, inventoryId); putRequest.SetDestination("CSV", "100000000001", "examplebucket-1250000000", "ap-guangzhou", "list1"); putRequest.IsEnable(true); putRequest.SetScheduleFrequency("Daily"); //执行请求 PutBucketInventoryResult putResult = cosXml.putBucketInventory(putRequest); //请求成功 Console.WriteLine(putResult.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
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(); } } }