コード例 #1
0
        public Task <T> ExecuteAsync <T>(CosRequest request) where T : CosResult
        {
            T result = Activator.CreateInstance <T>();

            CheckAppidAndRegion(request);

            var t = new TaskCompletionSource <T>();


            Schedue(request, result,
                    delegate(CosResult cosResult)
            {
                t.TrySetResult(result as T);
            }

                    , delegate(CosClientException clientException, CosServerException serverException)
            {
                if (clientException != null)
                {
                    t.TrySetException(clientException);
                }
                else
                {
                    t.TrySetException(serverException);
                }
            }
                    );

            return(t.Task);
        }
コード例 #2
0
        internal override void ExternInfo(CosRequest cosRequest)
        {
            base.ExternInfo(cosRequest);
            GetObjectBytesRequest getObjectBytesRequest = cosRequest as GetObjectBytesRequest;

            this.progressCallback = getObjectBytesRequest.GetCosProgressCallback();
        }
コード例 #3
0
 private void CheckAppidAndRegion(CosRequest request)
 {
     request.serviceConfig = config;
     if (request.IsHttps == null)
     {
         request.IsHttps = config.IsHttps;
     }
     if (request is GetServiceRequest)
     {
         return;
     }
     if (request.APPID == null)
     {
         request.APPID = config.Appid;
     }
     if (request is ObjectRequest)
     {
         if (((ObjectRequest)request).Region == null)
         {
             ((ObjectRequest)request).Region = config.Region;
         }
         return;
     }
     if (request is BucketRequest)
     {
         if (((BucketRequest)request).Region == null)
         {
             ((BucketRequest)request).Region = config.Region;
         }
         return;
     }
 }
コード例 #4
0
 public string GetAccessURL(CosRequest request)
 {
     try
     {
         CheckAppidAndRegion(request);
         request.CheckParameters();
         StringBuilder urlBuilder = new StringBuilder();
         if (request.IsHttps != null && (bool)request.IsHttps)
         {
             urlBuilder.Append("https://");
         }
         else
         {
             urlBuilder.Append("http://");
         }
         urlBuilder.Append(request.GetHost());
         urlBuilder.Append(request.RequestPath);
         return(urlBuilder.ToString());
     }
     catch (CosClientException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, ex.Message, ex);
     }
 }
コード例 #5
0
        public T Execute <T>(CosRequest request) where T : CosResult
        {
            T result = Activator.CreateInstance <T>();


            return((T)Excute(request, result));
        }
コード例 #6
0
        private CosResult Excute(CosRequest request, CosResult result)
        {
            CheckAppidAndRegion(request);
            httpClient.Excute(request, result, credentialProvider);

            return(result);
        }
コード例 #7
0
 public void Cancel(CosRequest cosRequest)
 {
     if (cosRequest != null)
     {
         cosRequest.Cancel();
     }
 }
コード例 #8
0
 /// <summary>
 /// excute request
 /// </summary>
 /// <param name="cosRequest"></param>
 /// <param name="cosResult"></param>
 /// <exception cref="COSXML.CosException.CosClientException">CosClientException</exception>
 /// <exception cref="COSXML.CosException.CosServerException">CosServerException</exception>
 public void Excute(CosRequest cosRequest, CosResult cosResult)
 {
     try
     {
         Request request = CreateRequest(cosRequest);
         //extern informations exchange
         //cosResult.ExternInfo(cosRequest);
         Response response;
         if (cosRequest is GetObjectRequest)
         {
             GetObjectRequest getObjectRequest = cosRequest as GetObjectRequest;
             response = new CosResponse(cosResult, getObjectRequest.GetSaveFilePath(), getObjectRequest.GetLocalFileOffset(),
                                        getObjectRequest.GetCosProgressCallback());
         }
         else
         {
             response = new CosResponse(cosResult, null, -1L, null);
         }
         cosRequest.BindRequest(request);
         CommandTask.Excute(request, response, config);
     }
     catch (CosServerException)
     {
         throw;
     }
     catch (CosClientException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new CosClientException((int)CosClientError.BAD_REQUEST, ex.Message, ex);
     }
 }
コード例 #9
0
ファイル: HttpClient.cs プロジェクト: sitsh/qcloud-sdk-dotnet
 /// <summary>
 /// excute request
 /// </summary>
 /// <param name="cosRequest"></param>
 /// <param name="cosResult"></param>
 /// <exception cref="COSXML.CosException.CosClientException">CosClientException</exception>
 /// <exception cref="COSXML.CosException.CosServerException">CosServerException</exception>
 public void Excute(CosRequest cosRequest, CosResult cosResult)
 {
     //HttpTask httpTask = new HttpTask();
     //httpTask.cosRequest = cosRequest;
     //httpTask.cosResult = cosResult;
     //httpTask.isSchedue = false;
     InternalExcute(cosRequest, cosResult);
 }
