public static void RestoreObject(COSXML.CosXml cosXml, string bucket, string key) { try { RestoreObjectRequest request = new RestoreObjectRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //恢复时间 request.SetExpireDays(3); request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Bulk); //执行请求 RestoreObjectResult result = cosXml.RestoreObject(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void AsyncGetService(CosXml cosXml) { GetServiceRequest request = new GetServiceRequest(); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); QLog.D("INFO", String.Format("current thread name: {0}-{1}", System.Threading.Thread.CurrentThread.Name, System.Threading.Thread.CurrentThread.ManagedThreadId)); cosXml.GetService(request, delegate(COSXML.Model.CosResult cosResult) { GetServiceResult getServiceResult = cosResult as GetServiceResult; QLog.D("XIAO", getServiceResult.GetResultInfo()); Console.WriteLine(getServiceResult.GetResultInfo()); }, delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx) { QLog.D("INFO", String.Format("current thread name: {0}-{1}", System.Threading.Thread.CurrentThread.Name, System.Threading.Thread.CurrentThread.ManagedThreadId)); if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public static void PostObject(COSXML.CosXml cosXml, string bucket, string key, string srcPath, PostObjectRequest.Policy policy) { try { PostObjectRequest request = new PostObjectRequest(bucket, key, srcPath); //设置签名有效时长 //request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); List <string> headers = new List <string>(); headers.Add("Host"); request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600, headers, null); request.SetCosProgressCallback(delegate(long completed, long total) { Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total)); }); //设置policy request.SetPolicy(policy); //执行请求 PostObjectResult result = cosXml.PostObject(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public void AddHeader(string name, string value) { try { headers.Add(name, value); } catch (ArgumentNullException) { QLog.D(TAG, "AddHeader: name is null"); } catch (ArgumentException) { if (String.IsNullOrEmpty(value)) { return; } if (!String.IsNullOrEmpty(headers[name])) { headers[name] = headers[name] + ',' + value; } else { headers[name] = value; } } }
public static void PutBucketVersioning(COSXML.CosXml cosXml, string bucket) { try { PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //开启版本控制 request.IsEnableVersionConfig(true); //执行请求 PutBucketVersioningResult result = cosXml.PutBucketVersioning(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
internal static void AddHeader(WebHeaderCollection webHeaderCollection, string key, string value) { if (isMonoPlatform == null) { isMonoPlatform = monoPlatforms.Contains(Environment.OSVersion.Platform); } // HTTP headers should be encoded to iso-8859-1, // however it will be encoded automatically by HttpWebRequest in mono. if (false == isMonoPlatform) { // Encode headers for win platforms. } if (addHeaderMethod == null) { // Specify the internal method name for adding headers // mono: AddWithoutValidate // win: AddInternal //var internalMethodName = (isMonoPlatform == false) ? "AddWithoutValidate" : "AddInternal"; var internalMethodName = "AddWithoutValidate"; QLog.D(TAG, internalMethodName.ToString()); var method = typeof(WebHeaderCollection).GetMethod( internalMethodName, BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(string) }, null); addHeaderMethod = method; } addHeaderMethod.Invoke(webHeaderCollection, new Object[] { key, value }); }
/// <summary> /// add authorization /// </summary> /// <param name="qcloudSignSource">QCloudSignSource</param> /// <param name="request"></param> private void CheckSign(QCloudSignSource qcloudSignSource, Request request) { // has authorizaiton, notice: using request.Headers, otherwise, error if (request.Headers.ContainsKey(CosRequestHeaderKey.AUTHORIZAIION)) { QLog.D(TAG, "has add authorizaiton in headers"); return; } //has no authorization, but signSourceProvider == null if (qcloudSignSource == null) { QLog.D(TAG, "signSourceProvider == null"); return; } if (credentialsProvider == null) { throw new ArgumentNullException("credentialsProvider == null"); } CosXmlSigner signer = new CosXmlSigner(); signer.Sign(request, qcloudSignSource, credentialsProvider.GetQCloudCredentials()); }
public static void Copy(string bucket, string key, CopySourceStruct copySource) { COSXMLCopyTask copyTask = new COSXMLCopyTask(bucket, null, key, copySource) { successCallback = delegate(CosResult cosResult) { COSXML.Transfer.COSXMLCopyTask.CopyTaskResult result = cosResult as COSXML.Transfer.COSXMLCopyTask.CopyTaskResult; QLog.D("XIAO", result.GetResultInfo()); Console.WriteLine(result.GetResultInfo()); Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); }, failCallback = delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); } }; transferManager.Copy(copyTask); }
public static void Upload(string bucket, string key, string srcPath, long offset, long sendContentLength) { COSXMLUploadTask uploadTask = new COSXMLUploadTask(bucket, null, key); uploadTask.SetSrcPath(srcPath, offset, sendContentLength); uploadTask.progressCallback = delegate(long completed, long total) { Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total)); }; uploadTask.successCallback = delegate(CosResult cosResult) { COSXML.Transfer.COSXMLUploadTask.UploadTaskResult result = cosResult as COSXML.Transfer.COSXMLUploadTask.UploadTaskResult; QLog.D("XIAO", result.GetResultInfo()); Console.WriteLine(result.GetResultInfo()); Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); }; uploadTask.failCallback = delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); }; transferManager.Upload(uploadTask); }
public static void ListParts(COSXML.CosXml cosXml, string bucket, string key, string uploadId) { try { ListPartsRequest request = new ListPartsRequest(bucket, key, uploadId); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 ListPartsResult result = cosXml.ListParts(request); QLog.D("XIAO", result.GetResultInfo()); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void AsynListParts(COSXML.CosXml cosXml, string bucket, string key, string uploadId) { QLog.D("XIAO", String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); ListPartsRequest request = new ListPartsRequest(bucket, key, uploadId); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); cosXml.ListParts(request, delegate(CosResult cosResult) { ListPartsResult result = cosResult as ListPartsResult; Console.WriteLine(result.GetResultInfo()); Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); QLog.D("XIAO", result.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); }); }
public static void CopyObject(COSXML.CosXml cosXml, string bucket, string key, COSXML.Model.Tag.CopySourceStruct copySource) { try { CopyObjectRequest request = new CopyObjectRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置拷贝源 request.SetCopySource(copySource); //设置是否拷贝还是更新 request.SetCopyMetaDataDirective(COSXML.Common.CosMetaDataDirective.COPY); //执行请求 CopyObjectResult result = cosXml.CopyObject(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void InitMultiUpload(COSXML.CosXml cosXml, string bucket, string key) { try { InitMultipartUploadRequest request = new InitMultipartUploadRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 InitMultipartUploadResult result = cosXml.InitMultipartUpload(request); Console.WriteLine(result.GetResultInfo()); QLog.D("XIAO", result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void MultiDeleteObject(COSXML.CosXml cosXml, string bucket, List <string> keys) { try { DeleteMultiObjectRequest request = new DeleteMultiObjectRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置返回结果形式 request.SetDeleteQuiet(false); //设置删除的keys request.SetObjectKeys(keys); //执行请求 DeleteMultiObjectResult result = cosXml.DeleteMultiObjects(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void AsynGetBucketReplication(COSXML.CosXml cosXml, string bucket) { GetBucketReplicationRequest request = new GetBucketReplicationRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); ///执行请求 cosXml.GetBucketReplication(request, delegate(CosResult cosResult) { GetBucketReplicationResult result = cosResult as GetBucketReplicationResult; Console.WriteLine(result.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public static void AsynPutBucketVersioning(COSXML.CosXml cosXml, string bucket) { PutBucketVersioningRequest request = new PutBucketVersioningRequest(bucket); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //开启版本控制 request.IsEnableVersionConfig(true); ///执行请求 cosXml.PutBucketVersioning(request, delegate(CosResult cosResult) { PutBucketVersioningResult result = cosResult as PutBucketVersioningResult; Console.WriteLine(result.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.Message); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public static void AsyncGetObject(COSXML.CosXml cosXml, string bucket, string key, string localDir, string localFileName) { GetObjectRequest request = new GetObjectRequest(bucket, key, localDir, localFileName); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); request.SetCosProgressCallback(delegate(long completed, long total) { Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total)); }); //执行请求 cosXml.GetObject(request, delegate(CosResult result) { GetObjectResult getObjectResult = result as GetObjectResult; Console.WriteLine(getObjectResult.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public static void UploadParts(COSXML.CosXml cosXml, string bucket, string key, string uploadId, int partNumber, string srcPath) { try { UploadPartRequest request = new UploadPartRequest(bucket, key, partNumber, uploadId, srcPath); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置进度回调 request.SetCosProgressCallback(delegate(long completed, long total) { Console.WriteLine(String.Format("{0} progress = {1} / {2} : {3:##.##}%", DateTime.Now.ToString(), completed, total, completed * 100.0 / total)); }); //执行请求 UploadPartResult result = cosXml.UploadPart(request); Console.WriteLine(result.GetResultInfo()); QLog.D("XIAO", result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void AsynDeleteObject(COSXML.CosXml cosXml, string bucket, string key) { DeleteObjectRequest request = new DeleteObjectRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 cosXml.DeleteObject(request, delegate(CosResult result) { DeleteObjectResult getObjectResult = result as DeleteObjectResult; Console.WriteLine(getObjectResult.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public static void CompleteMultiUpload(COSXML.CosXml cosXml, string bucket, string key, string uploadId, Dictionary <int, string> partNumberAndEtags) { try { CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(bucket, key, uploadId); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置已上传的parts request.SetPartNumberAndETag(partNumberAndEtags); //执行请求 CompleteMultipartUploadResult result = cosXml.CompleteMultiUpload(request); Console.WriteLine(result.GetResultInfo()); } catch (COSXML.CosException.CosClientException clientEx) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } catch (COSXML.CosException.CosServerException serverEx) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }
public static void Download(string bucket, string key, string localDir, string localFileName) { COSXMLDownloadTask downloadTask = new COSXMLDownloadTask(bucket, null, key, localDir, localFileName) { progressCallback = delegate(long completed, long total) { Console.WriteLine(String.Format("progress = {0} / {1} : {2:##.##}%", completed, total, completed * 100.0 / total)); }, successCallback = delegate(CosResult cosResult) { COSXML.Transfer.COSXMLDownloadTask.DownloadTaskResult result = cosResult as COSXML.Transfer.COSXMLDownloadTask.DownloadTaskResult; QLog.D("XIAO", result.GetResultInfo()); Console.WriteLine(result.GetResultInfo()); Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); }, failCallback = delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } Console.WriteLine(String.Format("currentThread id = {0}", Thread.CurrentThread.ManagedThreadId)); } }; transferManager.Download(downloadTask); }
public static void AsynCompleteMultiUpload(COSXML.CosXml cosXml, string bucket, string key, string uploadId, Dictionary <int, string> partNumberAndEtags) { CompleteMultipartUploadRequest request = new CompleteMultipartUploadRequest(bucket, key, uploadId); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置已上传的parts request.SetPartNumberAndETag(partNumberAndEtags); //执行请求 cosXml.CompleteMultiUpload(request, delegate(CosResult result) { CompleteMultipartUploadResult getObjectResult = result as CompleteMultipartUploadResult; Console.WriteLine(getObjectResult.GetResultInfo()); QLog.D("XIAO", result.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public static void GetService(CosXml cosXml) { GetServiceRequest request = new GetServiceRequest(); QLog.D("INFO", String.Format("current thread name: {0}-{1}", System.Threading.Thread.CurrentThread.Name, System.Threading.Thread.CurrentThread.ManagedThreadId)); //设置签名有效时长 //request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 GetServiceResult result = cosXml.GetService(request); QLog.D("XIAO", result.listAllMyBuckets.GetInfo()); QLog.D("XIAO", "bucket count: " + result.listAllMyBuckets.buckets.Count); Console.WriteLine(result.GetResultInfo()); //try //{ // QLog.D("INFO", String.Format("current thread name: {0}-{1}", System.Threading.Thread.CurrentThread.Name, System.Threading.Thread.CurrentThread.ManagedThreadId)); // //设置签名有效时长 // //request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); // //执行请求 // GetServiceResult result = cosXml.GetService(request); // QLog.D("XIAO", result.listAllMyBuckets.GetInfo()); // QLog.D("XIAO", "bucket count: " + result.listAllMyBuckets.buckets.Count); // Console.WriteLine(result.GetResultInfo()); //} //catch (COSXML.CosException.CosClientException clientEx) //{ // Console.WriteLine("CosClientException: " + clientEx.StackTrace); //} //catch (COSXML.CosException.CosServerException serverEx) //{ // Console.WriteLine("CosServerException: " + serverEx.GetInfo()); //} }
public static void AsynPartCopyObject(COSXML.CosXml cosXml, string bucket, string key, COSXML.Model.Tag.CopySourceStruct copySource, string uploadId, int partNumber) { UploadPartCopyRequest request = new UploadPartCopyRequest(bucket, key, partNumber, uploadId); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //设置拷贝源 request.SetCopySource(copySource); //设置拷贝范围 request.SetCopyRange(0, 10); //执行请求 cosXml.PartCopy(request, delegate(CosResult result) { UploadPartCopyResult getObjectResult = result as UploadPartCopyResult; Console.WriteLine(getObjectResult.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public void PaserServerError(Stream inputStream, string contentType, long contentLength) { CosServerException cosServerException = new CosServerException(cosResult.httpCode, cosResult.httpMessage); List <string> values; Headers.TryGetValue("x-cos-request-id", out values); cosServerException.requestId = (values != null && values.Count > 0) ? values[0] : null; Headers.TryGetValue("x-cos-trace-id", out values); cosServerException.traceId = (values != null && values.Count > 0) ? values[0] : null; if (inputStream != null && contentLength > 0) { CosServerError cosServerError = new CosServerError(); try { XmlParse.ParseCosError(inputStream, cosServerError); if (cosServerException.requestId != null) { cosServerException.requestId = cosServerError.requestId; } if (cosServerException.traceId != null) { cosServerException.traceId = cosServerError.traceId; } cosServerException.resource = cosServerError.resource; cosServerException.errorCode = cosServerError.code; cosServerException.errorMessage = cosServerError.message; } catch (Exception ex) { QLog.D(TAG, ex.Message); } } throw cosServerException; }
public static void AsynRestoreObject(COSXML.CosXml cosXml, string bucket, string key) { RestoreObjectRequest request = new RestoreObjectRequest(bucket, key); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //恢复时间 request.SetExpireDays(3); request.SetTier(COSXML.Model.Tag.RestoreConfigure.Tier.Bulk); //执行请求 cosXml.RestoreObject(request, delegate(CosResult result) { RestoreObjectResult getObjectResult = result as RestoreObjectResult; Console.WriteLine(getObjectResult.GetResultInfo()); }, delegate(CosClientException clientEx, CosServerException serverEx) { if (clientEx != null) { QLog.D("XIAO", clientEx.Message); Console.WriteLine("CosClientException: " + clientEx.StackTrace); } if (serverEx != null) { QLog.D("XIAO", serverEx.Message); Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } }); }
public override void Refresh() { //请求STS STSResponse response = new STSResponse(this); HttpClient.GetInstance().excute(request, response); QLog.D("STSQCloudCredentialProvider", String.Format("id ={0}, key ={1}, keyTime = {2}", tmpSecretId, tmpSecretKey, keyTime)); }
public string GetPolicy() { JsonSerializerSettings serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); //驼峰式 serializerSettings.Formatting = Formatting.Indented; //json 显示风格 string json = JsonConvert.SerializeObject(this, serializerSettings); QLog.D("STS", json); return(json); }
/// <summary> /// async to excute /// </summary> /// <param name="request"></param> /// <param name="response"></param> /// <param name="config"></param> public static void Schedue(Request request, Response response, HttpClientConfig config) { HttpWebRequest httpWebRequest = null; RequestState requestState = new RequestState(); try { requestState.request = request; requestState.response = response; httpWebRequest = WebRequest.Create(request.RequestUrlString) as HttpWebRequest; httpWebRequest.AllowWriteStreamBuffering = false; //bind webRequest request.BindHttpWebRequest(httpWebRequest); //handle request header HandleHttpWebRequestHeaders(request, httpWebRequest, config); requestState.httpWebRequest = httpWebRequest; //handle request body if (request.Body != null) { httpWebRequest.ContentLength = request.Body.ContentLength; httpWebRequest.BeginGetRequestStream(new AsyncCallback(AsyncRequestCallback), requestState); } else { //wait for response httpWebRequest.BeginGetResponse(new AsyncCallback(AsyncResponseCallback), requestState); } //print log PrintReqeustInfo(httpWebRequest); } catch (WebException webEx) { response.OnFinish(false, webEx); //abort requestState.Clear(); QLog.D(TAG, webEx.Message, webEx); } catch (Exception ex) { response.OnFinish(false, ex); //abort requestState.Clear(); QLog.E(TAG, ex.Message, ex); } }
public void Clear() { if (httpWebRequest != null) { httpWebRequest.Abort(); } if (httpWebResponse != null) { httpWebResponse.Close(); } QLog.D(TAG, "Close"); }