Skip to content

Commit b7550cf

Browse files
authored
Merge pull request #41 from aliyun/restorebuket
Supports IA/Archive in CreateBucket API and Restore API
2 parents 3e4cd25 + f241587 commit b7550cf

28 files changed

+486
-37
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ language: csharp
22
solution: aliyun-oss-sdk.sln
33
mono:
44
- latest
5-
- 4.2.1
6-
- 4.0.0
5+
- 5.4.1
6+
- 4.8.1
77
- 3.12.0
8+
env:
9+
global:
10+
- MONO_IOMAP=all

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ChangeLog - Aliyun OSS SDK for C#
22

3+
## 版本号:2.6.0 日期:2017/11/30
4+
### 变更内容
5+
- 增加:CreateBucket支持StorageClass
6+
- 增加:支持RestoreObject
7+
38
## 版本号:2.5.4 日期:2017/11/17
49
### 变更内容
510
- 修复:多线程调用BeginPutObject报ObjectDisposedException的问题

README-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- OSS C# SDK[在线文档](http://gosspublic.alicdn.com/AliyunNetSDK/apidocs/latest/index.html)
1313

1414
## 版本
15-
- 当前版本:2.5.4
15+
- 当前版本:2.6.0
1616

1717
## 运行环境
1818

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- OSS C# SDK[Online Documentation](http://gosspublic.alicdn.com/AliyunNetSDK/international/apidocs/latest/index.html).
1313

1414
## Version
15-
- Current version: 2.5.4.
15+
- Current version: 2.6.0.
1616

1717
## Run environment
1818

samples/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//
2929
// You can specify all the values or you can use the default the Revision and
3030
// Build Numbers by using the '*' as shown below:
31-
[assembly: AssemblyVersion("2.5.4")]
31+
[assembly: AssemblyVersion("2.6.0")]
3232
[assembly: NeutralResourcesLanguage("zh-CN")]
33-
[assembly: AssemblyFileVersion("2.5.4")]
33+
[assembly: AssemblyFileVersion("2.6.0")]
3434

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
using System;
8+
using System.Net;
9+
using System.Threading;
10+
using Aliyun.OSS.Model;
11+
using Aliyun.OSS.Common;
12+
13+
namespace Aliyun.OSS.Samples
14+
{
15+
/// <summary>
16+
/// Sample usage of RestoreObject API
17+
/// </summary>
18+
public static class RestoreArchiveObjectSample
19+
{
20+
static string accessKeyId = Config.AccessKeyId;
21+
static string accessKeySecret = Config.AccessKeySecret;
22+
static string endpoint = Config.Endpoint;
23+
static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret);
24+
25+
public static void RestoreArchiveObject(string bucketName, string key, bool waitUtilFinished = true, int maxWaitTimeInSeconds = 600)
26+
{
27+
RestoreObjectResult result = client.RestoreObject(bucketName, key);
28+
if (result.HttpStatusCode != HttpStatusCode.Accepted || !waitUtilFinished)
29+
{
30+
throw new OssException(result.RequestId + ", " + result.HttpStatusCode + " ,");
31+
}
32+
33+
while (maxWaitTimeInSeconds > 0)
34+
{
35+
var meta = client.GetObjectMetadata(bucketName, key);
36+
string restoreStatus = meta.HttpMetadata["x-oss-restore"] as string;
37+
if (restoreStatus != null && restoreStatus.StartsWith("ongoing-request=\"false\"", StringComparison.InvariantCultureIgnoreCase))
38+
{
39+
break;
40+
}
41+
42+
Thread.Sleep(1000);
43+
maxWaitTimeInSeconds--;
44+
}
45+
46+
if (maxWaitTimeInSeconds == 0)
47+
{
48+
throw new TimeoutException();
49+
}
50+
}
51+
52+
}
53+
}

samples/aliyun-oss-sdk-samples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
</TargetFrameworkProfile>
1313
<AppDesignerFolder>Properties</AppDesignerFolder>
1414
<SignAssembly>False</SignAssembly>
15-
<DelaySign>False</DelaySign>
1615
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
1716
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
1817
<NoStdLib>False</NoStdLib>
@@ -125,6 +124,7 @@
125124
<Compile Include="Samples\SetBucketAclSample.cs" />
126125
<Compile Include="Program.cs" />
127126
<Compile Include="Properties\AssemblyInfo.cs" />
127+
<Compile Include="Samples\RestoreArchiveObjectSample.cs" />
128128
</ItemGroup>
129129
<ItemGroup>
130130
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">