コード例 #10
0
 /// <summary>
 /// excute request
 /// </summary>
 /// <param name="cosRequest"></param>
 /// <param name="cosResult"></param>
 /// <param name="credentialProvider"></param>
 /// <exception cref="COSXML.CosException.CosClientException">CosClientException</exception>
 /// <exception cref="COSXML.CosException.CosServerException">CosServerException</exception>
 public void Excute(CosRequest cosRequest, CosResult cosResult, QCloudCredentialProvider credentialProvider)
 {
     //HttpTask httpTask = new HttpTask();
     //httpTask.cosRequest = cosRequest;
     //httpTask.cosResult = cosResult;
     //httpTask.isSchedue = false;
     InternalExcute(cosRequest, cosResult, credentialProvider);
 }
コード例 #11
0
ファイル: HttpClient.cs プロジェクト: P79N6A/C-_COS
        private bool CheckHasSign(CosRequest cosRequest)
        {
            if (cosRequest.GetRequestHeaders().ContainsKey(CosRequestHeaderKey.AUTHORIZAIION))
            {
                return(true);
            }

            return(false);
        }
コード例 #12
0
        private Request CreateRequest(CosRequest cosRequest)
        {
            cosRequest.CheckParameters();
            string  requestUrlWithSign = cosRequest.RequestURLWithSign;
            Request request            = new Request();

            request.Method = cosRequest.Method;
            if (requestUrlWithSign != null)
            {
                if (requestUrlWithSign.StartsWith("https"))
                {
                    request.IsHttps = true;
                }
                else
                {
                    request.IsHttps = false;
                }
                request.RequestUrlString = requestUrlWithSign;
            }
            else
            {
                request.IsHttps = (bool)cosRequest.IsHttps;
                request.Url     = CreateUrl(cosRequest);
                request.Host    = cosRequest.GetHost();
            }
            request.UserAgent = config.UserAgnet;
            Dictionary <string, string> headers = cosRequest.GetRequestHeaders();

            if (headers != null)
            {
                foreach (KeyValuePair <string, string> pair in headers)
                {
                    request.AddHeader(pair.Key, pair.Value);
                }
            }
            request.Body = cosRequest.GetRequestBody();

            // cacluate md5
            if (CheckNeedMd5(request, cosRequest.IsNeedMD5) && request.Body != null)
            {
                request.AddHeader(CosRequestHeaderKey.CONTENT_MD5, request.Body.GetMD5());
            }
            // content type header
            if (request.Body != null && request.Body.ContentType != null &&
                !request.Headers.ContainsKey(CosRequestHeaderKey.CONTENT_TYPE))
            {
                request.AddHeader(CosRequestHeaderKey.CONTENT_TYPE, request.Body.ContentType);
            }

            //cacluate sign, and add it.
            if (requestUrlWithSign == null)
            {
                CheckSign(cosRequest.GetSignSourceProvider(), request);
            }
            return(request);
        }
コード例 #13
0
 public void Schedue(CosRequest cosRequest, CosResult cosResult, COSXML.Callback.OnSuccessCallback <CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback, QCloudCredentialProvider credentialProvider)
 {
     //HttpTask httpTask = new HttpTask();
     //httpTask.cosRequest = cosRequest;
     //httpTask.cosResult = cosResult;
     //httpTask.isSchedue = true;
     //httpTask.successCallback = successCallback;
     //httpTask.failCallback = failCallback;
     InternalSchedue(cosRequest, cosResult, successCallback, failCallback, credentialProvider);
 }
コード例 #14
0
        private HttpUrl CreateUrl(CosRequest cosRequest)
        {
            HttpUrl httpUrl = new HttpUrl();

            httpUrl.Scheme = (bool)cosRequest.IsHttps ? "https" : "http";
            httpUrl.Host   = cosRequest.GetHost();
            httpUrl.Path   = URLEncodeUtils.EncodePathOfURL(cosRequest.RequestPath);
            httpUrl.SetQueryParameters(cosRequest.GetRequestParamters());
            return(httpUrl);
        }
コード例 #15
0
ファイル: HttpClient.cs プロジェクト: P79N6A/C-_COS
        private HttpUrl CreateUrl(CosRequest cosRequest)
        {
            HttpUrl httpUrl = new HttpUrl();

            httpUrl.Scheme(cosRequest.IsHttps ? "https" : "http");
            httpUrl.Host(cosRequest.GetHost());
            httpUrl.SetPath(cosRequest.RequestPath);
            httpUrl.SetQueryParamters(cosRequest.GetRequestParamters());
            return(httpUrl);
        }
コード例 #16
0
ファイル: HttpClient.cs プロジェクト: P79N6A/C-_COS
        public void excute(CosRequest cosRequest, CosResult cosResult)
        {
            Request  request  = CreateRequest(cosRequest);
            Response response = new Response();

            response.Body = cosResult.GetResponseBody();
            CommandTask.excute(request, response, config);
            cosResult.httpCode        = response.Code;
            cosResult.httpMessage     = response.Message;
            cosResult.responseHeaders = response.Headers;
        }
