Skip to content

Commit c50fc0a

Browse files
authored
Merge pull request #2 from qiniu/master
update from source
2 parents 1570a31 + be48cfc commit c50fc0a

File tree

16 files changed

+226
-9376
lines changed

16 files changed

+226
-9376
lines changed

CHANGELOG.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
**2016-11-22**
2+
3+
最新版本v7.0.0.3,适用于.NET xx
4+
5+
(xx: 2.0/3.0/3.5/4.0/4.5/4.5.1/4.5.2/4.6/4.6.1/4.6.2)
6+
7+
增加:上传域名默认使用CDN(`Qiniu.Common.Config.UploadFromCDN:Boolean`
8+
9+
优化:应对更多类型的网络错误(`WebException`
10+
11+
优化:上传失败重试域名(`upHost`)保持不变
12+
13+
优化:上传分块数量(`blockCount`)计算优化
14+
15+
16+
* * *
17+
18+
19+
**2016-10-28**
20+
21+
优化:上传示例中增加`UpCompleteHandler`的说明
22+
23+
24+
* * *
25+
26+
27+
**2016-10-24**
28+
29+
增加:增加`listFiles`(获取空间文件列表)功能,更新示例及文档
30+
31+
32+
* * *
33+
34+
35+
**2016-10-08**
36+
37+
推出新版本v7
38+
39+
40+
* * *
41+
42+
43+
**2016-08 ~ 2016-09**
44+
45+
增加:`Zone`模块
46+
47+
增加:多机房支持(华东/华北/华南/北美)
48+
49+
增加:示例及说明文档

Qiniu/Common/Config.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ namespace Qiniu.Common
99
/// </summary>
1010
public class Config
1111
{
12-
// SDK的版本号
13-
public const string VERSION = "1.2.0";
12+
// SDK的版本号 - 更新至7.0.0.3
13+
public const string VERSION = "7.0.0.3";
1414

15+
// 上传时,是否使用CDN
16+
public static bool UploadFromCDN = true;
1517

1618
// 空间所在的区域(Zone)
1719
public static Zone ZONE = Zone.ZONE_CN_East();
@@ -60,5 +62,16 @@ public static void ConfigZone(ZoneID zoneId)
6062
}
6163
}
6264

65+
/// <summary>
66+
/// 自动配置Zone
67+
/// </summary>
68+
/// <param name="accessKey"></param>
69+
/// <param name="bucket"></param>
70+
public static void ConfigZoneAuto(string accessKey,string bucket)
71+
{
72+
ZoneID zoneId = AutoZone.Query(accessKey, bucket);
73+
ConfigZone(zoneId);
74+
}
75+
6376
}
6477
}

Qiniu/Common/Zone.cs

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -110,103 +110,4 @@ public static Zone ZONE_US_North()
110110
}
111111

112112
}
113-
114-
public class AutoZone
115-
{
116-
/// <summary>
117-
/// 从uc.qbox.me查询得到回复后,解析出upHost,然后根据upHost确定Zone
118-
/// </summary>
119-
/// <param name="accessKey">AK</param>
120-
/// <param name="bucketName">Bucket</param>
121-
public static ZoneID Query(string accessKey, string bucketName)
122-
{
123-
ZoneID zoneId = ZoneID.Default;
124-
125-
// HTTP/GET https://uc.qbox.me/v1/query?ak=(AK)&bucket=(Bucket)
126-
// 该请求的返回数据参见后面的 QueryResponse 结构
127-
// 根据response消息提取出upHost
128-
string query = string.Format("https://uc.qbox.me/v1/query?ak={0}&bucket={1}", accessKey, bucketName);
129-
130-
//不同区域upHost分别唯一,据此确定对应的Zone
131-
Dictionary<string, ZoneID> ZONE_DICT = new Dictionary<string, ZoneID>()
132-
{
133-
{"http://up.qiniu.com", ZoneID.CN_East },
134-
{"http://up-z1.qiniu.com", ZoneID.CN_North},
135-
{"http://up-z2.qiniu.com", ZoneID.CN_South},
136-
{"http://up-na0.qiniu.com", ZoneID.US_North}
137-
};
138-
139-
try
140-
{
141-
HttpWebRequest wReq = WebRequest.Create(query) as HttpWebRequest;
142-
wReq.Method = "GET";
143-
System.Net.HttpWebResponse wResp = wReq.GetResponse() as System.Net.HttpWebResponse;
144-
using (StreamReader sr = new StreamReader(wResp.GetResponseStream()))
145-
{
146-
string respData = sr.ReadToEnd();
147-
QueryResponse qr = Newtonsoft.Json.JsonConvert.DeserializeObject<QueryResponse>(respData);
148-
string upHost = qr.HTTP.UP[0];
149-
zoneId = ZONE_DICT[upHost];
150-
}
151-
wResp.Close();
152-
153-
}
154-
catch (Exception ex)
155-
{
156-
throw new Exception("ConfigZone:" + ex.Message);
157-
}
158-
159-
return zoneId;
160-
}
161-
162-
#region UC_QUERY_RESPONSE
163-
164-
// 从uc.qbox.me返回的消息,使用Json解析
165-
// 以下是一个response示例
166-
// {
167-
// "ttl" : 86400,
168-
// "http" : {
169-
// "up" : [
170-
// "http://up.qiniu.com",
171-
// "http://upload.qiniu.com",
172-
// "-H up.qiniu.com http://183.136.139.16"
173-
// ],
174-
// "io" : [
175-
// "http://iovip.qbox.me"
176-
// ]
177-
// },
178-
// "https" : {
179-
// "io" : [
180-
// "https://iovip.qbox.me"
181-
// ],
182-
// "up" : [
183-
// "https://up.qbox.me"
184-
// ]
185-
// }
186-
// }
187-
188-
/// <summary>
189-
/// 从uc.qbox.me返回的消息
190-
/// </summary>
191-
private class QueryResponse
192-
{
193-
public string TTL { get; set; }
194-
public HttpBulk HTTP { get; set; }
195-
196-
public HttpBulk HTTPS { get; set; }
197-
}
198-
199-
/// <summary>
200-
/// HttpBulk作为QueryResponse的成员
201-
/// 包含uploadHost和iovip等
202-
/// </summary>
203-
private class HttpBulk
204-
{
205-
public string[] UP { get; set; }
206-
public string[] IO { get; set; }
207-
}
208-
209-
#endregion UC_QUERY_RESPONSE
210-
}
211-
212113
}

