From 9dfb1fe1f9fbd70d3a289921eccfeae173b45eb9 Mon Sep 17 00:00:00 2001
From: zheniantoushipashi <1319027852@qq.com>
Date: Tue, 26 Aug 2014 15:09:12 +0800
Subject: [PATCH 1/7] change the init method int class config.cs in case the
config be null
---
Qiniu/Conf/Config.cs | 37 +++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)
diff --git a/Qiniu/Conf/Config.cs b/Qiniu/Conf/Config.cs
index e5892c81..6a31619a 100644
--- a/Qiniu/Conf/Config.cs
+++ b/Qiniu/Conf/Config.cs
@@ -44,15 +44,36 @@ public class Config
///
/// 初始化七牛帐户、请求地址等信息,不应在客户端调用。
///
- public static void Init()
+ public static void Init()
{
- USER_AGENT = System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"];
- ACCESS_KEY = System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"];
- SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"];
- RS_HOST = System.Configuration.ConfigurationManager.AppSettings["RS_HOST"];
- UP_HOST = System.Configuration.ConfigurationManager.AppSettings["UP_HOST"];
- RSF_HOST = System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"];
- PREFETCH_HOST = System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"];
+ if (System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"] != null)
+ {
+ USER_AGENT = System.Configuration.ConfigurationManager.AppSettings["USER_AGENT"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"] != null)
+ {
+ ACCESS_KEY = System.Configuration.ConfigurationManager.AppSettings["ACCESS_KEY"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"] != null)
+ {
+ SECRET_KEY = System.Configuration.ConfigurationManager.AppSettings["SECRET_KEY"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["RS_HOST"] != null)
+ {
+ RS_HOST = System.Configuration.ConfigurationManager.AppSettings["RS_HOST"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["UP_HOST"] != null)
+ {
+ UP_HOST = System.Configuration.ConfigurationManager.AppSettings["UP_HOST"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"] != null)
+ {
+ RSF_HOST = System.Configuration.ConfigurationManager.AppSettings["RSF_HOST"];
+ }
+ if (System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"] != null)
+ {
+ PREFETCH_HOST = System.Configuration.ConfigurationManager.AppSettings["PREFETCH_HOST"];
+ }
}
private static string getUa()
{
From f7f241f8ce10b2dbae569cde15a37658db319f62 Mon Sep 17 00:00:00 2001
From: zheniantoushipashi <1319027852@qq.com>
Date: Mon, 17 Nov 2014 16:40:16 +0800
Subject: [PATCH 2/7] add mkzip class
---
Qiniu/PFOP/Mkzip.cs | 69 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 Qiniu/PFOP/Mkzip.cs
diff --git a/Qiniu/PFOP/Mkzip.cs b/Qiniu/PFOP/Mkzip.cs
new file mode 100644
index 00000000..71a3be4f
--- /dev/null
+++ b/Qiniu/PFOP/Mkzip.cs
@@ -0,0 +1,69 @@
+using Qiniu.Auth;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Qiniu.RS;
+using Qiniu.RPC;
+using Qiniu.Conf;
+using Qiniu.Util;
+using Newtonsoft.Json;
+
+namespace Qiniu.PFOP
+{
+ public class Mkzip
+ {
+
+ ///
+ /// 多文件压缩存储为用户提供了批量文件的压缩存储功能
+ /// POST /pfop/ HTTP/1.1
+ /// Host: api.qiniu.com
+ /// Content-Type: application/x-www-form-urlencoded
+ /// Authorization:
+ /// bucket =
+ /// mkzip/
+ /// /url/
+ /// /alias/
+ /// /url/
+ /// ...
+ ///
+ public String doMkzip(String bucket, String existKey, String newFileName, String[] urls, string pipeline)
+ {
+ if (bucket == null || string.IsNullOrEmpty(existKey) || string.IsNullOrEmpty(newFileName) || urls.Length < 0 || pipeline == null)
+ {
+ throw new Exception("params error");
+ }
+ String entryURI = bucket + ":" + newFileName;
+ String urlString = "";
+ for (int i = 0; i < urls.Length; i++)
+ {
+ String urlEntry = "/url/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(urls[i]);
+ urlString += urlEntry;
+ }
+ String fop = System.Web.HttpUtility.UrlEncode("mkzip/1" + urlString + "|saveas/" + Qiniu.Util.Base64URLSafe.ToBase64URLSafe(entryURI));
+
+ string body = string.Format("bucket={0}&key={1}&fops={2}&pipeline={3}", bucket, existKey, fop, pipeline);
+
+ System.Text.Encoding curEncoding = System.Text.Encoding.UTF8;
+
+ QiniuAuthClient authClient = new QiniuAuthClient();
+ CallRet ret = authClient.CallWithBinary(Config.API_HOST + "/pfop/", "application/x-www-form-urlencoded", StreamEx.ToStream(body), body.Length);
+ if (ret.OK)
+ {
+ try
+ {
+ PersistentId pid = JsonConvert.DeserializeObject(ret.Response);
+ return pid.persistentId;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ }
+ else
+ {
+ throw new Exception(ret.Response);
+ }
+ }
+ }
+}
From c561a95178764e2fc8392f30ce209a19cdeeb86d Mon Sep 17 00:00:00 2001
From: Bean
Date: Fri, 28 Nov 2014 09:27:12 +0800
Subject: [PATCH 3/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86fetch=E6=93=8D?=
=?UTF-8?q?=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Qiniu/RS/RSClient.cs | 497 +++++++++++++++++++++++--------------------
1 file changed, 261 insertions(+), 236 deletions(-)
diff --git a/Qiniu/RS/RSClient.cs b/Qiniu/RS/RSClient.cs
index 4d3a1a04..618542af 100644
--- a/Qiniu/RS/RSClient.cs
+++ b/Qiniu/RS/RSClient.cs
@@ -1,241 +1,266 @@
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json;
-using Qiniu.Auth;
-using Qiniu.Auth.digest;
-using Qiniu.Conf;
-using Qiniu.RPC;
-using Qiniu.Util;
-
-namespace Qiniu.RS
-{
- ///
- /// 文件管理操作
- ///
- public enum FileHandle
- {
- ///
- /// 查看
- ///
- STAT = 0,
- ///
- /// 移动move
- ///
- MOVE,
- ///
- /// 复制copy
- ///
- COPY,
- ///
- /// 删除delete
- ///
- DELETE
- }
-
- ///
- /// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete)操作
- /// 以及与这些操作对应的批量操作
- ///
- public class RSClient :QiniuAuthClient
- {
- private static string[] OPS = new string[] { "stat", "move", "copy", "delete" };
-
- public RSClient (Mac mac=null)
- : base(mac)
- {
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- private CallRet op (FileHandle op, EntryPath scope)
- {
- string url = string.Format ("{0}/{1}/{2}",
- Config.RS_HOST,
- OPS [(int)op],
- Base64URLSafe.Encode (scope.URI));
- return Call (url);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- private CallRet op2 (FileHandle op, EntryPathPair pair)
- {
- string url = string.Format ("{0}/{1}/{2}/{3}",
- Config.RS_HOST,
- OPS [(int)op],
- Base64URLSafe.Encode (pair.URISrc),
- Base64URLSafe.Encode (pair.URIDest));
- return Call (url);
- }
-
- ///
- /// 文件信息查看
- ///
- ///
- /// 文件的基本信息,见Entry
- public Entry Stat (EntryPath scope)
- {
- CallRet callRet = op (FileHandle.STAT, scope);
- return new Entry (callRet);
- }
-
- ///
- /// 删除文件
- ///
- /// 七牛云存储空间名称
- /// 需要删除的文件key
- ///
- public CallRet Delete (EntryPath scope)
- {
- CallRet callRet = op (FileHandle.DELETE, scope);
- return new Entry (callRet);
- }
-
- ///
- /// 移动文件
- ///
- /// 文件所属的源空间名称
- /// 源key
- /// 目标空间名称
- /// 目标key
- /// 见CallRet
- public CallRet Move (EntryPathPair pathPair)
- {
- return op2 (FileHandle.MOVE, pathPair);
- }
-
- ///
- /// 复制
- ///
- /// 文件所属的空间名称
- /// 需要复制的文件key
- /// 复制至目标空间
- /// 复制的副本文件key
- /// 见CallRet
- public CallRet Copy (EntryPathPair pathPair)
- {
- return op2 (FileHandle.COPY, pathPair);
- }
-
- ///
- /// 获取一元批操作http request Body
- ///
- /// 操作名
- /// 操作对象keys
- /// Request Body
- private string getBatchOp_1 (FileHandle op, EntryPath[] keys)
- {
- if (keys.Length < 1)
- return string.Empty;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i < keys.Length - 1; i++) {
- string item = string.Format ("op=/{0}/{1}&",
- OPS [(int)op],
- Base64URLSafe.Encode (keys [i].URI));
- sb.Append (item);
- }
- string litem = string.Format ("op=/{0}/{1}", OPS [(int)op], Base64URLSafe.Encode (keys [keys.Length - 1].URI));
- return sb.Append (litem).ToString ();
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- private string getBatchOp_2 (FileHandle op, EntryPathPair[] keys)
- {
- if (keys.Length < 1)
- return string.Empty;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i < keys.Length - 1; i++) {
- string item = string.Format ("op=/{0}/{1}/{2}&",
- OPS [(int)op],
- Base64URLSafe.Encode (keys [i].URISrc),
- Base64URLSafe.Encode (keys [i].URIDest));
- sb.Append (item);
- }
- string litem = string.Format ("op=/{0}/{1}/{2}", OPS [(int)op],
- Base64URLSafe.Encode (keys [keys.Length - 1].URISrc),
- Base64URLSafe.Encode (keys [keys.Length - 1].URIDest));
- return sb.Append (litem).ToString ();
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json;
+using Qiniu.Auth;
+using Qiniu.Auth.digest;
+using Qiniu.Conf;
+using Qiniu.RPC;
+using Qiniu.Util;
+
+namespace Qiniu.RS
+{
+ ///
+ /// 文件管理操作
+ ///
+ public enum FileHandle
+ {
+ ///
+ /// 查看
+ ///
+ STAT = 0,
+ ///
+ /// 移动move
+ ///
+ MOVE,
+ ///
+ /// 复制copy
+ ///
+ COPY,
+ ///
+ /// 删除delete
+ ///
+ DELETE,
+ ///
+ /// 抓取资源fetch
+ ///
+ FETCH
+ }
+
+ ///
+ /// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete), 抓取资源(fetch) 操作
+ /// 以及与这些操作对应的批量操作
+ ///
+ public class RSClient : QiniuAuthClient
+ {
+ private static string[] OPS = new string[] { "stat", "move", "copy", "delete", "fetch" };
+
+ public RSClient(Mac mac = null)
+ : base(mac)
+ {
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private CallRet op (FileHandle op, EntryPath scope)
+ {
+ string url = string.Format ("{0}/{1}/{2}",
+ Config.RS_HOST,
+ OPS [(int)op],
+ Base64URLSafe.Encode (scope.URI));
+ return Call (url);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private CallRet op2 (FileHandle op, EntryPathPair pair)
+ {
+ string url = string.Format ("{0}/{1}/{2}/{3}",
+ Config.RS_HOST,
+ OPS [(int)op],
+ Base64URLSafe.Encode (pair.URISrc),
+ Base64URLSafe.Encode (pair.URIDest));
+ return Call(url);
+ }
+
+ private CallRet opFetch(FileHandle op, string fromUrl, EntryPathPair pari)
+ {
+ string url = string.Format("{0}/{1}/{2}/to/{3}",
+ Config.RS_HOST,
+ OPS[(int)op],
+ Base64URLSafe.Encode(fromUrl),
+ Base64URLSafe.Encode(pari.URIDest));
+ return Call (url);
+ }
+
+ ///
+ /// 文件信息查看
+ ///
+ ///
+ /// 文件的基本信息,见Entry
+ public Entry Stat (EntryPath scope)
+ {
+ CallRet callRet = op (FileHandle.STAT, scope);
+ return new Entry (callRet);
+ }
+
+ ///
+ /// 删除文件
+ ///
+ /// 七牛云存储空间名称
+ /// 需要删除的文件key
+ ///
+ public CallRet Delete (EntryPath scope)
+ {
+ CallRet callRet = op (FileHandle.DELETE, scope);
+ return new Entry (callRet);
+ }
+
+ ///
+ /// 移动文件
+ ///
+ /// 文件所属的源空间名称
+ /// 源key
+ /// 目标空间名称
+ /// 目标key
+ /// 见CallRet
+ public CallRet Move (EntryPathPair pathPair)
+ {
+ return op2 (FileHandle.MOVE, pathPair);
+ }
+
+ ///
+ /// 复制
+ ///
+ /// 文件所属的空间名称
+ /// 需要复制的文件key
+ /// 复制至目标空间
+ /// 复制的副本文件key
+ /// 见CallRet
+ public CallRet Copy (EntryPathPair pathPair)
+ {
+ return op2 (FileHandle.COPY, pathPair);
+ }
+
+ ///
+ /// 抓取资源
+ ///
+ /// 需要抓取的文件URL
+ /// 标准EntryPathPai对应, 可不输入source bucket及source key
+ /// 见CallRet
+ public CallRet Fetch(string fromUrl, EntryPathPair pathPair)
+ {
+ return opFetch(FileHandle.FETCH, fromUrl, pathPair);
+ }
+
+ ///
+ /// 获取一元批操作http request Body
+ ///
+ /// 操作名
+ /// 操作对象keys
+ /// Request Body
+ private string getBatchOp_1 (FileHandle op, EntryPath[] keys)
+ {
+ if (keys.Length < 1)
+ return string.Empty;
+ StringBuilder sb = new StringBuilder ();
+ for (int i = 0; i < keys.Length - 1; i++) {
+ string item = string.Format ("op=/{0}/{1}&",
+ OPS [(int)op],
+ Base64URLSafe.Encode (keys [i].URI));
+ sb.Append (item);
+ }
+ string litem = string.Format ("op=/{0}/{1}", OPS [(int)op], Base64URLSafe.Encode (keys [keys.Length - 1].URI));
+ return sb.Append (litem).ToString ();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private string getBatchOp_2 (FileHandle op, EntryPathPair[] keys)
+ {
+ if (keys.Length < 1)
+ return string.Empty;
+ StringBuilder sb = new StringBuilder ();
+ for (int i = 0; i < keys.Length - 1; i++) {
+ string item = string.Format ("op=/{0}/{1}/{2}&",
+ OPS [(int)op],
+ Base64URLSafe.Encode (keys [i].URISrc),
+ Base64URLSafe.Encode (keys [i].URIDest));
+ sb.Append (item);
+ }
+ string litem = string.Format ("op=/{0}/{1}/{2}", OPS [(int)op],
+ Base64URLSafe.Encode (keys [keys.Length - 1].URISrc),
+ Base64URLSafe.Encode (keys [keys.Length - 1].URIDest));
+ return sb.Append (litem).ToString ();
}
private CallRet batch(string requestBody)
{
return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
- }
-
- ///
- /// 批操作:文件信息查看
- ///
- ///
- /// public static void BatchStat(string bucket, string[] keys)
- ///{
- /// RSClient client = new RSClient();
- /// List scopes= new List();
- /// foreach(string key in keys)
- /// {
- /// Console.WriteLine("\n===> Stat {0}:{1}", bucket, key);
- /// scopes.Add(new Scope(bucket,key));
- /// }
- /// client.BatchStat(scopes.ToArray());
- ///}
- ///
- ///
- ///
- /// 文件bucket+key,see
- ///
- public List BatchStat (EntryPath[] keys)
- {
- string requestBody = getBatchOp_1 (FileHandle.STAT, keys);
- CallRet ret = batch (requestBody);
- if (ret.OK) {
- List items = JsonConvert.DeserializeObject> (ret.Response);
- return items;
- }
- return null;
- }
-
- ///
- /// 批操作:文件移动
- ///
- /// EntryPathPair
- public CallRet BatchMove (EntryPathPair[] entryPathPairs)
- {
- string requestBody = getBatchOp_2 (FileHandle.MOVE, entryPathPairs);
- return batch (requestBody);
- }
-
- ///
- ///
- ///
- ///
- ///
- public CallRet BatchCopy (EntryPathPair[] entryPathPari)
- {
- string requestBody = getBatchOp_2 (FileHandle.COPY, entryPathPari);
- return batch (requestBody);
- }
-
- ///
- /// 批量删除
- ///
- ///
- ///
- public CallRet BatchDelete (EntryPath[] keys)
- {
- string requestBody = getBatchOp_1 (FileHandle.DELETE, keys);
- return batch (requestBody);
- }
- }
-}
+ }
+
+ ///
+ /// 批操作:文件信息查看
+ ///
+ ///
+ /// public static void BatchStat(string bucket, string[] keys)
+ ///{
+ /// RSClient client = new RSClient();
+ /// List scopes= new List();
+ /// foreach(string key in keys)
+ /// {
+ /// Console.WriteLine("\n===> Stat {0}:{1}", bucket, key);
+ /// scopes.Add(new Scope(bucket,key));
+ /// }
+ /// client.BatchStat(scopes.ToArray());
+ ///}
+ ///
+ ///
+ ///
+ /// 文件bucket+key,see
+ ///
+ public List BatchStat (EntryPath[] keys)
+ {
+ string requestBody = getBatchOp_1 (FileHandle.STAT, keys);
+ CallRet ret = batch (requestBody);
+ if (ret.OK) {
+ List items = JsonConvert.DeserializeObject> (ret.Response);
+ return items;
+ }
+ return null;
+ }
+
+ ///
+ /// 批操作:文件移动
+ ///
+ /// EntryPathPair
+ public CallRet BatchMove (EntryPathPair[] entryPathPairs)
+ {
+ string requestBody = getBatchOp_2 (FileHandle.MOVE, entryPathPairs);
+ return batch (requestBody);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public CallRet BatchCopy (EntryPathPair[] entryPathPari)
+ {
+ string requestBody = getBatchOp_2 (FileHandle.COPY, entryPathPari);
+ return batch (requestBody);
+ }
+
+ ///
+ /// 批量删除
+ ///
+ ///
+ ///
+ public CallRet BatchDelete (EntryPath[] keys)
+ {
+ string requestBody = getBatchOp_1 (FileHandle.DELETE, keys);
+ return batch (requestBody);
+ }
+ }
+}
From 62fa57bfae5e2de49622572b733ce83d44db934a Mon Sep 17 00:00:00 2001
From: Bean
Date: Fri, 28 Nov 2014 09:36:25 +0800
Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A1=8C=E5=B0=BE?=
=?UTF-8?q?=E6=A0=87=E5=BF=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Qiniu/RS/RSClient.cs | 532 +++++++++++++++++++++----------------------
1 file changed, 266 insertions(+), 266 deletions(-)
diff --git a/Qiniu/RS/RSClient.cs b/Qiniu/RS/RSClient.cs
index 618542af..94908856 100644
--- a/Qiniu/RS/RSClient.cs
+++ b/Qiniu/RS/RSClient.cs
@@ -1,266 +1,266 @@
-using System.Collections.Generic;
-using System.Text;
-using Newtonsoft.Json;
-using Qiniu.Auth;
-using Qiniu.Auth.digest;
-using Qiniu.Conf;
-using Qiniu.RPC;
-using Qiniu.Util;
-
-namespace Qiniu.RS
-{
- ///
- /// 文件管理操作
- ///
- public enum FileHandle
- {
- ///
- /// 查看
- ///
- STAT = 0,
- ///
- /// 移动move
- ///
- MOVE,
- ///
- /// 复制copy
- ///
- COPY,
- ///
- /// 删除delete
- ///
- DELETE,
- ///
- /// 抓取资源fetch
- ///
- FETCH
- }
-
- ///
- /// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete), 抓取资源(fetch) 操作
- /// 以及与这些操作对应的批量操作
- ///
- public class RSClient : QiniuAuthClient
- {
- private static string[] OPS = new string[] { "stat", "move", "copy", "delete", "fetch" };
-
- public RSClient(Mac mac = null)
- : base(mac)
- {
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- private CallRet op (FileHandle op, EntryPath scope)
- {
- string url = string.Format ("{0}/{1}/{2}",
- Config.RS_HOST,
- OPS [(int)op],
- Base64URLSafe.Encode (scope.URI));
- return Call (url);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- private CallRet op2 (FileHandle op, EntryPathPair pair)
- {
- string url = string.Format ("{0}/{1}/{2}/{3}",
- Config.RS_HOST,
- OPS [(int)op],
- Base64URLSafe.Encode (pair.URISrc),
- Base64URLSafe.Encode (pair.URIDest));
- return Call(url);
- }
-
- private CallRet opFetch(FileHandle op, string fromUrl, EntryPathPair pari)
- {
- string url = string.Format("{0}/{1}/{2}/to/{3}",
- Config.RS_HOST,
- OPS[(int)op],
- Base64URLSafe.Encode(fromUrl),
- Base64URLSafe.Encode(pari.URIDest));
- return Call (url);
- }
-
- ///
- /// 文件信息查看
- ///
- ///
- /// 文件的基本信息,见Entry
- public Entry Stat (EntryPath scope)
- {
- CallRet callRet = op (FileHandle.STAT, scope);
- return new Entry (callRet);
- }
-
- ///
- /// 删除文件
- ///
- /// 七牛云存储空间名称
- /// 需要删除的文件key
- ///
- public CallRet Delete (EntryPath scope)
- {
- CallRet callRet = op (FileHandle.DELETE, scope);
- return new Entry (callRet);
- }
-
- ///
- /// 移动文件
- ///
- /// 文件所属的源空间名称
- /// 源key
- /// 目标空间名称
- /// 目标key
- /// 见CallRet
- public CallRet Move (EntryPathPair pathPair)
- {
- return op2 (FileHandle.MOVE, pathPair);
- }
-
- ///
- /// 复制
- ///
- /// 文件所属的空间名称
- /// 需要复制的文件key
- /// 复制至目标空间
- /// 复制的副本文件key
- /// 见CallRet
- public CallRet Copy (EntryPathPair pathPair)
- {
- return op2 (FileHandle.COPY, pathPair);
- }
-
- ///
- /// 抓取资源
- ///
- /// 需要抓取的文件URL
- /// 标准EntryPathPai对应, 可不输入source bucket及source key
- /// 见CallRet
- public CallRet Fetch(string fromUrl, EntryPathPair pathPair)
- {
- return opFetch(FileHandle.FETCH, fromUrl, pathPair);
- }
-
- ///
- /// 获取一元批操作http request Body
- ///
- /// 操作名
- /// 操作对象keys
- /// Request Body
- private string getBatchOp_1 (FileHandle op, EntryPath[] keys)
- {
- if (keys.Length < 1)
- return string.Empty;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i < keys.Length - 1; i++) {
- string item = string.Format ("op=/{0}/{1}&",
- OPS [(int)op],
- Base64URLSafe.Encode (keys [i].URI));
- sb.Append (item);
- }
- string litem = string.Format ("op=/{0}/{1}", OPS [(int)op], Base64URLSafe.Encode (keys [keys.Length - 1].URI));
- return sb.Append (litem).ToString ();
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- private string getBatchOp_2 (FileHandle op, EntryPathPair[] keys)
- {
- if (keys.Length < 1)
- return string.Empty;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i < keys.Length - 1; i++) {
- string item = string.Format ("op=/{0}/{1}/{2}&",
- OPS [(int)op],
- Base64URLSafe.Encode (keys [i].URISrc),
- Base64URLSafe.Encode (keys [i].URIDest));
- sb.Append (item);
- }
- string litem = string.Format ("op=/{0}/{1}/{2}", OPS [(int)op],
- Base64URLSafe.Encode (keys [keys.Length - 1].URISrc),
- Base64URLSafe.Encode (keys [keys.Length - 1].URIDest));
- return sb.Append (litem).ToString ();
- }
-
- private CallRet batch(string requestBody)
- {
- return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
- }
-
- ///
- /// 批操作:文件信息查看
- ///
- ///
- /// public static void BatchStat(string bucket, string[] keys)
- ///{
- /// RSClient client = new RSClient();
- /// List scopes= new List();
- /// foreach(string key in keys)
- /// {
- /// Console.WriteLine("\n===> Stat {0}:{1}", bucket, key);
- /// scopes.Add(new Scope(bucket,key));
- /// }
- /// client.BatchStat(scopes.ToArray());
- ///}
- ///
- ///
- ///
- /// 文件bucket+key,see
- ///
- public List BatchStat (EntryPath[] keys)
- {
- string requestBody = getBatchOp_1 (FileHandle.STAT, keys);
- CallRet ret = batch (requestBody);
- if (ret.OK) {
- List items = JsonConvert.DeserializeObject> (ret.Response);
- return items;
- }
- return null;
- }
-
- ///
- /// 批操作:文件移动
- ///
- /// EntryPathPair
- public CallRet BatchMove (EntryPathPair[] entryPathPairs)
- {
- string requestBody = getBatchOp_2 (FileHandle.MOVE, entryPathPairs);
- return batch (requestBody);
- }
-
- ///
- ///
- ///
- ///
- ///
- public CallRet BatchCopy (EntryPathPair[] entryPathPari)
- {
- string requestBody = getBatchOp_2 (FileHandle.COPY, entryPathPari);
- return batch (requestBody);
- }
-
- ///
- /// 批量删除
- ///
- ///
- ///
- public CallRet BatchDelete (EntryPath[] keys)
- {
- string requestBody = getBatchOp_1 (FileHandle.DELETE, keys);
- return batch (requestBody);
- }
- }
-}
+using System.Collections.Generic;
+using System.Text;
+using Newtonsoft.Json;
+using Qiniu.Auth;
+using Qiniu.Auth.digest;
+using Qiniu.Conf;
+using Qiniu.RPC;
+using Qiniu.Util;
+
+namespace Qiniu.RS
+{
+ ///
+ /// 文件管理操作
+ ///
+ public enum FileHandle
+ {
+ ///
+ /// 查看
+ ///
+ STAT = 0,
+ ///
+ /// 移动move
+ ///
+ MOVE,
+ ///
+ /// 复制copy
+ ///
+ COPY,
+ ///
+ /// 删除delete
+ ///
+ DELETE,
+ ///
+ /// 抓取资源fetch
+ ///
+ FETCH
+ }
+
+ ///
+ /// 资源存储客户端,提供对文件的查看(stat),移动(move),复制(copy),删除(delete), 抓取资源(fetch) 操作
+ /// 以及与这些操作对应的批量操作
+ ///
+ public class RSClient : QiniuAuthClient
+ {
+ private static string[] OPS = new string[] { "stat", "move", "copy", "delete", "fetch" };
+
+ public RSClient(Mac mac = null)
+ : base(mac)
+ {
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private CallRet op (FileHandle op, EntryPath scope)
+ {
+ string url = string.Format ("{0}/{1}/{2}",
+ Config.RS_HOST,
+ OPS [(int)op],
+ Base64URLSafe.Encode (scope.URI));
+ return Call (url);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private CallRet op2 (FileHandle op, EntryPathPair pair)
+ {
+ string url = string.Format ("{0}/{1}/{2}/{3}",
+ Config.RS_HOST,
+ OPS [(int)op],
+ Base64URLSafe.Encode (pair.URISrc),
+ Base64URLSafe.Encode (pair.URIDest));
+ return Call(url);
+ }
+
+ private CallRet opFetch(FileHandle op, string fromUrl, EntryPathPair pari)
+ {
+ string url = string.Format("{0}/{1}/{2}/to/{3}",
+ Config.RS_HOST,
+ OPS[(int)op],
+ Base64URLSafe.Encode(fromUrl),
+ Base64URLSafe.Encode(pari.URIDest));
+ return Call (url);
+ }
+
+ ///
+ /// 文件信息查看
+ ///
+ ///
+ /// 文件的基本信息,见Entry
+ public Entry Stat (EntryPath scope)
+ {
+ CallRet callRet = op (FileHandle.STAT, scope);
+ return new Entry (callRet);
+ }
+
+ ///
+ /// 删除文件
+ ///
+ /// 七牛云存储空间名称
+ /// 需要删除的文件key
+ ///
+ public CallRet Delete (EntryPath scope)
+ {
+ CallRet callRet = op (FileHandle.DELETE, scope);
+ return new Entry (callRet);
+ }
+
+ ///
+ /// 移动文件
+ ///
+ /// 文件所属的源空间名称
+ /// 源key
+ /// 目标空间名称
+ /// 目标key
+ /// 见CallRet
+ public CallRet Move (EntryPathPair pathPair)
+ {
+ return op2 (FileHandle.MOVE, pathPair);
+ }
+
+ ///
+ /// 复制
+ ///
+ /// 文件所属的空间名称
+ /// 需要复制的文件key
+ /// 复制至目标空间
+ /// 复制的副本文件key
+ /// 见CallRet
+ public CallRet Copy (EntryPathPair pathPair)
+ {
+ return op2 (FileHandle.COPY, pathPair);
+ }
+
+ ///
+ /// 抓取资源
+ ///
+ /// 需要抓取的文件URL
+ /// 标准EntryPathPai对应, 可不输入source bucket及source key
+ /// 见CallRet
+ public CallRet Fetch(string fromUrl, EntryPathPair pathPair)
+ {
+ return opFetch(FileHandle.FETCH, fromUrl, pathPair);
+ }
+
+ ///
+ /// 获取一元批操作http request Body
+ ///
+ /// 操作名
+ /// 操作对象keys
+ /// Request Body
+ private string getBatchOp_1 (FileHandle op, EntryPath[] keys)
+ {
+ if (keys.Length < 1)
+ return string.Empty;
+ StringBuilder sb = new StringBuilder ();
+ for (int i = 0; i < keys.Length - 1; i++) {
+ string item = string.Format ("op=/{0}/{1}&",
+ OPS [(int)op],
+ Base64URLSafe.Encode (keys [i].URI));
+ sb.Append (item);
+ }
+ string litem = string.Format ("op=/{0}/{1}", OPS [(int)op], Base64URLSafe.Encode (keys [keys.Length - 1].URI));
+ return sb.Append (litem).ToString ();
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ private string getBatchOp_2 (FileHandle op, EntryPathPair[] keys)
+ {
+ if (keys.Length < 1)
+ return string.Empty;
+ StringBuilder sb = new StringBuilder ();
+ for (int i = 0; i < keys.Length - 1; i++) {
+ string item = string.Format ("op=/{0}/{1}/{2}&",
+ OPS [(int)op],
+ Base64URLSafe.Encode (keys [i].URISrc),
+ Base64URLSafe.Encode (keys [i].URIDest));
+ sb.Append (item);
+ }
+ string litem = string.Format ("op=/{0}/{1}/{2}", OPS [(int)op],
+ Base64URLSafe.Encode (keys [keys.Length - 1].URISrc),
+ Base64URLSafe.Encode (keys [keys.Length - 1].URIDest));
+ return sb.Append (litem).ToString ();
+ }
+
+ private CallRet batch(string requestBody)
+ {
+ return CallWithBinary(Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", StreamEx.ToStream(requestBody), requestBody.Length);
+ }
+
+ ///
+ /// 批操作:文件信息查看
+ ///
+ ///
+ /// public static void BatchStat(string bucket, string[] keys)
+ ///{
+ /// RSClient client = new RSClient();
+ /// List scopes= new List();
+ /// foreach(string key in keys)
+ /// {
+ /// Console.WriteLine("\n===> Stat {0}:{1}", bucket, key);
+ /// scopes.Add(new Scope(bucket,key));
+ /// }
+ /// client.BatchStat(scopes.ToArray());
+ ///}
+ ///
+ ///
+ ///
+ /// 文件bucket+key,see
+ ///
+ public List BatchStat (EntryPath[] keys)
+ {
+ string requestBody = getBatchOp_1 (FileHandle.STAT, keys);
+ CallRet ret = batch (requestBody);
+ if (ret.OK) {
+ List items = JsonConvert.DeserializeObject> (ret.Response);
+ return items;
+ }
+ return null;
+ }
+
+ ///
+ /// 批操作:文件移动
+ ///
+ /// EntryPathPair
+ public CallRet BatchMove (EntryPathPair[] entryPathPairs)
+ {
+ string requestBody = getBatchOp_2 (FileHandle.MOVE, entryPathPairs);
+ return batch (requestBody);
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public CallRet BatchCopy (EntryPathPair[] entryPathPari)
+ {
+ string requestBody = getBatchOp_2 (FileHandle.COPY, entryPathPari);
+ return batch (requestBody);
+ }
+
+ ///
+ /// 批量删除
+ ///
+ ///
+ ///
+ public CallRet BatchDelete (EntryPath[] keys)
+ {
+ string requestBody = getBatchOp_1 (FileHandle.DELETE, keys);
+ return batch (requestBody);
+ }
+ }
+}
From 2be5360c3abd9b860c3c5f41c19e244e8928a84a Mon Sep 17 00:00:00 2001
From: Bean
Date: Sat, 29 Nov 2014 14:13:55 +0800
Subject: [PATCH 5/7] =?UTF-8?q?=E6=97=A0=E9=9C=80=E4=BD=BF=E7=94=A8EntryPa?=
=?UTF-8?q?thPair=EF=BC=8C=E5=8F=AA=E9=9C=80EntryPath=E5=8D=B3=E5=8F=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Qiniu/RS/RSClient.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Qiniu/RS/RSClient.cs b/Qiniu/RS/RSClient.cs
index 94908856..a2d2048b 100644
--- a/Qiniu/RS/RSClient.cs
+++ b/Qiniu/RS/RSClient.cs
@@ -80,13 +80,13 @@ OPS [(int)op],
return Call(url);
}
- private CallRet opFetch(FileHandle op, string fromUrl, EntryPathPair pari)
+ private CallRet opFetch(FileHandle op, string fromUrl, EntryPath entryPath)
{
string url = string.Format("{0}/{1}/{2}/to/{3}",
Config.RS_HOST,
OPS[(int)op],
Base64URLSafe.Encode(fromUrl),
- Base64URLSafe.Encode(pari.URIDest));
+ Base64URLSafe.Encode(entryPath.URI));
return Call (url);
}
@@ -143,11 +143,11 @@ public CallRet Copy (EntryPathPair pathPair)
/// 抓取资源
///
/// 需要抓取的文件URL
- /// 标准EntryPathPai对应, 可不输入source bucket及source key
+ /// 目标entryPath
/// 见CallRet
- public CallRet Fetch(string fromUrl, EntryPathPair pathPair)
+ public CallRet Fetch(string fromUrl, EntryPath entryPath)
{
- return opFetch(FileHandle.FETCH, fromUrl, pathPair);
+ return opFetch(FileHandle.FETCH, fromUrl, entryPath);
}
///
From e008fe70e840aa9551753679affcfe016be75484 Mon Sep 17 00:00:00 2001
From: Bai Long
Date: Thu, 26 Feb 2015 16:08:41 +0800
Subject: [PATCH 6/7] update version [ci skip]
---
Qiniu/Conf/Config.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Qiniu/Conf/Config.cs b/Qiniu/Conf/Config.cs
index 6a31619a..0f9f62f0 100644
--- a/Qiniu/Conf/Config.cs
+++ b/Qiniu/Conf/Config.cs
@@ -5,7 +5,7 @@ namespace Qiniu.Conf
{
public class Config
{
- public static string VERSION = "6.1.4";
+ public static string VERSION = "6.1.5";
public static string USER_AGENT = getUa();
#region 帐户信息
From de1b7d3b9c0c21155f543f08b9f62a688cf9833f Mon Sep 17 00:00:00 2001
From: Bai Long
Date: Thu, 26 Feb 2015 16:09:15 +0800
Subject: [PATCH 7/7] [ci skip]
---
Qiniu/Conf/Config.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Qiniu/Conf/Config.cs b/Qiniu/Conf/Config.cs
index 0f9f62f0..949eb6fc 100644
--- a/Qiniu/Conf/Config.cs
+++ b/Qiniu/Conf/Config.cs
@@ -26,7 +26,7 @@ public class Config
///
/// 七牛资源上传服务器地址.
///
- public static string UP_HOST = "http://upload.qiniu.com";
+ public static string UP_HOST = "http://up.qiniu.com";
///
/// 七牛资源列表服务器地址.
///