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); }
internal override void ExternInfo(CosRequest cosRequest) { base.ExternInfo(cosRequest); GetObjectBytesRequest getObjectBytesRequest = cosRequest as GetObjectBytesRequest; this.progressCallback = getObjectBytesRequest.GetCosProgressCallback(); }
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; } }
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); } }
public T Execute <T>(CosRequest request) where T : CosResult { T result = Activator.CreateInstance <T>(); return((T)Excute(request, result)); }
private CosResult Excute(CosRequest request, CosResult result) { CheckAppidAndRegion(request); httpClient.Excute(request, result, credentialProvider); return(result); }
public void Cancel(CosRequest cosRequest) { if (cosRequest != null) { cosRequest.Cancel(); } }
/// <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); } }
/// <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); }
/// <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); }
private bool CheckHasSign(CosRequest cosRequest) { if (cosRequest.GetRequestHeaders().ContainsKey(CosRequestHeaderKey.AUTHORIZAIION)) { return(true); } return(false); }
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); }
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); }
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); }
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); }
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; }
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); }
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 }); }
// 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); } }
public void schedue(CosRequest request, CosResult result, COSXML.Callback.OnSuccessCallback <CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback) { CheckAppidAndRegion(request); httpClient.Schedue(request, result, successCallback, failCallback); }
internal override void ExternInfo(CosRequest cosRequest) { this.outputFilePath = ((SelectObjectRequest)cosRequest).outputFilePath; this.progressCallback = ((SelectObjectRequest)cosRequest).progressCallback; }
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); }
private T Execute <T>(CosRequest request, T result) where T : CosResult { return((T)Excute(request, result)); }
private CosResult excute(CosRequest request, CosResult result) { CheckAppidAndRegion(request); httpClient.Excute(request, result); return(result); }