Qiniu/Common/ZoneHelper.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
using System.IO;
5+
6+
namespace Qiniu.Common
7+
{
8+
public class AutoZone
9+
{
10+
/// <summary>
11+
/// 从uc.qbox.me查询得到回复后,解析出upHost,然后根据upHost确定Zone
12+
/// </summary>
13+
/// <param name="accessKey">AK</param>
14+
/// <param name="bucketName">Bucket</param>
15+
public static ZoneID Query(string accessKey, string bucketName)
16+
{
17+
ZoneID zoneId = ZoneID.Default;
18+
19+
// HTTP/GET https://uc.qbox.me/v1/query?ak=(AK)&bucket=(Bucket)
20+
// 该请求的返回数据参见后面的 QueryResponse 结构
21+
// 根据response消息提取出upHost
22+
string query = string.Format("https://uc.qbox.me/v1/query?ak={0}&bucket={1}", accessKey, bucketName);
23+
24+
//不同区域upHost分别唯一,据此确定对应的Zone
25+
Dictionary<string, ZoneID> ZONE_DICT = new Dictionary<string, ZoneID>()
26+
{
27+
{"http://up.qiniu.com", ZoneID.CN_East },
28+
{"http://up-z1.qiniu.com", ZoneID.CN_North},
29+
{"http://up-z2.qiniu.com", ZoneID.CN_South},
30+
{"http://up-na0.qiniu.com", ZoneID.US_North}
31+
};
32+
33+
try
34+
{
35+
HttpWebRequest wReq = WebRequest.Create(query) as HttpWebRequest;
36+
wReq.Method = "GET";
37+
System.Net.HttpWebResponse wResp = wReq.GetResponse() as System.Net.HttpWebResponse;
38+
using (StreamReader sr = new StreamReader(wResp.GetResponseStream()))
39+
{
40+
string respData = sr.ReadToEnd();
41+
QueryResponse qr = Newtonsoft.Json.JsonConvert.DeserializeObject<QueryResponse>(respData);
42+
string upHost = qr.HTTP.UP[0];
43+
zoneId = ZONE_DICT[upHost];
44+
}
45+
wResp.Close();
46+
47+
}
48+
catch (Exception ex)
49+
{
50+
throw new Exception("ConfigZone:" + ex.Message);
51+
}
52+
53+
return zoneId;
54+
}
55+
56+
#region UC_QUERY_RESPONSE
57+
58+
// 从uc.qbox.me返回的消息,使用Json解析
59+
// 以下是一个response示例
60+
// {
61+
// "ttl" : 86400,
62+
// "http" : {
63+
// "up" : [
64+
// "http://up.qiniu.com",
65+
// "http://upload.qiniu.com",
66+
// "-H up.qiniu.com http://183.136.139.16"
67+
// ],
68+
// "io" : [
69+
// "http://iovip.qbox.me"
70+
// ]
71+
// },
72+
// "https" : {
73+
// "io" : [
74+
// "https://iovip.qbox.me"
75+
// ],
76+
// "up" : [
77+
// "https://up.qbox.me"
78+
// ]
79+
// }
80+
// }
81+
82+
/// <summary>
83+
/// 从uc.qbox.me返回的消息
84+
/// </summary>
85+
private class QueryResponse
86+
{
87+
public string TTL { get; set; }
88+
public HttpBulk HTTP { get; set; }
89+
90+
public HttpBulk HTTPS { get; set; }
91+
}
92+
93+
/// <summary>
94+
/// HttpBulk作为QueryResponse的成员
95+
/// 包含uploadHost和iovip等
96+
/// </summary>
97+
private class HttpBulk
98+
{
99+
public string[] UP { get; set; }
100+
public string[] IO { get; set; }
101+
}
102+
103+
#endregion UC_QUERY_RESPONSE
104+
}
105+
}

