Exemplo n.º 1
0
        /// <summary>
        /// 获取空间文件信息
        /// </summary>
        /// <param name="bucket">空间名称</param>
        /// <param name="key">文件key</param>
        /// <returns>文件信息获取结果</returns>
        public StatResult Stat(string bucket, string key)
        {
            StatResult result = new StatResult();

            try
            {
                string statUrl = string.Format("{0}{1}", this.config.RsHost(this.mac.AccessKey, bucket),
                                               StatOp(bucket, key));
                string token = auth.CreateManageToken(statUrl);

                HttpResult hr = httpManager.Get(statUrl, token);
                result.Shadow(hr);
            }
            catch (QiniuException ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("[{0}] [stat] 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);
        }
        public StatResult stat(string bucket, string key)
        {
            StatResult statResult  = null;
            string     statUrl     = string.Format("{0}{1}", Config.ZONE.RsHost, statOp(bucket, key));
            string     accessToken = Auth.createManageToken(statUrl, null, this.mac);

            Dictionary <string, string> statHeaders = new Dictionary <string, string>();

            statHeaders.Add("Authorization", accessToken);
            CompletionHandler statCompletionHandler = new CompletionHandler(delegate(ResponseInfo respInfo, string response)
            {
                if (respInfo.isOk())
                {
                    statResult = StringUtils.jsonDecode <StatResult>(response);
                }
                else
                {
                    statResult = new StatResult();
                }
                statResult.Response     = response;
                statResult.ResponseInfo = respInfo;
            });

            this.mHttpManager.get(statUrl, statHeaders, statCompletionHandler);
            return(statResult);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     获取空间文件信息
        /// </summary>
        /// <param name="bucket">空间名称</param>
        /// <param name="key">文件key</param>
        /// <returns>文件信息获取结果</returns>
        public async Task <StatResult> Stat(string bucket, string key)
        {
            var result = new StatResult();

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

                var statUrl = $"{host}{StatOp(bucket, key)}";
                var token   = _auth.CreateManageToken(statUrl);

                var hr = await _httpManager.GetAsync(statUrl, token);

                result.Shadow(hr);
            }
            catch (QiniuException ex)
            {
                var sb = new StringBuilder();
                sb.Append($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.ffff}] [stat] 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);
        }