示例#1
0
        /// <summary>
        /// 请求持久化
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="fops"></param>
        /// <param name="notifyURL"></param>
        /// <returns></returns>
        public async Task<string> Do(EntryPath entry, string[] fops, Uri notifyURL,string pipleline,int force=0)
        {
            if (fops.Length < 1 || entry == null || string.IsNullOrEmpty(entry.Bucket) || notifyURL == null || !notifyURL.IsAbsoluteUri)
            {
                throw new Exception("params error");
            }
            StringBuilder sb = new StringBuilder();
            sb.Append(fops[0]);

            for (int i = 1; i < fops.Length; ++i)
            {
                sb.Append(";");
                sb.Append(fops[i]);
            }

            string body = string.Format("bucket={0}&key={1}&fops={2}&notifyURL={3}&force={4}&pipeline={5}", entry.Bucket, StringEx.ToUrlEncode(entry.Key), sb.ToString(), notifyURL.ToString(), force, pipleline);
            CallRet ret =await CallWithBinary(Config.API_HOST + "/pfop/",new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/x-www-form-urlencoded"),StreamEx.ToStream(body), body.Length);

            if (ret.OK)
            {
                try
                {
                    PersistentId pid = JsonConvert.DeserializeObject<PersistentId>(ret.Response);
                    return pid.persistentId;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                throw new Exception(ret.Response);
            }
        }
示例#2
0
 public static void RSDel(string bucket,string key)
 {
     RSClient target = new RSClient(); // TODO: 初始化为适当的值
     EntryPath scope = new EntryPath(bucket,key); // TODO: 初始化为适当的值
     CallRet actual;
     actual = target.Delete(scope);
 }
示例#3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="op"></param>
		/// <param name="scope"></param>
		/// <returns></returns>
		private async Task<CallRet> op (FileHandle op, EntryPath scope)
		{
			string url = string.Format ("{0}/{1}/{2}",
			                            Config.RS_HOST,
			                            OPS [(int)op],
			                            Base64URLSafe.Encode (scope.URI));
			return await Call (url);
		}
示例#4
0
        private async Task <CallRet> opAsync(FileHandle op, EntryPath scope)
        {
            string url = string.Format("{0}/{1}/{2}",
                                       Config.RS_HOST,
                                       OPS[(int)op],
                                       Base64URLSafe.Encode(scope.URI));

            return(await CallAsync(url));
        }
示例#5
0
		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(entryPath.URI));
			return Call (url);
		}
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="op"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        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));
        }
示例#7
0
		private async Task<CallRet> opFetch(FileHandle op, string fromUrl, EntryPath entryPath)
		{
			string url = string.Format("{0}/{1}/{2}/to/{3}",
										Config.PREFETCH_HOST,
										OPS[(int)op],
										Base64URLSafe.Encode(fromUrl),
										Base64URLSafe.Encode(entryPath.URI));
			return await Call (url);
		}
		public void StatTest()
		{
			RSClient target = new RSClient();
			//YES
		
			EntryPath scope = new EntryPath(Bucket, tmpKeys[0]); 
			Entry actual;
			actual = target.Stat(scope);
			Assert.IsTrue(actual.OK, "StatTest Failure");
		}
示例#9
0
        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(entryPath.URI));

            return(Call(url));
        }
示例#10
0
        private async Task <CallRet> opFetchAsync(FileHandle op, string fromUrl, EntryPath entryPath)
        {
            string url = string.Format("{0}/{1}/{2}/to/{3}",
                                       Config.PREFETCH_HOST,
                                       OPS[(int)op],
                                       Base64URLSafe.Encode(fromUrl),
                                       Base64URLSafe.Encode(entryPath.URI));

            return(await CallAsync(url));
        }
