diff --git a/QCloudCSharpSDK/COSXML/Model/Object/RestoreObjectRequest.cs b/QCloudCSharpSDK/COSXML/Model/Object/RestoreObjectRequest.cs index 73febd1..a6f1468 100644 --- a/QCloudCSharpSDK/COSXML/Model/Object/RestoreObjectRequest.cs +++ b/QCloudCSharpSDK/COSXML/Model/Object/RestoreObjectRequest.cs @@ -4,6 +4,7 @@ using System.Text; using COSXML.Model.Tag; using COSXML.Common; +using COSXML.CosException; using COSXML.Network; namespace COSXML.Model.Object @@ -27,6 +28,7 @@ public RestoreObjectRequest(string bucket, string key) this.queryParameters.Add("restore", null); restoreConfigure = new RestoreConfigure(); restoreConfigure.casJobParameters = new RestoreConfigure.CASJobParameters(); + restoreConfigure.days = 0; } /// @@ -35,12 +37,10 @@ public RestoreObjectRequest(string bucket, string key) /// public void SetExpireDays(int days) { - - if (days < 0) + if (days <= 0) { - days = 0; + throw new CosClientException(-1, "param 'Days' ranges from 1-365, Some storage types do not need call SetExpireDays function to set Days param"); } - restoreConfigure.days = days; } @@ -65,6 +65,12 @@ public void SetVersionId(string versionId) public override Network.RequestBody GetRequestBody() { + if (restoreConfigure.days == 0) + { + RestoreConfigureNoDays restoreConfigureNoDays = new RestoreConfigureNoDays(); + restoreConfigureNoDays.casJobParameters = restoreConfigure.casJobParameters; + return GetXmlRequestBody(restoreConfigureNoDays); + } return GetXmlRequestBody(restoreConfigure); } } diff --git a/QCloudCSharpSDK/COSXML/Model/Tag/RestoreConfigure.cs b/QCloudCSharpSDK/COSXML/Model/Tag/RestoreConfigure.cs index c3a118c..ddb90dc 100644 --- a/QCloudCSharpSDK/COSXML/Model/Tag/RestoreConfigure.cs +++ b/QCloudCSharpSDK/COSXML/Model/Tag/RestoreConfigure.cs @@ -45,4 +45,17 @@ public enum Tier Bulk } } + + [XmlRoot("RestoreRequest")] + public sealed class RestoreConfigureNoDays + { + /// + /// 归档存储工作参数配置 + /// + /// + [XmlElement("CASJobParameters")] + public RestoreConfigure.CASJobParameters casJobParameters; + } + + } diff --git a/QCloudCSharpSDK/COSXMLDemo/MainProcess.cs b/QCloudCSharpSDK/COSXMLDemo/MainProcess.cs index 7026aaa..ea73327 100644 --- a/QCloudCSharpSDK/COSXMLDemo/MainProcess.cs +++ b/QCloudCSharpSDK/COSXMLDemo/MainProcess.cs @@ -13,7 +13,10 @@ static void Main(string[] args) public void DoSomething() { - + // BucketPolicyModel.BucketPolicyMain(); + // DownloadObject.DownloadObjectMain(); + // UploadObject.UploadObjectMain(); + // BucketPolicyModel.BucketPolicyMain(); // DownloadObject.DownloadObjectMain(); UploadObject.UploadObjectMain(); @@ -40,13 +43,16 @@ public void DoSomething() // BucketReplicationModel.BucketReplicationMain(); // BucketLoggingModel.BucketLoggingMain(); + // BucketTaggingModel.BucketTaggingMain(); + // ObjectTaggingModel.ObjectTaggingMain(); // BucketInventoryModel.BucketInventoryMain(); // BucketDomainModel.BucketDomainMain(); // PutObjectACLModel.PutObjectACLMain();// // BucketRefererModel.BucketRefererMain();// + // BucketWebsiteModel.BucketWebsiteMain(); } diff --git a/QCloudCSharpSDK/COSXMLDemo/Object/ObjectRestore.cs b/QCloudCSharpSDK/COSXMLDemo/Object/ObjectRestore.cs index 98950a7..26eb4e9 100644 --- a/QCloudCSharpSDK/COSXMLDemo/Object/ObjectRestore.cs +++ b/QCloudCSharpSDK/COSXMLDemo/Object/ObjectRestore.cs @@ -45,6 +45,7 @@ public void RestoreObject() string key = "exampleObject"; //对象键 RestoreObjectRequest request = new RestoreObjectRequest(bucket, key); //恢复时间 + request.SetExpireDays(3); //https://cloud.tencent.com/document/product/436/12633 request.SetExpireDays(3); request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Bulk); //执行请求 diff --git a/QCloudCSharpSDK/COSXMLTests/ObjectTest.cs b/QCloudCSharpSDK/COSXMLTests/ObjectTest.cs index 45b042c..ef001e9 100644 --- a/QCloudCSharpSDK/COSXMLTests/ObjectTest.cs +++ b/QCloudCSharpSDK/COSXMLTests/ObjectTest.cs @@ -1071,8 +1071,13 @@ public void RestoreObject() cosXml.PutObject(putRequest); RestoreObjectRequest request = new RestoreObjectRequest(bucket, objectKey); - //恢复时间 - request.SetExpireDays(-1); + //恢复时间,时间参数在1-365内 + try { + request.SetExpireDays(-1); } + catch (COSXML.CosException.CosClientException clientEx) { + Assert.True(true); + } + request.SetExpireDays(3); request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Standard); @@ -1100,6 +1105,44 @@ public void RestoreObject() Assert.Fail(); } } + + + [Test()] + public void RestoreObjectNoDaysParam() + { + + + string objectKey = "archive_object"; + try + { + byte[] data = File.ReadAllBytes(smallFileSrcPath); + PutObjectRequest putRequest = new PutObjectRequest(bucket, objectKey, data); + putRequest.SetCosStorageClass("DEEP_ARCHIVE"); + cosXml.PutObject(putRequest); + RestoreObjectRequest request = new RestoreObjectRequest(bucket, objectKey); + request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Standard); + + //执行请求,该请求不设置Days参数 + RestoreObjectResult result = cosXml.RestoreObject(request); + Assert.True(result.IsSuccessful()); + request.SetVersionId("null"); + DeleteObjectRequest deleteRequest = new DeleteObjectRequest(bucket, objectKey); + deleteRequest.SetVersionId("null"); + DeleteObjectResult deleteObjectResult = cosXml.DeleteObject(deleteRequest); + Assert.True(deleteObjectResult.IsSuccessful()); + } + catch (COSXML.CosException.CosClientException clientEx) + { + Console.WriteLine("CosClientException: " + clientEx.Message); + Assert.Fail(); + } + catch (COSXML.CosException.CosServerException serverEx) + { + Console.WriteLine("CosServerException: " + serverEx.GetInfo()); + Assert.Fail(); + } + } + [Test()] public void PostObject()