Exemplo n.º 1
0
        /// <summary>
        ///     数据处理
        /// </summary>
        /// <param name="bucket">空间</param>
        /// <param name="key">空间文件的key</param>
        /// <param name="fops">操作(命令参数)</param>
        /// <param name="pipeline">私有队列</param>
        /// <param name="notifyUrl">通知url</param>
        /// <param name="force">forece参数</param>
        /// <returns>pfop操作返回结果,正确返回结果包含persistentId</returns>
        public async Task <PfopResult> Pfop(string bucket, string key, string fops, string pipeline, string notifyUrl, bool force)
        {
            var result = new PfopResult();

            try
            {
                var host = await _config.ApiHost(_mac.AccessKey, bucket);

                var pfopUrl = $"{host}/pfop/";

                var sb = new StringBuilder();
                sb.Append($"bucket={StringHelper.UrlEncode(bucket)}&key={StringHelper.UrlEncode(key)}&fops={StringHelper.UrlEncode(fops)}");
                if (!string.IsNullOrEmpty(notifyUrl))
                {
                    sb.Append($"&notifyURL={StringHelper.UrlEncode(notifyUrl)}");
                }

                if (force)
                {
                    sb.Append("&force=1");
                }

                if (!string.IsNullOrEmpty(pipeline))
                {
                    sb.Append($"&pipeline={pipeline}");
                }

                var data  = Encoding.UTF8.GetBytes(sb.ToString());
                var token = _auth.CreateManageToken(pfopUrl, data);

                var hr = await _httpManager.PostFormAsync(pfopUrl, data, token);

                result.Shadow(hr);
            }
            catch (QiniuException ex)
            {
                var sb = new StringBuilder();
                sb.Append($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.ffff}] [pfop] Error:  ");
                Exception e = ex;
                while (e != null)
                {
                    sb.Append(e.Message + " ");
                    e = e.InnerException;
                }

                sb.AppendLine();

                result.Code     = ex.HttpResult.Code;
                result.RefCode  = ex.HttpResult.Code;
                result.Text     = ex.HttpResult.Text;
                result.RefText += sb.ToString();
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 数据处理
        /// </summary>
        /// <param name="bucket">空间</param>
        /// <param name="key">空间文件的key</param>
        /// <param name="fops">操作(命令参数)</param>
        /// <param name="pipeline">私有队列</param>
        /// <param name="notifyUrl">通知url</param>
        /// <param name="force">forece参数</param>
        /// <returns>pfop操作返回结果,正确返回结果包含persistentId</returns>
        public PfopResult Pfop(string bucket, string key, string fops, string pipeline, string notifyUrl, bool force)
        {
            PfopResult result = new PfopResult();

            try
            {
                string pfopUrl = string.Format("{0}/pfop/", this.config.ApiHost(this.mac.AccessKey, bucket));

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("bucket={0}&key={1}&fops={2}", StringHelper.UrlEncode(bucket), StringHelper.UrlEncode(key),
                                StringHelper.UrlEncode(fops));
                if (!string.IsNullOrEmpty(notifyUrl))
                {
                    sb.AppendFormat("&notifyURL={0}", StringHelper.UrlEncode(notifyUrl));
                }
                if (force)
                {
                    sb.Append("&force=1");
                }
                if (!string.IsNullOrEmpty(pipeline))
                {
                    sb.AppendFormat("&pipeline={0}", pipeline);
                }
                byte[] data  = Encoding.UTF8.GetBytes(sb.ToString());
                string token = auth.CreateManageToken(pfopUrl, data);

                HttpResult hr = httpManager.PostForm(pfopUrl, data, token);
                result.Shadow(hr);
            }
            catch (QiniuException ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("[{0}] [pfop] Error:  ", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff"));
                Exception e = ex;
                while (e != null)
                {
                    sb.Append(e.Message + " ");
                    e = e.InnerException;
                }
                sb.AppendLine();

                result.Code     = ex.HttpResult.Code;
                result.RefCode  = ex.HttpResult.Code;
                result.Text     = ex.HttpResult.Text;
                result.RefText += sb.ToString();
            }

            return(result);
        }