示例#11
0
文件: Pfop.cs 项目: EnhWeb/csharp-sdk
        public async Task <string> DoAsync(EntryPath entry, string[] fops, Uri notifyURL, string pipleline, int force = 0)
        {
            if (fops.Length < 1 || entry == null || string.IsNullOrEmpty(entry.Bucket) || notifyURL == null || !notifyURL.IsAbsoluteUri)
            {
                throw new Exception("params error");
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(fops[0]);

            for (int i = 1; i < fops.Length; ++i)
            {
                sb.Append(";");
                sb.Append(fops[i]);
            }

            // FormUrlEncodedContent 自带 UrlEncode
            var content = new FormUrlEncodedContent(new Dictionary <string, string>
            {
                { "bucket", entry.Bucket },
                { "key", entry.Key },
                { "fops", sb.ToString() },
                { "notifyURL", notifyURL.ToString() },
                { "force", force.ToString() },
                { "pipeline", pipleline }
            });

            CallRet ret = await CallWithBinaryAsync(Config.API_HOST + "/pfop/", content);

            if (ret.OK)
            {
                try
                {
                    PersistentId pid = JsonConvert.DeserializeObject <PersistentId>(ret.Response);
                    return(pid.persistentId);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                throw new Exception(ret.Response);
            }
        }
示例#12
0
        public void BatchDeleteTest()
        {
            List<string> tmps = RSHelper.RSPut(Bucket,2);

            RSClient target = new RSClient(); // TODO: 初始化为适当的值
            EntryPath[] keys = new EntryPath[2]; // TODO: 初始化为适当的值
            int i = 0;
            foreach (string k in tmps) {
                keys [i++] = new EntryPath (Bucket, k);
            }

            CallRet actual;
            actual = target.BatchDelete(keys);
            if (actual.OK) {
                foreach (string k in tmps) {
                    RSHelper.RSDel(Bucket,k);
                }
            }
            Assert.IsTrue(actual.OK, "BatchStatTest Failure"); ;
        }
示例#13
0
        /// <summary>
        /// 请求持久化
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="fops"></param>
        /// <param name="notifyURL"></param>
        /// <returns></returns>
        public string Do(EntryPath entry, string[] fops, Uri notifyURL)
        {
            if (fops.Length < 1 || entry == null || string.IsNullOrEmpty(entry.Bucket) || notifyURL == null || !notifyURL.IsAbsoluteUri)
            {
                throw new Exception("params error");
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(fops[0]);

            for (int i = 1; i < fops.Length; ++i)
            {
                sb.Append(";");
                sb.Append(fops[i]);
            }

            string body = string.Format("bucket={0}&key={1}&fops={2}&notifyURL={3}", entry.Bucket, StringEx.ToUrlEncode(entry.Key), sb.ToString(), notifyURL.ToString());

            CallRet ret = CallWithBinary(Config.API_HOST + "/pfop/", "application/x-www-form-urlencoded", StreamEx.ToStream(body), body.Length);

            if (ret.OK)
            {
                try
                {
                    PersistentId pid = JsonConvert.DeserializeObject <PersistentId>(ret.Response);
                    return(pid.persistentId);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                throw new Exception(ret.Response);
            }
        }
示例#14
0
        /// <summary>
        /// 请求持久化
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="fops"></param>
        /// <param name="notifyURL"></param>
        /// <returns></returns>
        public async Task <string> Do(EntryPath entry, string[] fops, Uri notifyURL, string pipleline, int force = 0)
        {
            if (fops.Length < 1 || entry == null || string.IsNullOrEmpty(entry.Bucket) || notifyURL == null || !notifyURL.IsAbsoluteUri)
            {
                throw new Exception("params error");
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(fops[0]);

            for (int i = 1; i < fops.Length; ++i)
            {
                sb.Append(";");
                sb.Append(fops[i]);
            }

            string  body = string.Format("bucket={0}&key={1}&fops={2}&notifyURL={3}&force={4}&pipeline={5}", entry.Bucket, StringEx.ToUrlEncode(entry.Key), sb.ToString(), notifyURL.ToString(), force, pipleline);
            CallRet ret  = await CallWithBinary(Config.API_HOST + "/pfop/", new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/x-www-form-urlencoded"), StreamEx.ToStream(body), body.Length);

            if (ret.OK)
            {
                try
                {
                    PersistentId pid = JsonConvert.DeserializeObject <PersistentId>(ret.Response);
                    return(pid.persistentId);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                throw new Exception(ret.Response);
            }
        }
示例#15
0
文件: Pfop.cs 项目: amwtke/bkwecaht
        /// <summary>
        /// 请求持久化
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="fops"></param>
        /// <param name="notifyURL"></param>
        /// <returns></returns>
        public string Do(EntryPath entry, string[] fops, Uri notifyURL)
        {
            if (fops.Length < 1 || entry == null || string.IsNullOrEmpty(entry.Bucket) || notifyURL == null || !notifyURL.IsAbsoluteUri)
            {
                throw new Exception("params error");
            }
            StringBuilder sb = new StringBuilder();
            sb.Append(fops[0]);

            for (int i = 1; i < fops.Length; ++i)
            {
                sb.Append(";");
                sb.Append(fops[i]);
            }

            string body = string.Format("bucket={0}&key={1}&fops={2}&notifyURL={3}", entry.Bucket, StringEx.ToUrlEncode(entry.Key), sb.ToString(), notifyURL.ToString());

            CallRet ret = CallWithBinary(Config.API_HOST + "/pfop/", "application/x-www-form-urlencoded",StreamEx.ToStream(body), body.Length);

            if (ret.OK)
            {
                try
                {
                    PersistentId pid = JsonConvert.DeserializeObject<PersistentId>(ret.Response);
                    return pid.persistentId;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            else
            {
                throw new Exception(ret.Response);
            }
        }
示例#16
0
文件: RSClient.cs 项目: sigcms/Seeger
 /// <summary>
 /// 获取一元批操作http request Body
 /// </summary>
 /// <param name="opName">操作名</param>
 /// <param name="keys">操作对象keys</param>
 /// <returns>Request Body</returns>
 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 ();
 }
示例#17
0
文件: RSClient.cs 项目: sigcms/Seeger
 /// <summary>
 /// 文件信息查看
 /// </summary>
 /// <param name="scope"></param>
 /// <returns>文件的基本信息,见<see cref="Entry">Entry</see></returns>
 public Entry Stat(EntryPath scope)
 {
     CallRet callRet = op (FileHandle.STAT, scope);
     return new Entry (callRet);
 }
示例#18
0
文件: RSClient.cs 项目: sigcms/Seeger
 /// <summary>
 /// 删除文件
 /// </summary>
 /// <param name="bucket">七牛云存储空间名称</param>
 /// <param name="key">需要删除的文件key</param>
 /// <returns></returns>
 public CallRet Delete(EntryPath scope)
 {
     CallRet callRet = op (FileHandle.DELETE, scope);
     return new Entry (callRet);
 }
示例#19
0
文件: RSClient.cs 项目: sigcms/Seeger
 /// <summary>
 /// 批操作:文件信息查看
 /// <example>
 /// <code>
 /// public static void BatchStat(string bucket, string[] keys)
 ///{
 ///    RSClient client = new RSClient();
 ///    List<Scope> scopes= new List<Scope>();
 ///    foreach(string key in keys)
 ///    {
 ///        Console.WriteLine("\n===> Stat {0}:{1}", bucket, key);
 ///        scopes.Add(new Scope(bucket,key));
 ///    }
 ///    client.BatchStat(scopes.ToArray()); 
 ///}
 /// </code>
 /// </example>
 /// </summary>
 /// <param name="keys">文件bucket+key,see<see cref="Scope"/></param>
 /// <returns></returns>
 public List<BatchRetItem> BatchStat(EntryPath[] keys)
 {
     string requestBody = getBatchOp_1 (FileHandle.STAT, keys);
     CallRet ret = batch (requestBody);
     if (ret.OK) {
         List<BatchRetItem> items = JsonConvert.DeserializeObject<List<BatchRetItem>> (ret.Response);
         return items;
     }
     return null;
 }
示例#20
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="bucket">七牛云存储空间名称</param>
        /// <param name="key">需要删除的文件key</param>
        /// <returns></returns>
        public async Task <CallRet> DeleteAsync(EntryPath scope)
        {
            CallRet callRet = await opAsync(FileHandle.DELETE, scope);

            return(new Entry(callRet));
        }
示例#21
0
		/// <summary>
		/// 删除文件
		/// </summary>
		/// <param name="bucket">七牛云存储空间名称</param>
		/// <param name="key">需要删除的文件key</param>
		/// <returns></returns>
		public async Task<CallRet> Delete (EntryPath scope)
		{
			CallRet callRet = await op (FileHandle.DELETE, scope);
			return new Entry (callRet);
		}
示例#22
0
 public void BatchStatTest()
 {
     RSClient target = new RSClient(); // TODO: 初始化为适当的值
     EntryPath[] keys = new EntryPath[2]; // TODO: 初始化为适当的值
     keys[0] = new EntryPath(Bucket, tmpKeys[0]);
     keys[1] = new EntryPath(Bucket, tmpKeys[1]);//error params
     List<BatchRetItem> actual;
     actual = target.BatchStat(keys);
     Assert.IsTrue(actual.Count == 2, "BatchStatTest Failure");
 }
示例#23
0
		/// <summary>
		/// 抓取资源
		/// </summary>
		/// <param name="fromUrl">需要抓取的文件URL</param>
		/// <param name="entryPath">目标entryPath</param>
		/// <returns>见<see cref="CallRet">CallRet</see></returns>
		public CallRet Fetch(string fromUrl, EntryPath entryPath)
		{
			return opFetch(FileHandle.FETCH, fromUrl, entryPath);
		}
示例#24
0
		/// <summary>
		/// 文件信息查看
		/// </summary>
		/// <param name="scope"></param>
		/// <returns>文件的基本信息,见<see cref="Entry">Entry</see></returns>
		public async Task<Entry> Stat (EntryPath scope)
		{
			CallRet callRet =await op (FileHandle.STAT, scope);
			return new Entry (callRet);
		}
示例#25
0
		/// <summary>
		/// 删除文件
		/// </summary>
		/// <param name="bucket">七牛云存储空间名称</param>
		/// <param name="key">需要删除的文件key</param>
		/// <returns></returns>
		public async System.Threading.Tasks.Task<CallRet> Delete(EntryPath scope)
		{
			CallRet callRet = await op(FileHandle.DELETE, scope);
			return new Entry(callRet);
		}
示例#26
0
 /// <summary>
 /// 抓取资源
 /// </summary>
 /// <param name="fromUrl">需要抓取的文件URL</param>
 /// <param name="entryPath">目标entryPath</param>
 /// <returns>见<see cref="CallRet">CallRet</see></returns>
 public CallRet Fetch(string fromUrl, EntryPath entryPath)
 {
     return(opFetch(FileHandle.FETCH, fromUrl, entryPath));
 }
示例#27
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public async Task<CallRet> BatchDelete (EntryPath[] keys)
		{
			string requestBody = getBatchOp_1 (FileHandle.DELETE, keys);
			return await batch (requestBody);
		}
示例#28
0
        /// <summary>
        /// 抓取资源
        /// </summary>
        /// <param name="fromUrl">需要抓取的文件URL</param>
        /// <param name="entryPath">目标entryPath</param>
        /// <returns>见<see cref="CallRet">CallRet</see></returns>
        public async Task<CallRet> Fetch(string fromUrl, EntryPath entryPath)
		{
			return await opFetch(FileHandle.FETCH, fromUrl, entryPath);
		}
示例#29
0
文件: RSClient.cs 项目: sigcms/Seeger
 /// <summary>
 /// 批量删除
 /// </summary>
 /// <param name="keys"></param>
 /// <returns></returns>
 public CallRet BatchDelete(EntryPath[] keys)
 {
     string requestBody = getBatchOp_1 (FileHandle.DELETE, keys);
     return batch (requestBody);
 }
示例#30
0
		/// <summary>
		/// 文件信息查看
		/// </summary>
		/// <param name="scope"></param>
		/// <returns>文件的基本信息,见<see cref="Entry">Entry</see></returns>
		public async System.Threading.Tasks.Task<Entry> Stat(EntryPath scope)
		{
			CallRet callRet = await op(FileHandle.STAT, scope);
			return new Entry(callRet);
		}
		/// <summary>
		/// Pres the fetch.
		/// </summary>
		/// <returns><c>true</c>, if fetch was pred, <c>false</c> otherwise.</returns>
		/// <param name="path">Path.</param>
		public  bool PreFetch(EntryPath path){
			string url = Config.PREFETCH_HOST + "/prefetch/" + path.Base64EncodedURI;
			CallRet ret = Call (url);
			return ret.OK;
		}
示例#32
0
        /// <summary>
        /// 文件信息查看
        /// </summary>
        /// <param name="scope"></param>
        /// <returns>文件的基本信息,见<see cref="Entry">Entry</see></returns>
        public Entry Stat(EntryPath scope)
        {
            CallRet callRet = op(FileHandle.STAT, scope);

            return(new Entry(callRet));
        }
示例#33
0
 /// <summary>
 /// 抓取资源
 /// </summary>
 /// <param name="fromUrl">需要抓取的文件URL</param>
 /// <param name="entryPath">目标entryPath</param>
 /// <returns>见<see cref="CallRet">CallRet</see></returns>
 public async Task <CallRet> FetchAsync(string fromUrl, EntryPath entryPath)
 {
     return(await opFetchAsync(FileHandle.FETCH, fromUrl, entryPath));
 }
示例#34
0
		/// <summary>
		/// Pres the fetch.
		/// </summary>
		/// <returns><c>true</c>, if fetch was pred, <c>false</c> otherwise.</returns>
		/// <param name="path">Path.</param>
		public async System.Threading.Tasks.Task<bool> PreFetch(EntryPath path)
		{
			string url = Config.PREFETCH_HOST + "/prefetch/" + path.Base64EncodedURI;
			CallRet ret = await Call(url);
			return ret.OK;
		}
示例#35
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="bucket">七牛云存储空间名称</param>
        /// <param name="key">需要删除的文件key</param>
        /// <returns></returns>
        public CallRet Delete(EntryPath scope)
        {
            CallRet callRet = op(FileHandle.DELETE, scope);

            return(new Entry(callRet));
        }
示例#36
0
 private CallRet Mkfile(Client client, string key, long fsize)
 {
     EntryPath entry = new EntryPath (extra.Bucket, key);
     string url = string.Format ("{0}/rs-mkfile/{1}/fsize/{2}/", Config.UP_HOST, entry.Base64EncodedURI, fsize);
     if (!string.IsNullOrEmpty (extra.MimeType)) {
         url += (string.Format ("/mimeType/{0}", extra.MimeType.ToBase64URLSafe ()));
     }
     if (!string.IsNullOrEmpty (extra.CustomMeta)) {
         url += (string.Format ("/meta/{0}", extra.CustomMeta.ToBase64URLSafe ()));
     }
     if (!string.IsNullOrEmpty (extra.CallbackParams)) {
         url += (string.Format ("/params/{0}", extra.CallbackParams.ToBase64URLSafe ()));
     }
     int proCount = extra.Progresses.Length;
     using (Stream body = new MemoryStream()) {
         for (int i = 0; i < proCount; i++) {
             byte[] bctx = Encoding.ASCII.GetBytes (extra.Progresses [i].ctx);
             body.Write (bctx, 0, bctx.Length);
             if (i != proCount - 1) {
                 body.WriteByte ((byte)',');
             }
         }
         body.Seek (0, SeekOrigin.Begin);
         return client.CallWithBinary (url, "text/plain", body, body.Length);
     }
 }
示例#37
0
        /// <summary>
        /// 文件信息查看
        /// </summary>
        /// <param name="scope"></param>
        /// <returns>文件的基本信息,见<see cref="Entry">Entry</see></returns>
        public async Task <Entry> StatAsync(EntryPath scope)
        {
            CallRet callRet = await opAsync(FileHandle.STAT, scope);

            return(new Entry(callRet));
        }