Qiniu/Http/HttpManager.cs

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,9 @@ public void get(string pUrl, Dictionary<string, string> pHeaders,
8686
}
8787
catch(WebException wexp)
8888
{
89-
// 在 HTTP-400 错误情形下HttpWebResponse(上述vWebResp)已经为null值
90-
// 需要在此处WebException的wexp.Response中获取真实的Response内容
91-
// 2016-08-10, 18:20 FIXED by fengyh (http://fengyh.cn/)
92-
if (wexp.Status == WebExceptionStatus.ProtocolError)
93-
{
94-
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
95-
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
96-
}
89+
// FIX-HTTP 4xx/5xx Error 2016-11-22, 17:00 @fengyh
90+
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
91+
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
9792
}
9893
catch (Exception exp)
9994
{
@@ -171,12 +166,9 @@ public void postForm(string pUrl, Dictionary<string, string> pHeaders,
171166
}
172167
catch (WebException wexp)
173168
{
174-
// FIX-HTTP400E-NullWebResponse 2016-08-17, 14:57 @fengyh
175-
if (wexp.Status == WebExceptionStatus.ProtocolError)
176-
{
177-
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
178-
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
179-
}
169+
// FIX-HTTP 4xx/5xx Error 2016-11-22, 17:00 @fengyh
170+
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
171+
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
180172
}
181173
catch (Exception exp)
182174
{
@@ -249,12 +241,9 @@ public void postData(string pUrl, Dictionary<string, string> pHeaders,
249241
}
250242
catch (WebException wexp)
251243
{
252-
// FIX-HTTP400E-NullWebResponse 2016-08-17, 14:57 @fengyh
253-
if (wexp.Status == WebExceptionStatus.ProtocolError)
254-
{
255-
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
256-
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
257-
}
244+
// FIX-HTTP 4xx/5xx Error 2016-11-22, 17:00 @fengyh
245+
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
246+
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
258247
}
259248
catch (Exception exp)
260249
{
@@ -328,12 +317,9 @@ public void postData(string pUrl, Dictionary<string, string> pHeaders,
328317
}
329318
catch (WebException wexp)
330319
{
331-
// FIX-HTTP400E-NullWebResponse 2016-08-17, 14:57 @fengyh
332-
if (wexp.Status == WebExceptionStatus.ProtocolError)
333-
{
334-
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
335-
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
336-
}
320+
// FIX-HTTP 4xx/5xx Error 2016-11-22, 17:00 @fengyh
321+
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
322+
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
337323
}
338324
catch (Exception exp)
339325
{
@@ -485,12 +471,9 @@ public void postMultipartDataForm(string pUrl, Dictionary<string, string> pHeade
485471
}
486472
catch (WebException wexp)
487473
{
488-
// FIX-HTTP400E-NullWebResponse 2016-08-17, 14:57 @fengyh
489-
if (wexp.Status == WebExceptionStatus.ProtocolError)
490-
{
491-
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
492-
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
493-
}
474+
// FIX-HTTP 4xx/5xx Error 2016-11-22, 17:00 @fengyh
475+
HttpWebResponse xWebResp = wexp.Response as HttpWebResponse;
476+
handleErrorWebResponse(xWebResp, pCompletionHandler, wexp);
494477
}
495478
catch (Exception exp)
496479
{

Qiniu/Qiniu.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<Reference Include="System.Data" />
4949
<Reference Include="System.Xml" />
5050
</ItemGroup>
51-
<ItemGroup>
51+
<ItemGroup>
5252
<Compile Include="Http\HttpCode.cs" />
5353
<Compile Include="Http\HttpFileType.cs" />
5454
<Compile Include="Http\HttpFormFile.cs" />
@@ -57,6 +57,7 @@
5757
<Compile Include="Storage\Model\CdnRefreshResult.cs" />
5858
<Compile Include="Common\Config.cs" />
5959
<Compile Include="Common\Zone.cs" />
60+
<Compile Include="Common\ZoneHelper.cs" />
6061
<Compile Include="Http\CancellationSignal.cs" />
6162
<Compile Include="Http\CompletionHandler.cs" />
6263
<Compile Include="Http\HttpResult.cs" />
@@ -72,6 +73,7 @@
7273
<Compile Include="Storage\Model\BucketsResult.cs" />
7374
<Compile Include="Storage\Model\DomainsResult.cs" />
7475
<Compile Include="Storage\Model\FetchResult.cs" />
76+
<Compile Include="Storage\Model\ListFilesResult.cs" />
7577
<Compile Include="Storage\Model\StatResult.cs" />
7678
<Compile Include="Storage\Persistent\KeyGenerator.cs" />
7779
<Compile Include="Storage\Persistent\ResumeRecord.cs" />

0 commit comments

Comments
 (0)