Beispiel #1
0
        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);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
            }
        }