/// <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);
     }
 }
 public static void Init(HttpClientConfig config, QCloudCredentialProvider credentialsProvider)
 {
     lock (sync)
     {
         HttpClient.config = config;
         HttpClient.credentialsProvider = credentialsProvider;
         // init grobal httpwebreqeust
         CommandTask.Init(HttpClient.config);
     }
 }
Exemple #3
0
        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;
        }
Exemple #4
0
        public HttpClient(HttpClientConfig config)
        {
            if (config != null)
            {
                this.config = config;
            }
            else
            {
                this.config = new HttpClientConfig.Builder().Build();
            }

            // init grobal httpwebreqeust
            CommandTask.Init(this.config);
        }
 public static void Init(HttpClientConfig config, QCloudCredentialProvider credentialsProvider)
 {
     lock (sync)
     {
         if (config == null)
         {
             throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "HttpClientConfig = null");
         }
         HttpClient.config = config;
         HttpClient.credentialsProvider = credentialsProvider;
         // init grobal httpwebreqeust
         CommandTask.Init(HttpClient.config);
     }
 }
Exemple #6
0
 public void Init(HttpClientConfig config)
 {
     if (this.config == null)
     {
         lock (sync)
         {
             if (this.config == null)
             {
                 this.config = config;
                 // init grobal httpwebreqeust
                 CommandTask.Init(this.config);
             }
         }
     }
 }
 public void excute(Request request, Response response)
 {
     try
     {
         CommandTask.Excute(request, response, config);
     }
     catch (CosServerException)
     {
         throw;
     }
     catch (CosClientException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new CosClientException((int)CosClientError.BAD_REQUEST, ex.Message, ex);
     }
 }
Exemple #8
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);
            }
        }