Skip to content

Commit 4a670da

Browse files
authored
Merge pull request #50 from aliyun/crc
Add Crc Test Cases
2 parents d32f076 + 263981a commit 4a670da

30 files changed

+1015
-25
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
13+
namespace Aliyun.OSS.Commands
14+
{
15+
internal class GetBucketLocationCommand : OssCommand<BucketLocationResult>
16+
{
17+
private readonly string _bucketName;
18+
19+
protected override string Bucket
20+
{
21+
get { return _bucketName; }
22+
}
23+
24+
private GetBucketLocationCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
25+
string bucketName, IDeserializer<ServiceResponse, BucketLocationResult> deserializer)
26+
: base(client, endpoint, context, deserializer)
27+
{
28+
OssUtils.CheckBucketName(bucketName);
29+
_bucketName = bucketName;
30+
}
31+
32+
public static GetBucketLocationCommand Create(IServiceClient client, Uri endpoint,
33+
ExecutionContext context,
34+
string bucketName)
35+
{
36+
return new GetBucketLocationCommand(client, endpoint, context, bucketName,
37+
DeserializerFactory.GetFactory().CreateGetBucketLocationResultDeserializer());
38+
}
39+
40+
protected override IDictionary<string, string> Parameters
41+
{
42+
get
43+
{
44+
return new Dictionary<string, string>()
45+
{
46+
{ RequestParameters.SUBRESOURCE_LOCATION, null }
47+
};
48+
}
49+
}
50+
}
51+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
using System;
8+
using Aliyun.OSS.Common.Communication;
9+
using Aliyun.OSS.Util;
10+
using Aliyun.OSS.Transform;
11+
using System.Collections.Generic;
12+
13+
namespace Aliyun.OSS.Commands
14+
{
15+
internal class GetBucketMetadataCommand : OssCommand<BucketMetadata>
16+
{
17+
private readonly string _bucketName;
18+
19+
protected override HttpMethod Method
20+
{
21+
get { return HttpMethod.Head; }
22+
}
23+
24+
protected override string Bucket
25+
{
26+
get { return _bucketName; }
27+
}
28+
29+
private GetBucketMetadataCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
30+
IDeserializer<ServiceResponse, BucketMetadata> deserializer,
31+
string bucketName)
32+
: base(client, endpoint, context, deserializer)
33+
{
34+
OssUtils.CheckBucketName(bucketName);
35+
36+
_bucketName = bucketName;
37+
}
38+
39+
public static GetBucketMetadataCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context,
40+
string bucketName)
41+
{
42+
return new GetBucketMetadataCommand(client, endpoint, context,
43+
DeserializerFactory.GetFactory().CreateGetBucketMetadataResultDeserializer(),
44+
bucketName);
45+
}
46+
}
47+
48+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
13+
namespace Aliyun.OSS.Commands
14+
{
15+
internal class GetBucketStorageCapacityCommand : OssCommand<GetBucketStorageCapacityResult>
16+
{
17+
private readonly string _bucketName;
18+
19+
protected override string Bucket
20+
{
21+
get { return _bucketName; }
22+
}
23+
24+
private GetBucketStorageCapacityCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
25+
string bucketName, IDeserializer<ServiceResponse, GetBucketStorageCapacityResult> deserializer)
26+
: base(client, endpoint, context, deserializer)
27+
{
28+
OssUtils.CheckBucketName(bucketName);
29+
_bucketName = bucketName;
30+
}
31+
32+
public static GetBucketStorageCapacityCommand Create(IServiceClient client, Uri endpoint,
33+
ExecutionContext context,
34+
string bucketName)
35+
{
36+
return new GetBucketStorageCapacityCommand(client, endpoint, context, bucketName,
37+
DeserializerFactory.GetFactory().CreateGetBucketStorageCapacityResultDeserializer());
38+
}
39+
40+
protected override IDictionary<string, string> Parameters
41+
{
42+
get
43+
{
44+
return new Dictionary<string, string>()
45+
{
46+
{ RequestParameters.SUBRESOURCE_QOS, null }
47+
};
48+
}
49+
}
50+
}
51+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
using System;
8+
using System.IO;
9+
using System.Collections.Generic;
10+
11+
using Aliyun.OSS.Common.Communication;
12+
using Aliyun.OSS.Util;
13+
using Aliyun.OSS.Transform;
14+
15+
namespace Aliyun.OSS.Commands
16+
{
17+
internal class SetBucketStorageCapacityCommand : OssCommand
18+
{
19+
private readonly string _bucketName;
20+
private readonly SetBucketStorageCapacityRequest _setBucketStorageCapacityRequest;
21+
22+
protected override HttpMethod Method
23+
{
24+
get { return HttpMethod.Put; }
25+
}
26+
27+
protected override string Bucket
28+
{
29+
get { return _bucketName; }
30+
}
31+
32+
private SetBucketStorageCapacityCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
33+
string bucketName, SetBucketStorageCapacityRequest setBucketStorageCapacityRequest)
34+
: base(client, endpoint, context)
35+
{
36+
OssUtils.CheckBucketName(bucketName);
37+
if (setBucketStorageCapacityRequest.StorageCapacity < -1)
38+
throw new ArgumentException("storage capacity must greater than -1");
39+
40+
_bucketName = bucketName;
41+
_setBucketStorageCapacityRequest = setBucketStorageCapacityRequest;
42+
}
43+
44+
public static SetBucketStorageCapacityCommand Create(IServiceClient client, Uri endpoint,
45+
ExecutionContext context,
46+
string bucketName, SetBucketStorageCapacityRequest setBucketStorageCapacityRequest)
47+
{
48+
return new SetBucketStorageCapacityCommand(client, endpoint, context, bucketName, setBucketStorageCapacityRequest);
49+
}
50+
51+
52+
protected override IDictionary<string, string> Parameters
53+
{
54+
get
55+
{
56+
return new Dictionary<string, string>()
57+
{
58+
{ RequestParameters.SUBRESOURCE_QOS, null }
59+
};
60+
}
61+
}
62+
protected override Stream Content
63+
{
64+
get
65+
{
66+
return SerializerFactory.GetFactory().CreateSetBucketStorageCapacityRequestSerializer()
67+
.Serialize(_setBucketStorageCapacityRequest);
68+
}
69+
}
70+
}
71+
}

