示例#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 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());
            //}
        }
示例#3
0
        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));
        }
示例#4
0
        /// 获取存储桶列表
        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
        }