sdk/Commands/CreateBucketCommand.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66

77
using System;
8+
using System.IO;
89
using Aliyun.OSS.Common.Communication;
10+
using Aliyun.OSS.Transform;
911
using Aliyun.OSS.Util;
1012

1113
namespace Aliyun.OSS.Commands
@@ -24,19 +26,35 @@ protected override string Bucket
2426
get { return _bucketName; }
2527
}
2628

29+
protected override Stream Content
30+
{
31+
get
32+
{
33+
return StorageClass == null ? null : SerializerFactory.GetFactory().CreateCreateBucketSerialization()
34+
.Serialize(StorageClass.Value);
35+
}
36+
}
37+
38+
protected StorageClass? StorageClass
39+
{
40+
get;
41+
set;
42+
}
43+
2744
private CreateBucketCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
28-
string bucketName)
45+
string bucketName, StorageClass? storageClass)
2946
: base(client, endpoint, context)
3047
{
3148
OssUtils.CheckBucketName(bucketName);
3249
_bucketName = bucketName;
50+
StorageClass = storageClass;
3351
}
3452

3553
public static CreateBucketCommand Create(IServiceClient client, Uri endpoint,
3654
ExecutionContext context,
37-
string bucketName)
55+
string bucketName, StorageClass? storageClass = null)
3856
{
39-
return new CreateBucketCommand(client, endpoint, context, bucketName);
57+
return new CreateBucketCommand(client, endpoint, context, bucketName, storageClass);
4058
}
4159
}
4260
}

sdk/Commands/OssCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ protected bool UseChunkedEncoding
6363
private set;
6464
}
6565

66+
protected bool ParametersInUri
67+
{
68+
get;
69+
set;
70+
}
71+
6672
protected OssCommand(IServiceClient client, Uri endpoint, ExecutionContext context)
6773
: this(client, endpoint, context, false)
6874
{
@@ -104,7 +110,8 @@ private ServiceRequest BuildRequest()
104110
Method = Method,
105111
Endpoint = OssUtils.MakeBucketEndpoint(Endpoint, Bucket, conf),
106112
ResourcePath = OssUtils.MakeResourcePath(Endpoint, Bucket, Key),
107-
UseChunkedEncoding = UseChunkedEncoding
113+
UseChunkedEncoding = UseChunkedEncoding,
114+
ParametersInUri = ParametersInUri
108115
};
109116

110117
foreach (var p in Parameters)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using Aliyun.OSS.Common.Communication;
10+
using Aliyun.OSS.Util;
11+
using Aliyun.OSS.Transform;
12+
using Aliyun.OSS.Properties;
13+
using Aliyun.OSS.Model;
14+
15+
namespace Aliyun.OSS.Commands
16+
{
17+
internal class RestoreObjectCommand : OssCommand<RestoreObjectResult>
18+
{
19+
private string bucketName;
20+
private string key;
21+
22+
protected override string Bucket
23+
{
24+
get {
25+
return bucketName;
26+
}
27+
}
28+
29+
protected override string Key
30+
{
31+
get {
32+
return key;
33+
}
34+
}
35+
36+
protected override HttpMethod Method
37+
{
38+
get { return HttpMethod.Post; }
39+
}
40+
41+
protected override IDictionary<string, string> Parameters
42+
{
43+
get
44+
{
45+
var parameters = new Dictionary<string, string>();
46+
parameters[RequestParameters.SUBRESOURCE_RESTORE] = null;
47+
return parameters;
48+
}
49+
}
50+
51+
private RestoreObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
52+
string bucketName, string key, IDeserializer<ServiceResponse, RestoreObjectResult> deserializer)
53+
: base(client, endpoint, context, deserializer)
54+
{
55+
OssUtils.CheckBucketName(bucketName);
56+
OssUtils.CheckObjectKey(key);
57+
58+
this.bucketName = bucketName;
59+
this.key = key;
60+
this.ParametersInUri = true; // in restore request, the parameter restore needs to be in uri
61+
}
62+
63+
public static RestoreObjectCommand Create(IServiceClient client, Uri endpoint,
64+
ExecutionContext context,
65+
string bucketName, string key)
66+
{
67+
return new RestoreObjectCommand(client, endpoint, context, bucketName, key, DeserializerFactory.GetFactory().CreateRestoreObjectResultDeserializer());
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)