From 601d36b495582e500b85fb62012a1c23a27c7c07 Mon Sep 17 00:00:00 2001 From: icattlecoder Date: Sat, 12 Oct 2013 14:50:22 +0800 Subject: [PATCH 1/3] fix link --- Docs/README.md | 2 +- Qiniu/FileOp/bi.cs | 12 +++ Qiniu/RS/BiClient.cs | 241 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 Qiniu/FileOp/bi.cs create mode 100644 Qiniu/RS/BiClient.cs diff --git a/Docs/README.md b/Docs/README.md index 118adb83..ebbb8c4c 100644 --- a/Docs/README.md +++ b/Docs/README.md @@ -339,7 +339,7 @@ public static void BatchDelete(string bucket, string[] keys) ``` -##4. 资源列表 +## 4. 资源列表 资源列表接口允许用户列出空间下的所有文件信息。使用资源列表接口如果引入Qiniu.RSF命名空间。 ```c# diff --git a/Qiniu/FileOp/bi.cs b/Qiniu/FileOp/bi.cs new file mode 100644 index 00000000..c73d7f7c --- /dev/null +++ b/Qiniu/FileOp/bi.cs @@ -0,0 +1,12 @@ +using System; + +namespace Qiniu +{ + public class bi + { + public bi () + { + } + } +} + diff --git a/Qiniu/RS/BiClient.cs b/Qiniu/RS/BiClient.cs new file mode 100644 index 00000000..ac5c9a98 --- /dev/null +++ b/Qiniu/RS/BiClient.cs @@ -0,0 +1,241 @@ +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", "delet" }; + + 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 (); + } + + private CallRet batch (string requestBody) + { + return CallWithBinary (Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", requestBody.ToStream (), 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 43d01a4e836e71df0c9117f86f5f95232f0666dd Mon Sep 17 00:00:00 2001 From: icattlecoder Date: Sat, 12 Oct 2013 14:55:30 +0800 Subject: [PATCH 2/3] fix --- Qiniu/FileOp/bi.cs | 12 --- Qiniu/RS/BiClient.cs | 241 ------------------------------------------- README.md | 14 ++- 3 files changed, 6 insertions(+), 261 deletions(-) delete mode 100644 Qiniu/FileOp/bi.cs delete mode 100644 Qiniu/RS/BiClient.cs diff --git a/Qiniu/FileOp/bi.cs b/Qiniu/FileOp/bi.cs deleted file mode 100644 index c73d7f7c..00000000 --- a/Qiniu/FileOp/bi.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace Qiniu -{ - public class bi - { - public bi () - { - } - } -} - diff --git a/Qiniu/RS/BiClient.cs b/Qiniu/RS/BiClient.cs deleted file mode 100644 index ac5c9a98..00000000 --- a/Qiniu/RS/BiClient.cs +++ /dev/null @@ -1,241 +0,0 @@ -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", "delet" }; - - 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 (); - } - - private CallRet batch (string requestBody) - { - return CallWithBinary (Conf.Config.RS_HOST + "/batch", "application/x-www-form-urlencoded", requestBody.ToStream (), 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); - } - } -} diff --git a/README.md b/README.md index 90ecbd44..7b6d86f4 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Qiniu Resource (Cloud) Storage SDK for C# # 关于 - -此 C# SDK 适用于 .NET4 及以上版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/v2/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。 - + +此 C# SDK 适用于 .NET4 及以上版本,基于 [七牛云存储官方API](http://docs.qiniu.com/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。 + ## 使用 - -参考文档:[七牛云存储 C# SDK 使用指南](http://docs.qiniu.com/v2/sdk/csharp/) - + +参考文档:[七牛云存储 C# SDK 使用指南](https://github.com/qiniu/csharp-sdk/blob/develop/Docs/README.md) + ## 贡献代码 1. Fork @@ -23,5 +23,3 @@ Copyright (c) 2012 qiniutek.com 基于 MIT 协议发布: * [www.opensource.org/licenses/MIT](http://www.opensource.org/licenses/MIT) - - From aaaff22582c8c64f0032c55e2d1aa6835dada9c9 Mon Sep 17 00:00:00 2001 From: icattlecoder Date: Sat, 12 Oct 2013 15:05:04 +0800 Subject: [PATCH 3/3] fix --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c168f9cb..46322283 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,9 @@ install: - sudo apt-get update && sudo apt-get install nunit mono-gmcs cli-common-dev libgl1-mesa-dev libsdl1.2-dev libopenal-dev before_script: - - export QINIU_ACCESS_KEY="IFkgYHCdmdNPWNjMMhk9LAV7guz1wpI5Sp5h8ssK" - - export QINIU_SECRET_KEY="R6Nlsu6SQwStqhlDv-e4fMGW3qM4ryBspHgdjAFR" - - export QINIU_TEST_BUCKET="icattlecoder3" + - export QINIU_ACCESS_KEY="iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV" + - export QINIU_SECRET_KEY="6QTOr2Jg1gcZEWDQXKOGZh5PziC2MCV5KsntT70j" + - export QINIU_TEST_BUCKET="qtestbucket" - export QINIU_TEST_DOMAIN="qiniuphotos.qiniudn.com" script: