Skip to content

Commit 161ab80

Browse files
author
fengyunhai
committed
v7.0.0.5
1 parent c50fc0a commit 161ab80

30 files changed

+1353
-103
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
**2016-12-01**
2+
3+
最新版本v7.0.0.5
4+
5+
增加:[Fusion](http://developer.qiniu.com/article/index.html#fusion)相关功能
6+
7+
增加: dfop
8+
9+
修复:上传(分片上传)文件发生重试时,上传到空间的文件内容错误
10+
11+
修改:默认不使用CDN(可自行设置);重试域名和原始上传域名保持一致
12+
13+
* * *
14+
15+
116
**2016-11-22**
217

318
最新版本v7.0.0.3,适用于.NET xx

Qiniu.Test/FusionManagerTest.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Qiniu.Fusion;
4+
using Qiniu.Fusion.Model;
5+
using Qiniu.Util;
6+
7+
namespace QiniuTest
8+
{
9+
/// <summary>
10+
/// Test class of BucketManager
11+
/// </summary>
12+
[TestClass]
13+
public class FusionManagerTest
14+
{
15+
/// <summary>
16+
/// get/set
17+
/// </summary>
18+
public TestContext Instance
19+
{
20+
get;
21+
set;
22+
}
23+
24+
/// <summary>
25+
/// Test method of BucketManager
26+
/// </summary>
27+
[TestMethod]
28+
public void fusionMgrTest()
29+
{
30+
//Settings.load();
31+
Settings.LoadFromFile();
32+
string testResUrl = "http://test.fengyh.cn/qiniu/files/hello.txt";
33+
Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);
34+
FusionManager target = new FusionManager(mac);
35+
36+
//
37+
}
38+
}
39+
}

Qiniu.Test/Qiniu.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
</Choose>
6262
<ItemGroup>
6363
<Compile Include="BucketManagerTest.cs" />
64+
<Compile Include="FusionManagerTest.cs" />
6465
<Compile Include="ZoneConfigTest.cs" />
6566
<Compile Include="FormUploaderTest.cs" />
6667
<Compile Include="HttpManager2Test.cs" />

Qiniu/Common/Config.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@ namespace Qiniu.Common
33
{
44
/// <summary>
55
/// 配置信息,主要包括Zone配置
6-
/// [2016-09-05 18:10] 添加北美(US_North)机房 @fengyh
7-
/// [2016-09-23 10:26] 添加华南(CN_South)机房 @fengyh
8-
/// [2016-09-27 17:50] 更新并精简部分代码 @fengyh
96
/// </summary>
107
public class Config
118
{
12-
// SDK的版本号 - 更新至7.0.0.3
13-
public const string VERSION = "7.0.0.3";
9+
// SDK的版本号 - 更新至7.0.0.5
10+
public const string VERSION = "7.0.0.5";
1411

15-
// 上传时,是否使用CDN
16-
public static bool UploadFromCDN = true;
12+
// 上传时,是否使用CDN (默认:否)
13+
public static bool UploadFromCDN = false;
1714

1815
// 空间所在的区域(Zone)
19-
public static Zone ZONE = Zone.ZONE_CN_East();
16+
public static Zone ZONE = Zone.ZONE_Default();
2017

2118
// Fusion API
2219
public const string FUSION_API_HOST = "http://fusion.qiniuapi.com";
2320

24-
2521
//分片上传块的大小,固定为4M,不可修改
2622
public const int BLOCK_SIZE = 4 * 1024 * 1024;
2723

2824
//上传失败重试次数
29-
public const int RETRY_MAX = 5;
25+
public static int RETRY_MAX = 5;
26+
27+
// 上传重试是否启用时间间隔 (默认:否)
28+
public static bool RetryWaitForNext = false;
29+
30+
// 上传重试的时间间隔(单位:毫秒, 默认1000ms)
31+
public static int RETRY_INTERVAL_MILISEC = 1000;
3032

3133
//回复超时时间,单位微秒
3234
public const int TIMEOUT_INTERVAL = 30 * 1000;
@@ -58,10 +60,11 @@ public static void ConfigZone(ZoneID zoneId)
5860
ZONE = Zone.ZONE_US_North();
5961
break;
6062
default:
63+
ZONE = Zone.ZONE_Default();
6164
break;
6265
}
6366
}
64-
67+
6568
/// <summary>
6669
/// 自动配置Zone
6770
/// </summary>

