예제 #1
0
        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());
                }
            });
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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());
            //}
        }
예제 #4
0
        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()
                });
            }
        }
예제 #5
0
        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.");
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        /// <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);
            }
        }
예제 #9
0
 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);
     }
 }
예제 #10
0
        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);
        }