コード例 #17
0
ファイル: HttpClient.cs プロジェクト: P79N6A/C-_COS
        private Request CreateRequest(CosRequest cosRequest)
        {
            Request request = new Request();

            request.Method  = cosRequest.Method;
            request.IsHttps = cosRequest.IsHttps;
            request.SetHttpUrl(CreateUrl(cosRequest));
            Dictionary <string, string> headers = cosRequest.GetRequestHeaders();

            if (headers != null)
            {
                foreach (KeyValuePair <string, string> pair in headers)
                {
                    request.AddHeader(pair.Key, pair.Value);
                }
            }

            request.Body = cosRequest.GetRequestBody();
            return(request);
        }
コード例 #18
0
        public static void SetRequestACLData(CosRequest request)
        {
            request.GetType().GetMethod("SetCosACL", new[] { typeof(CosACL) }).Invoke(request, new object[] { CosACL.Private });

            COSXML.Model.Tag.GrantAccount readAccount = new COSXML.Model.Tag.GrantAccount();
            readAccount.AddGrantAccount("1131975903", "1131975903");
            request.GetType().GetMethod("SetXCosGrantRead").Invoke(request, new object[] { readAccount });

            COSXML.Model.Tag.GrantAccount writeAccount = new COSXML.Model.Tag.GrantAccount();
            writeAccount.AddGrantAccount("1131975903", "1131975903");
            var writeMethod = request.GetType().GetMethod("SetXCosGrantWrite");

            if (writeMethod != null)
            {
                writeMethod.Invoke(request, new object[] { writeAccount });
            }

            COSXML.Model.Tag.GrantAccount fullControlAccount = new COSXML.Model.Tag.GrantAccount();
            fullControlAccount.AddGrantAccount("2832742109", "2832742109");
            request.GetType().GetMethod("SetXCosReadWrite").Invoke(request, new object[] { fullControlAccount });
        }
コード例 #19
0
        // public void Execute(Request request, Response response)
        // {

        //     try
        //     {
        //         CommandTask.Excute(request, response, config);
        //     }
        //     catch (CosServerException)
        //     {
        //         throw;
        //     }
        //     catch (CosClientException)
        //     {
        //         throw;
        //     }
        //     catch (Exception ex)
        //     {
        //         throw new CosClientException((int)CosClientError.BadRequest, ex.Message, ex);
        //     }
        // }

        public void InternalSchedue(CosRequest cosRequest, CosResult cosResult, COSXML.Callback.OnSuccessCallback <CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback, QCloudCredentialProvider credentialProvider)
        {
            try
            {
                Request request = CreateRequest(cosRequest, credentialProvider);
                cosResult.ExternInfo(cosRequest);
                Response response;

                if (cosRequest is GetObjectRequest)
                {
                    GetObjectRequest getObjectRequest = cosRequest as GetObjectRequest;

                    response = new CosResponse(cosResult, getObjectRequest.GetSaveFilePath(), getObjectRequest.GetLocalFileOffset(),
                                               getObjectRequest.GetCosProgressCallback(), successCallback, failCallback);
                }
                else
                {
                    response = new CosResponse(cosResult, null, -1L, null, successCallback, failCallback);
                }

                cosRequest.BindRequest(request);
                CommandTask.Schedue(request, response, config);
            }
            catch (CosServerException serverException)
            {
                //throw serverException;
                failCallback(null, serverException);
            }
            catch (CosClientException clientException)
            {
                //throw clientException;
                failCallback(clientException, null);
            }
            catch (Exception ex)
            {
                //throw new CosClientException((int)CosClientError.BAD_REQUEST, ex.Message, ex);
                failCallback(new CosClientException((int)CosClientError.BadRequest, ex.Message, ex), null);
            }
        }
コード例 #20
0
 public void schedue(CosRequest request, CosResult result, COSXML.Callback.OnSuccessCallback <CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback)
 {
     CheckAppidAndRegion(request);
     httpClient.Schedue(request, result, successCallback, failCallback);
 }
コード例 #21
0
 internal override void ExternInfo(CosRequest cosRequest)
 {
     this.outputFilePath   = ((SelectObjectRequest)cosRequest).outputFilePath;
     this.progressCallback = ((SelectObjectRequest)cosRequest).progressCallback;
 }
コード例 #22
0
 private void Schedue(CosRequest request, CosResult result, COSXML.Callback.OnSuccessCallback <CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback)
 {
     CheckAppidAndRegion(request);
     httpClient.Schedue(request, result, successCallback, failCallback, credentialProvider);
 }
コード例 #23
0
 private T Execute <T>(CosRequest request, T result) where T : CosResult
 {
     return((T)Excute(request, result));
 }
コード例 #24
0
 private CosResult excute(CosRequest request, CosResult result)
 {
     CheckAppidAndRegion(request);
     httpClient.Excute(request, result);
     return(result);
 }