Qiniu/Common/Zone.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public class Zone
4141
// CDN加速
4242
public string UploadHost { set; get; }
4343

44+
/// <summary>
45+
/// 默认(华东)
46+
/// </summary>
47+
/// <returns></returns>
48+
public static Zone ZONE_Default()
49+
{
50+
return ZONE_CN_East();
51+
}
52+
4453
/// <summary>
4554
/// 华东
4655
/// xx-(NULL)

Qiniu/Fusion/FusionManager.cs

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using Qiniu.Util;
6+
using Qiniu.Fusion.Model;
7+
using System.Net;
8+
using Qiniu.Http;
9+
using Newtonsoft.Json;
10+
11+
namespace Qiniu.Fusion
12+
{
13+
public class FusionManager
14+
{
15+
private Mac mac;
16+
private HttpManager httpMgr;
17+
18+
public FusionManager(Mac mac)
19+
{
20+
this.mac = mac;
21+
httpMgr = new HttpManager();
22+
}
23+
24+
private string refreshUrl()
25+
{
26+
return string.Format("{0}/v2/tune/refresh", Common.Config.FUSION_API_HOST);
27+
}
28+
29+
private string prefetchUrl()
30+
{
31+
return string.Format("{0}/v2/tune/prefetch", Common.Config.FUSION_API_HOST);
32+
}
33+
34+
private string bandwidthUrl()
35+
{
36+
return string.Format("{0}/v2/tune/bandwidth", Common.Config.FUSION_API_HOST);
37+
}
38+
39+
private string fluxUrl()
40+
{
41+
return string.Format("{0}/v2/tune/flux", Common.Config.FUSION_API_HOST);
42+
}
43+
44+
private string loglistUrl()
45+
{
46+
return string.Format("{0}/v2/tune/log/list", Common.Config.FUSION_API_HOST);
47+
}
48+
49+
/// <summary>
50+
/// 缓存刷新
51+
/// </summary>
52+
/// <param name="request"></param>
53+
/// <returns></returns>
54+
public RefreshResult Refresh(RefreshRequest request)
55+
{
56+
RefreshResult result = new RefreshResult();
57+
58+
string url = refreshUrl();
59+
string body = request.ToJsonStr();
60+
byte[] data = Encoding.UTF8.GetBytes(body);
61+
62+
string token = Auth.createManageToken(url, null, mac);
63+
64+
Dictionary<string, string> headers = new Dictionary<string, string>();
65+
headers.Add("Authorization", token);
66+
67+
httpMgr.postData(url, headers, data, HttpManager.FORM_MIME_JSON,
68+
new CompletionHandler(delegate(ResponseInfo respInfo,string respJson)
69+
{
70+
if(respInfo.StatusCode!=200)
71+
{
72+
Console.WriteLine(respInfo);
73+
}
74+
75+
result = JsonConvert.DeserializeObject<RefreshResult>(respJson);
76+
}));
77+
78+
79+
return result;
80+
}
81+
82+
/// <summary>
83+
/// 文件预取
84+
/// </summary>
85+
/// <param name="request"></param>
86+
/// <returns></returns>
87+
public PrefetchResult Prefetch(PrefetchRequest request)
88+
{
89+
PrefetchResult result = new PrefetchResult();
90+
91+
string url = prefetchUrl();
92+
string body = request.ToJsonStr();
93+
byte[] data = Encoding.UTF8.GetBytes(body);
94+
95+
string token = Auth.createManageToken(url, null, mac);
96+
97+
Dictionary<string, string> headers = new Dictionary<string, string>();
98+
headers.Add("Authorization", token);
99+
100+
httpMgr.postData(url, headers, data, HttpManager.FORM_MIME_JSON,
101+
new CompletionHandler(delegate (ResponseInfo respInfo, string respJson)
102+
{
103+
if (respInfo.StatusCode != 200)
104+
{
105+
Console.WriteLine(respInfo);
106+
}
107+
108+
result = JsonConvert.DeserializeObject<PrefetchResult>(respJson);
109+
}));
110+
111+
return result;
112+
}
113+
114+
/// <summary>
115+
/// 带宽
116+
/// </summary>
117+
/// <param name="request"></param>
118+
/// <returns></returns>
119+
public BandwidthResult Bandwidth(BandwidthRequest request)
120+
{
121+
BandwidthResult result = new BandwidthResult();
122+
123+
string url = bandwidthUrl();
124+
string body = request.ToJsonStr();
125+
byte[] data = Encoding.UTF8.GetBytes(body);
126+
127+
string token = Auth.createManageToken(url, null, mac);
128+
129+
Dictionary<string, string> headers = new Dictionary<string, string>();
130+
headers.Add("Authorization", token);
131+
132+
httpMgr.postData(url, headers, data, HttpManager.FORM_MIME_JSON,
133+
new CompletionHandler(delegate (ResponseInfo respInfo, string respJson)
134+
{
135+
if (respInfo.StatusCode != 200)
136+
{
137+
Console.WriteLine(respInfo);
138+
}
139+
140+
result = JsonConvert.DeserializeObject<BandwidthResult>(respJson);
141+
}));
142+
143+
return result;
144+
}
145+
146+
/// <summary>
147+
/// 流量
148+
/// </summary>
149+
/// <param name="request"></param>
150+
/// <returns></returns>
151+
public FluxResult Flux(FluxRequest request)
152+
{
153+
FluxResult result = new FluxResult();
154+
155+
string url = fluxUrl();
156+
string body = request.ToJsonStr();
157+
byte[] data = Encoding.UTF8.GetBytes(body);
158+
159+
string token = Auth.createManageToken(url, null, mac);
160+
161+
Dictionary<string, string> headers = new Dictionary<string, string>();
162+
headers.Add("Authorization", token);
163+
164+
httpMgr.postData(url, headers, data, HttpManager.FORM_MIME_JSON,
165+
new CompletionHandler(delegate (ResponseInfo respInfo, string respJson)
166+
{
167+
if (respInfo.StatusCode != 200)
168+
{
169+
Console.WriteLine(respInfo);
170+
}
171+
172+
result = JsonConvert.DeserializeObject<FluxResult>(respJson);
173+
}));
174+
175+
return result;
176+
}
177+
178+
/// <summary>
179+
/// 日志列表
180+
/// </summary>
181+
/// <param name="request"></param>
182+
/// <returns></returns>
183+
public LogListResult LogList(LogListRequest request)
184+
{
185+
LogListResult result = new LogListResult();
186+
187+
string url = loglistUrl();
188+
string body = request.ToJsonStr();
189+
byte[] data = Encoding.UTF8.GetBytes(body);
190+
191+
string token = Auth.createManageToken(url, null, mac);
192+
193+
Dictionary<string, string> headers = new Dictionary<string, string>();
194+
headers.Add("Authorization", token);
195+
196+
httpMgr.postData(url, headers, data, HttpManager.FORM_MIME_JSON,
197+
new CompletionHandler(delegate (ResponseInfo respInfo, string respJson)
198+
{
199+
result = JsonConvert.DeserializeObject<LogListResult>(respJson);
200+
result.Code = respInfo.StatusCode;
201+
if (respInfo.StatusCode != 200)
202+
{
203+
Console.WriteLine(respInfo);
204+
}
205+
}));
206+
207+
return result;
208+
}
209+
}
210+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Text;
2+
3+
namespace Qiniu.Fusion.Model
4+
{
5+
public class BandwidthRequest
6+
{
7+
public string StartDate { get; set; }
8+
9+
public string EndDate { get; set; }
10+
11+
public string Granularity { get; set; }
12+
13+
public string Domains { get; set; }
14+
15+
public BandwidthRequest()
16+
{
17+
StartDate = "";
18+
EndDate = "";
19+
Granularity = "";
20+
Domains = "";
21+
}
22+
23+
public BandwidthRequest(string startDate,string endDate,string granularity,string domains)
24+
{
25+
StartDate = startDate;
26+
EndDate = endDate;
27+
Granularity = granularity;
28+
Domains = domains;
29+
}
30+
31+
public string ToJsonStr()
32+
{
33+
StringBuilder sb = new StringBuilder();
34+
sb.Append("{ ");
35+
sb.AppendFormat("\"startDate\":\"{0}\", ", StartDate);
36+
sb.AppendFormat("\"endDate\":\"{0}\", ", EndDate);
37+
sb.AppendFormat("\"granularity\":\"{0}\", ", Granularity);
38+
sb.AppendFormat("\"domains\":\"{0}\"", Domains);
39+
sb.Append(" }");
40+
41+
return sb.ToString();
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)