Exemple #1
0
        public static void AsynListBucketVersions(COSXML.CosXml cosXml, string bucket)
        {
            ListBucketVersionsRequest request = new ListBucketVersionsRequest(bucket);

            //设置签名有效时长
            request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);

            //执行请求
            cosXml.ListBucketVersions(request,
                                      delegate(CosResult cosResult)
            {
                ListBucketVersionsResult result = cosResult as ListBucketVersionsResult;
                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());
                }
            });
        }
Exemple #2
0
        public static void ListBucketVersions(COSXML.CosXml cosXml, string bucket)
        {
            try
            {
                ListBucketVersionsRequest request = new ListBucketVersionsRequest(bucket);
                //设置签名有效时长
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.SECONDS), 600);
                //执行请求
                ListBucketVersionsResult result = cosXml.ListBucketVersions(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());
            }
        }
        public void ListBucketVersions()
        {
            try
            {
                var service = QCloudServer.Instance().NewService(QCloudServer.Instance().regionForBucketVersioning);

                ListBucketVersionsRequest request = new ListBucketVersionsRequest(QCloudServer.Instance().bucketVersioning);
                request.SetDelimiter("/");
                request.SetEncodingType("url");
                request.SetMaxKeys("500");

                //执行请求
                ListBucketVersionsResult result = service.ListBucketVersions(request);

                Assert.True(result.httpCode == 200);
                // Console.WriteLine(result.GetResultInfo());
                Assert.IsNotEmpty((result.GetResultInfo()));

                var listObjects = result.listBucketVersions;

                Assert.NotNull(listObjects.delimiter);
                Assert.NotNull(listObjects.encodingType);
                Assert.NotNull(listObjects.name);
                Assert.NotZero(listObjects.maxKeys);
                Assert.IsFalse(listObjects.isTruncated);

                Assert.That(listObjects.prefix, Is.Null.Or.Empty);
                Assert.That(listObjects.keyMarker, Is.Null.Or.Empty);
                Assert.That(listObjects.versionIdMarker, Is.Null.Or.Empty);
                Assert.That(listObjects.nextVersionIdMarker, Is.Null.Or.Empty);
                Assert.That(listObjects.nextKeyMarker, Is.Null.Or.Empty);

                Assert.NotZero(listObjects.commonPrefixesList.Count);
                foreach (var commonPrefix in listObjects.commonPrefixesList)
                {
                    Assert.NotNull(commonPrefix.prefix);
                }

                Assert.NotZero(listObjects.objectVersionList.Count);
                foreach (var content in listObjects.objectVersionList)
                {
                    Assert.NotNull(content.eTag);
                    Assert.NotNull(content.owner);
                    Assert.NotNull(content.owner.uid);
                    Assert.NotNull(content.owner.displayName);
                    Assert.NotNull(content.key);
                    Assert.NotNull(content.lastModified);
                    Assert.NotNull(content.size);
                    Assert.NotNull(content.storageClass);
                    Assert.NotNull(content.versionId);
                    Assert.NotNull(content.isLatest);
                }

                Assert.NotZero(listObjects.deleteMarkers.Count);
                foreach (var content in listObjects.deleteMarkers)
                {
                    Assert.NotNull(content.owner);
                    Assert.NotNull(content.owner.uid);
                    Assert.NotNull(content.owner.displayName);
                    Assert.NotNull(content.key);
                    Assert.NotNull(content.lastModified);
                    Assert.NotNull(content.versionId);
                    Assert.NotNull(content.isLatest);
                }
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.Fail();
            }
        }