sdk/Common/Handlers/CompleteMultipartUploadCrc64Handler.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ public CompleteMultipartUploadCrc64Handler(CompleteMultipartUploadRequest reques
2222

2323
public override void Handle(Communication.ServiceResponse response)
2424
{
25+
2526
if (response.Headers.ContainsKey(HttpHeaders.HashCrc64Ecma))
2627
{
2728
ulong crc64 = 0;
29+
bool checkCrc = true;
2830
foreach (var part in _request.PartETags)
2931
{
30-
crc64 = Crc64.Combine(crc64, ulong.Parse(part.Crc64), part.Length);
32+
if (!String.IsNullOrEmpty(part.Crc64) && part.Length != 0)
33+
{
34+
crc64 = Crc64.Combine(crc64, ulong.Parse(part.Crc64), part.Length);
35+
}
36+
else
37+
{
38+
checkCrc = false;
39+
}
40+
}
41+
42+
if (!checkCrc) // the request does not have CRC64 for at least one part, skip the check
43+
{
44+
return;
3145
}
3246

3347
var ossCalculatedHashStr = response.Headers[HttpHeaders.HashCrc64Ecma];

sdk/Domain/BucketLocationResult.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
using Aliyun.OSS.Model;
8+
9+
namespace Aliyun.OSS
10+
{
11+
/// <summary>
12+
/// The result class of the operation to get bucket's location.
13+
/// </summary>
14+
public class BucketLocationResult : GenericResult
15+
{
16+
/// <summary>
17+
/// The bucket location.
18+
/// </summary>
19+
public string Location { get; internal set; }
20+
}
21+
}

sdk/Domain/BucketMetadata.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Net;
10+
using Aliyun.OSS.Util;
11+
12+
namespace Aliyun.OSS
13+
{
14+
/// <summary>
15+
/// OSS bucket's metadata, which is the collection of 'key,value' pair.
16+
/// </summary>
17+
public class BucketMetadata
18+
{
19+
private readonly IDictionary<string, string> _metadata =
20+
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
21+
22+
/// <summary>
23+
/// Gets HTTP standard headers and their values.
24+
/// </summary>
25+
public IDictionary<string, string> HttpMetadata
26+
{
27+
get { return _metadata; }
28+
}
29+
30+
/// <summary>
31+
/// Gets or sets the bucket region(location)
32+
/// </summary>
33+
public string BucketRegion
34+
{
35+
get
36+
{
37+
return _metadata.ContainsKey(HttpHeaders.BucketRegion)
38+
? _metadata[HttpHeaders.BucketRegion] : null;
39+
}
40+
set
41+
{
42+
_metadata[HttpHeaders.BucketRegion] = value;
43+
}
44+
45+
}
46+
47+
/// <summary>
48+
/// Adds one HTTP header and its value.
49+
/// </summary>
50+
/// <param name="key">header name</param>
51+
/// <param name="value">header value</param>
52+
public void AddHeader(string key, string value)
53+
{
54+
_metadata.Add(key, value);
55+
}
56+
}
57+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
using Aliyun.OSS.Model;
8+
9+
namespace Aliyun.OSS
10+
{
11+
/// <summary>
12+
/// The result class of the operation to get bucket's storage capacity.
13+
/// </summary>
14+
public class GetBucketStorageCapacityResult : GenericResult
15+
{
16+
/// <summary>
17+
/// The bucket storage capacity.
18+
/// </summary>
19+
public long StorageCapacity { get; internal set; }
20+
}
21+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) Alibaba Cloud Computing
3+
* All rights reserved.
4+
*
5+
*/
6+
7+
namespace Aliyun.OSS
8+
{
9+
/// <summary>
10+
/// The request class of the operation to set the bucket storage capacity
11+
/// </summary>
12+
public class SetBucketStorageCapacityRequest
13+
{
14+
/// <summary>
15+
/// Gets the bucket name
16+
/// </summary>
17+
public string BucketName { get; private set; }
18+
19+
/// <summary>
20+
/// The bucket storage capacity
21+
/// </summary>
22+
public long StorageCapacity { get; private set; }
23+
24+
/// <summary>
25+
/// Creates a new instance of <see cref="SetBucketStorageCapacityRequest" />.
26+
/// </summary>
27+
/// <param name="bucketName"><see cref="OssObject" />bucket name</param>
28+
/// <param name="storageCapacity">storage capacity</param>
29+
public SetBucketStorageCapacityRequest(string bucketName, long storageCapacity)
30+
{
31+
BucketName = bucketName;
32+
StorageCapacity = storageCapacity;
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)