/// <summary>
        /// End the asynchronous request for creating a bucket.
        /// </summary>
        /// <param name="ar">Response to the asynchronous request</param>
        /// <returns>Response to the bucket creation request</returns>
        public CreateBucketResponse EndCreateBucket(IAsyncResult ar)
        {
            HttpObsAsyncResult result = ar as HttpObsAsyncResult;

            try
            {
                return(this.EndDoRequest <CreateBucketRequest, CreateBucketResponse>(ar, false));
            }
            catch (ObsException ex)
            {
                if (result != null && result.HttpContext != null &&
                    result.HttpRequest != null &&
                    ex.StatusCode == HttpStatusCode.BadRequest &&
                    "Unsupported Authorization Type".Equals(ex.ErrorMessage) &&
                    this.ObsConfig.AuthTypeNegotiation &&
                    result.HttpContext.AuthType == AuthTypeEnum.OBS)
                {
                    if (result.HttpRequest.Content != null && result.HttpRequest.Content.CanSeek)
                    {
                        result.HttpRequest.Content.Seek(0, SeekOrigin.Begin);
                    }
                    result.HttpContext.AuthType = AuthTypeEnum.V2;
                    HttpObsAsyncResult retryResult = this.httpClient.BeginPerformRequest(result.HttpRequest, result.HttpContext,
                                                                                         result.AsyncCallback, result.AsyncState);

                    retryResult.AdditionalState = result.AdditionalState;
                    return(this.EndDoRequest <CreateBucketRequest, CreateBucketResponse>(retryResult));
                }
                throw ex;
            }
            finally
            {
                CommonUtil.CloseIDisposable(result);
            }
        }
        internal IAsyncResult BeginDoRequest <T>(T request, DoValidateDelegate doValidateDelegate,
                                                 AsyncCallback callback, object state) where T : ObsWebServiceRequest
        {
            HttpContext context = this.BeforeRequest(request, doValidateDelegate, true);

            try
            {
                HttpObsAsyncResult result = this.httpClient.BeginPerformRequest(this.PrepareHttpRequest(request, context), context, callback, state);

                result.AdditionalState = new object[] { request, context };
                return(result);
            }
            catch (ObsException ex)
            {
                if (LoggerMgr.IsErrorEnabled)
                {
                    LoggerMgr.Error(string.Format("{0} exception code: {1}, with message: {2}", request.GetAction(), ex.ErrorCode, ex.Message));
                }
                throw ex;
            }
            catch (Exception ex)
            {
                if (LoggerMgr.IsErrorEnabled)
                {
                    LoggerMgr.Error(string.Format("{0} exception with message: {1}", request.GetAction(), ex.Message));
                }
                throw new ObsException(ex.Message, ex);
            }
        }
        internal K EndDoRequest <T, K>(IAsyncResult ar, bool autoClose)
            where T : ObsWebServiceRequest
            where K : ObsWebServiceResponse
        {
            if (ar == null)
            {
                throw new ObsException(Constants.NullRequestMessage, ErrorType.Sender, Constants.NullRequest, "");
            }
            HttpObsAsyncResult result = ar as HttpObsAsyncResult;

            if (result == null)
            {
                throw new ObsException(Constants.NullRequestMessage, ErrorType.Sender, Constants.NullRequest, "");
            }
            object[] additionalState = result.AdditionalState as object[];

            T           request = additionalState[0] as T;
            HttpContext context = additionalState[1] as HttpContext;

            try
            {
                HttpResponse httpResponse = this.httpClient.EndPerformRequest(result);
                return(this.PrepareResponse <T, K>(request, context, result.HttpRequest, httpResponse));
            }
            catch (ObsException ex)
            {
                if (LoggerMgr.IsErrorEnabled)
                {
                    LoggerMgr.Error(string.Format("{0} exception code: {1}, with message: {2}", request.GetAction(), ex.ErrorCode, ex.Message));
                }
                throw ex;
            }
            catch (Exception ex)
            {
                if (LoggerMgr.IsErrorEnabled)
                {
                    LoggerMgr.Error(string.Format("{0} exception with message: {1}", request.GetAction(), ex.Message));
                }
                throw new ObsException(ex.Message, ex);
            }
            finally
            {
                if (autoClose)
                {
                    if (request != null)
                    {
                        request.Sender = null;
                    }

                    CommonUtil.CloseIDisposable(result);
                }

                if (LoggerMgr.IsInfoEnabled)
                {
                    LoggerMgr.Info(string.Format("{0} end, cost {1} ms", request.GetAction(), (DateTime.Now - result.RequestStartDateTime).TotalMilliseconds));
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 结束对复制段的异步请求。
        /// </summary>
        /// <param name="ar">异步请求的响应结果。</param>
        /// <returns>复制段的响应结果。</returns>
        public CopyPartResponse EndCopyPart(IAsyncResult ar)
        {
            CopyPartResponse   response = this.EndDoRequest <CopyPartRequest, CopyPartResponse>(ar);
            HttpObsAsyncResult result   = ar as HttpObsAsyncResult;
            CopyPartRequest    request  = result.AdditionalState as CopyPartRequest;

            response.PartNumber = request.PartNumber;
            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// 结束对上传段的异步请求。
        /// </summary>
        /// <param name="ar">异步请求的响应结果。</param>
        /// <returns>上传段的响应结果。</returns>
        public UploadPartResponse EndUploadPart(IAsyncResult ar)
        {
            UploadPartResponse response = this.EndDoRequest <UploadPartRequest, UploadPartResponse>(ar);
            HttpObsAsyncResult result   = ar as HttpObsAsyncResult;
            UploadPartRequest  request  = result.AdditionalState as UploadPartRequest;

            response.PartNumber = request.PartNumber;
            return(response);
        }
Beispiel #6
0
        /// <summary>
        /// 结束对获取对象属性的异步请求。
        /// </summary>
        /// <param name="ar">异步请求的响应结果。</param>
        /// <returns>获取对象属性的响应结果。</returns>
        public GetObjectMetadataResponse EndGetObjectMetadata(IAsyncResult ar)
        {
            GetObjectMetadataResponse response = this.EndDoRequest <GetObjectMetadataRequest, GetObjectMetadataResponse>(ar);
            HttpObsAsyncResult        result   = ar as HttpObsAsyncResult;
            GetObjectMetadataRequest  request  = result.AdditionalState as GetObjectMetadataRequest;

            response.BucketName = request.BucketName;
            response.ObjectKey  = request.ObjectKey;
            return(response);
        }