/// 获取地域的存储桶列表 public void GetRegionalService() { //.cssg-snippet-body-start:[get-regional-service] try { GetServiceRequest request = new GetServiceRequest(); string region = "ap-guangzhou"; request.host = $"cos.{region}.myqcloud.com"; //执行请求 GetServiceResult result = cosXml.GetService(request); //得到所有的 buckets List <ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets; } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
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 Task <List <Bucket> > ListBucketsAsync() { GetServiceRequest request = new GetServiceRequest(); GetServiceResult result = _client.GetService(request); if (result == null || result.listAllMyBuckets == null) { throw new Exception("List buckets result is null."); } //得到所有的 buckets List <ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets; List <Bucket> buckets = new List <Bucket>(); foreach (var item in allBuckets) { buckets.Add(new Bucket() { Location = item.location, Name = item.name, Owner = new Owner() { Id = result.listAllMyBuckets.owner.id, Name = result.listAllMyBuckets.owner.disPlayName, }, CreationDate = item.createDate }); } return(Task.FromResult(buckets)); }
public void GetServerTest() { try { QCloudServer instance = new QCloudServer(); GetServiceRequest request = new GetServiceRequest(); GetServiceResult result = instance.cosXml.GetService(request); Assert.True(result.httpCode == 200); // Console.WriteLine(result.GetResultInfo()); Assert.IsNotEmpty((result.GetResultInfo())); ValidateBucketList(result.listAllMyBuckets); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.Fail(); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.Fail(); } }
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 async Task <ResponseModel> SelectBucket(int tokenTome = 600) { try { GetServiceRequest request = new GetServiceRequest(); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), tokenTome); //执行请求 GetServiceResult result = await Task.FromResult(_cosXml.GetService(request)); return(new ResponseModel { Code = 200, Message = "Success", Data = result.GetResultInfo() }); } catch (COSXML.CosException.CosClientException clientEx) { return(new ResponseModel { Code = 0, Message = "CosClientException: " + clientEx.Message }); } catch (CosServerException serverEx) { return(new ResponseModel { Code = 0, Message = "CosServerException: " + serverEx.GetInfo() }); } }
public void ParseResponseTest() { GetServiceResult target = new GetServiceResult(); // TODO: Initialize to an appropriate value Response response = null; // TODO: Initialize to an appropriate value target.ParseResponse(response); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public void GetResultInfoTest() { GetServiceResult target = new GetServiceResult(); // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; actual = target.GetResultInfo(); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void SyncGetServerTest() { QCloudServer instance = QCloudServer.Instance(); GetServiceRequest request = new GetServiceRequest(); GetServiceResult result = instance.cosXml.Execute <GetServiceResult>(request); Assert.True(result.httpCode == 200); Assert.IsNotEmpty((result.GetResultInfo())); ValidateBucketList(result.listAllMyBuckets); }
public async Task AsyncGetServerTest() { QCloudServer instance = QCloudServer.Instance(); GetServiceRequest request = new GetServiceRequest(); GetServiceResult result = await instance.cosXml.ExecuteAsync <GetServiceResult>(request); Assert.True(result.httpCode == 200); // Console.WriteLine(result.GetResultInfo()); Assert.IsNotEmpty((result.GetResultInfo())); ValidateBucketList(result.listAllMyBuckets); }
/// <summary> /// 查询存储桶列表 /// </summary> public ResultModel <ListAllMyBuckets> GetChucunto() { CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(SetConnectionTimeoutMs) //设置连接超时时间,单位毫秒,默认45000ms .SetReadWriteTimeoutMs(SetReadWriteTimeoutMs) //设置读写超时时间,单位毫秒,默认45000ms .IsHttps(IsHttps) //设置默认 HTTPS 请求 .SetAppid(SetAppid) //设置腾讯云账户的账户标识 APPID .SetRegion(SetRegion) //设置一个默认的存储桶地域 .Build(); string secretId = SecretId; //云 API 密钥 SecretId string secretKey = SecretKey; //云 API 密钥 SecretKey long durationSecond = DurationSecond; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider); ResultModel <ListAllMyBuckets> result = new ResultModel <ListAllMyBuckets>(); try { GetServiceRequest request = new GetServiceRequest(); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 GetServiceResult cosresult = cosXml.GetService(request); result.date = cosresult.listAllMyBuckets; result.success = true; result.code = 200; result.message = cosresult.GetResultInfo(); //请求成功 return(result); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 result.message = clientEx.Message; result.success = false; return(result); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 result.message = serverEx.Message; result.success = false; return(result); } }
public void getService() { //.cssg-snippet-body-start:[get-service] CosXmlConfig config = new CosXmlConfig.Builder() .SetConnectionTimeoutMs(60000) //设置连接超时时间,单位毫秒,默认45000ms .SetReadWriteTimeoutMs(40000) //设置读写超时时间,单位毫秒,默认45000ms .IsHttps(true) //设置默认 HTTPS 请求 .SetAppid("1253653367") //设置腾讯云账户的账户标识 APPID .SetRegion("ap-guangzhou") //设置一个默认的存储桶地域 .Build(); string secretId = Environment.GetEnvironmentVariable("COS_KEY"); //云 API 密钥 SecretId string secretKey = Environment.GetEnvironmentVariable("COS_SECRET"); //云 API 密钥 SecretKey long durationSecond = 600; //每次请求签名有效时长,单位为秒 QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, secretKey, durationSecond); CosXml cosXml = new CosXmlServer(config, qCloudCredentialProvider); try { GetServiceRequest request = new GetServiceRequest(); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 GetServiceResult result = cosXml.GetService(request); //得到所有的 buckets List <ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets; } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); Assert.Null(clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.Null(serverEx); } //.cssg-snippet-body-end }
public void GetServerTest() { try { QCloudServer instance = QCloudServer.Instance(); GetServiceRequest request = new GetServiceRequest(); GetServiceResult result = instance.cosXml.GetService(request); Console.WriteLine(result.GetResultInfo()); Assert.True(true); } catch (COSXML.CosException.CosClientException clientEx) { Console.WriteLine("CosClientException: " + clientEx.Message); Assert.True(false); } catch (COSXML.CosException.CosServerException serverEx) { Console.WriteLine("CosServerException: " + serverEx.GetInfo()); Assert.True(false); } }
public static CosListAllMyBucketsResponseDto QueryBucketList() { var cosXml = InitializeCosConfig(); var response = new CosListAllMyBucketsResponseDto() { BucketsList = new List <ListAllMyBuckets.Bucket>() }; try { GetServiceRequest request = new GetServiceRequest(); //设置签名有效时长 request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600); //执行请求 GetServiceResult result = cosXml.GetService(request); //得到所有的 buckets response.statusCode = result.httpCode; response.statusMessage = result.httpMessage; response.BucketsList = result.listAllMyBuckets.buckets;; return(response); } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 response.statusCode = clientEx.errorCode; response.statusMessage = clientEx.Message; response.info = clientEx.ToJson(); return(response); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 response.statusCode = serverEx.statusCode; response.statusMessage = serverEx.statusMessage; response.info = serverEx.GetInfo(); return(response); } }
/// 获取存储桶列表 public void GetService() { //.cssg-snippet-body-start:[get-service] try { GetServiceRequest request = new GetServiceRequest(); //执行请求 GetServiceResult result = cosXml.GetService(request); //得到所有的 buckets List <ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets; } catch (COSXML.CosException.CosClientException clientEx) { //请求失败 Console.WriteLine("CosClientException: " + clientEx); } catch (COSXML.CosException.CosServerException serverEx) { //请求失败 Console.WriteLine("CosServerException: " + serverEx.GetInfo()); } //.cssg-snippet-body-end }
public void AsyncGetServerTest() { bool isSuccess = false; ManualResetEvent manualResetEvent = new ManualResetEvent(false); QCloudServer instance = QCloudServer.Instance(); GetServiceRequest request = new GetServiceRequest(); instance.cosXml.GetService(request, delegate(COSXML.Model.CosResult cosResult) { GetServiceResult result = cosResult as GetServiceResult; Console.WriteLine(result.GetResultInfo()); isSuccess = true; manualResetEvent.Set(); }, delegate(COSXML.CosException.CosClientException clientEx, COSXML.CosException.CosServerException serverEx) { Console.WriteLine(clientEx == null ? serverEx.GetInfo() : clientEx.Message); isSuccess = false; manualResetEvent.Set(); }); manualResetEvent.WaitOne(); Assert.True(isSuccess); }
public void GetServiceResultConstructorTest() { GetServiceResult target = new GetServiceResult(); Assert.Inconclusive("TODO: Implement code to verify target"); }