Ejemplo n.º 1
0
        private void PutBucket()
        {
            try
            {
                PutBucketRequest request = new PutBucketRequest(bucket);
                QCloudServer.SetRequestACLData(request);

                //执行请求
                PutBucketResult result = cosXml.PutBucket(request);

                Assert.AreEqual(result.httpCode, 200);

                isBucketCreatedByTest = true;
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());

                if (serverEx.statusCode != 409)
                {
                    Assert.Fail();
                }
            }
        }
Ejemplo n.º 2
0
        public void CopyObject()
        {
            try
            {
                CopySourceStruct copySource = new CopySourceStruct(QCloudServer.Instance().appid,
                                                                   bucket, QCloudServer.Instance().region, copykey);

                CopyObjectRequest request = new CopyObjectRequest(bucket, multiKey);

                //设置拷贝源
                request.SetCopySource(copySource);

                //设置是否拷贝还是更新
                request.SetCopyMetaDataDirective(COSXML.Common.CosMetaDataDirective.COPY);

                //执行请求
                CopyObjectResult result = cosXml.CopyObject(request);

                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.StackTrace);
                Assert.True(false);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.True(false);
            }
        }
        public void AsyncGetBucket()
        {
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            GetBucketRequest request = new GetBucketRequest(QCloudServer.Instance().bucketForObjectTest);

            ///执行请求
            QCloudServer.Instance().cosXml.GetBucket(request,
                                                     delegate(CosResult cosResult)
            {
                GetBucketResult result = cosResult as GetBucketResult;

                Assert.True(result.httpCode == 200);
                manualResetEvent.Set();
            },

                                                     delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    Console.WriteLine("CosClientException: " + clientEx.Message);
                }

                if (serverEx != null)
                {
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }

                Assert.Fail();
                manualResetEvent.Set();
            }
                                                     );

            manualResetEvent.WaitOne();
        }
Ejemplo n.º 4
0
        public void clear()
        {
            DeleteObject();
            MultiDeleteObject();

            QCloudServer.DeleteAllFile(localDir, "*.txt");
        }
Ejemplo n.º 5
0
        private void PutBucketACL()
        {
            try
            {
                PutBucketACLRequest request = new PutBucketACLRequest(bucket);
                request.SetQueryParameter("time", TimeUtils.GetCurrentTime(TimeUnit.Seconds).ToString());
                request.SetRequestHeader("custom", "value1");
                request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.Seconds), 600, new List <string>()
                {
                    "custome"
                },
                                new List <string>()
                {
                    "time"
                });
                QCloudServer.SetRequestACLData(request);

                //执行请求
                PutBucketACLResult result = cosXml.PutBucketACL(request);

                Assert.AreEqual(result.httpCode, 200);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.Fail();
            }
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
0
        public void SensitiveRecognition()
        {
            //对象键
            try {
                string key = photoKey;

                SensitiveContentRecognitionRequest request = new SensitiveContentRecognitionRequest(bucket, key, "p**n,terrorist,politics");

                SensitiveContentRecognitionResult result = QCloudServer.Instance().cosXml.SensitiveContentRecognition(request);

                // Console.WriteLine(result.GetResultInfo());
                Assert.IsNotEmpty((result.GetResultInfo()));

                Assert.True(result.httpCode == 200);
                Assert.NotNull(result.recognitionResult);
                Assert.NotNull(result.recognitionResult.PoliticsInfo);
                Assert.Zero(result.recognitionResult.PoliticsInfo.Code);
                Assert.NotNull(result.recognitionResult.PoliticsInfo.Score);
                Assert.NotNull(result.recognitionResult.PoliticsInfo.Count);
                Assert.NotNull(result.recognitionResult.PoliticsInfo.Msg);
                Assert.NotNull(result.recognitionResult.PoliticsInfo.Label);
                Assert.NotNull(result.recognitionResult.PoliticsInfo.HitFlag);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.Fail();
            }
        }
Ejemplo n.º 8
0
 public void TestDescribeMediaBuckets()
 {
     try
     {
         DescribeMediaBucketsRequest request = new DescribeMediaBucketsRequest();
         DescribeMediaBucketsResult  result  = QCloudServer.Instance().cosXml.DescribeMediaBuckets(request);
         Assert.AreEqual(result.httpCode, 200);
         Assert.NotNull(result.mediaBuckets.MediaBucketList);
         Assert.NotZero(result.mediaBuckets.MediaBucketList.Count);
         for (int i = 0; i < result.mediaBuckets.MediaBucketList.Count; i++)
         {
             Assert.NotNull(result.mediaBuckets.MediaBucketList[i].BucketId);
             Assert.NotNull(result.mediaBuckets.MediaBucketList[i].Region);
             Assert.NotNull(result.mediaBuckets.MediaBucketList[i].CreateTime);
         }
     }
     catch (COSXML.CosException.CosClientException clientEx)
     {
         Console.WriteLine("CosClientException: " + clientEx.Message);
         Assert.Fail();
     }
     catch (COSXML.CosException.CosServerException serverEx)
     {
         Console.WriteLine("CosServerException: " + serverEx.GetInfo());
         Assert.Fail();
     }
 }
Ejemplo n.º 9
0
 public void TestBucketCORS()
 {
     DeleteBucketCORS();
     PutBucketCORS();
     Thread.Sleep(100);
     QCloudServer.TestWithServerFailTolerance(() => GetBucketCORS());
 }
Ejemplo n.º 10
0
        public void Setup()
        {
            bucket = QCloudServer.Instance().bucketForObjectTest;

            // 本地文件名,用于暂存下载的文件,以测试上传时处理接口
            localTempPhotoFilePath       = TimeUtils.GetCurrentTime(TimeUnit.Seconds) + ".jpg";
            localQRCodeTempPhotoFilePath = "qr_" + TimeUtils.GetCurrentTime(TimeUnit.Seconds) + ".jpg";
            localSnapshotFilePath        = "/tmp/snapshot.jpg";

            /*
             * localTempPhotoFilePath = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.Seconds) + ".jpg", 1);
             * FileInfo fileInfo = new FileInfo(localTempPhotoFilePath);
             * DirectoryInfo directoryInfo = fileInfo.Directory;
             * PutObjectRequest request = new PutObjectRequest(bucket, photoKey, fileInfo.Name);
             * QCloudServer.Instance().cosXml.PutObject(request);
             */
            /*
             * qrPhotoKey = "qr_code_photo.jpg";
             * localQRCodeTempPhotoFilePath = QCloudServer.CreateFile("qr_" + TimeUtils.GetCurrentTime(TimeUnit.Seconds) + ".jpg", 1);
             * fileInfo = new FileInfo(localQRCodeTempPhotoFilePath);
             * PutObjectRequest request = new PutObjectRequest(bucket, qrPhotoKey, fileInfo.Name);
             * QCloudServer.Instance().cosXml.PutObject(request);
             */
            // 预先上传好的媒体文件,用于万象媒体接口的测试
            photoKey   = "CITestImage.png";
            qrPhotoKey = "CITestQrImage.jpg";
            videoKey   = "CITestVideo.mp4";
            audioKey   = "CITestAudio.mp3";
            textKey    = "CITestText.txt";
        }
Ejemplo n.º 11
0
        public void init()
        {
            string region = "ap-guangzhou";

            CosXmlConfig config = new CosXmlConfig.Builder()
                                  .SetRegion(region)
                                  .SetDebugLog(true)
                                  .SetConnectionLimit(512)
                                  .Build();

            QCloudCredentialProvider qCloudCredentialProvider = new DefaultSessionQCloudCredentialProvider(
                "AKIDLT2qvPSOSRq5eM2TR11daHYBfT1rl8fuWgAJhtbo3eFwcbpFnZHAYkgpaFrzvtq4",
                "i19oUWRIvvpqGpiUgwqa3wufzSbDPyaxv0JYArSQFMc=",
                1597907089,
                "YiPWtzGhVPG5HQlOLQdxZrxHOitu1JXL903fda3a64f28616997f861116b2d7d1EyG_RmvCKqArCLtOXxKv9MGtugt4lPcUbESOTHdhmhEyMYgnPpJSLpbQoKPYzg7WwwvjjXqOKQvs_I9iCHyaBXJu_LToqeuQfO4NFpos8I_NWBKxg23xFpvuXHXJ7kDuyudwu7qInonvJpoXAnb_J-7rMY94aVWSg6kolryvO-x5_C3cBa1fIiKTrwkRP4keh0g3_asIwP99DA-WASJ147C_NsZl9fdTlWEBnIeQqB7uRHAZkF-_f03-fBYJofeYGe7FArrfai4_AO57QbTwacfzHk2s-43WuCIhoLud_-k"
                );

            cosXml = new CosXmlServer(config, qCloudCredentialProvider);

            transferManager = new TransferManager(cosXml, new TransferConfig());

            smallFileSrcPath = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.SECONDS) + ".txt", 1024 * 1024 * 1);
            bigFileSrcPath   = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.SECONDS) + ".txt", 1024 * 1024 * 10);
            FileInfo      fileInfo      = new FileInfo(smallFileSrcPath);
            DirectoryInfo directoryInfo = fileInfo.Directory;

            localDir      = directoryInfo.FullName;
            localFileName = "local.txt";
        }
Ejemplo n.º 12
0
        public void Setup()
        {
            cosXml = QCloudServer.Instance().cosXml;
            bucket = QCloudServer.Instance().bucketForBucketTest;
            region = QCloudServer.Instance().region;

            PutBucket();
            Thread.Sleep(100);
        }
Ejemplo n.º 13
0
        public void PutObjectWithDeSample()
        {
            string key     = "original_photo.jpg";
            string srcPath = localTempPhotoFilePath;

            PutObjectRequest request = new PutObjectRequest(bucket, key, srcPath);

            JObject o = new JObject();

            // 返回原图
            o["is_pic_info"] = 1;
            JArray  rules = new JArray();
            JObject rule  = new JObject();

            rule["bucket"] = bucket;
            rule["fileid"] = "desample_photo.jpg";
            //处理参数,规则参见:https://cloud.tencent.com/document/product/460/19017
            rule["rule"] = "imageMogr2/thumbnail/400x";
            rules.Add(rule);
            o["rules"] = rules;
            string ruleString = o.ToString(Formatting.None);

            request.SetRequestHeader("Pic-Operations", ruleString);
            //执行请求
            PutObjectResult result       = QCloudServer.Instance().cosXml.PutObject(request);
            var             uploadResult = result.uploadResult;

            // Console.WriteLine(result.GetResultInfo());
            Assert.IsNotEmpty((result.GetResultInfo()));

            Assert.True(result.IsSuccessful());
            Assert.NotNull(uploadResult);

            Assert.NotNull(uploadResult.originalInfo);
            Assert.NotNull(uploadResult.originalInfo.ETag);
            Assert.NotNull(uploadResult.originalInfo.Key);
            Assert.NotNull(uploadResult.originalInfo.Location);
            Assert.NotNull(uploadResult.originalInfo.imageInfo.Ave);
            Assert.NotNull(uploadResult.originalInfo.imageInfo.Format);
            Assert.NotNull(uploadResult.originalInfo.imageInfo.Orientation);
            Assert.NotZero(uploadResult.originalInfo.imageInfo.Width);
            Assert.NotZero(uploadResult.originalInfo.imageInfo.Height);
            Assert.NotZero(uploadResult.originalInfo.imageInfo.Quality);

            Assert.NotNull(uploadResult.processResults);
            Assert.NotZero(uploadResult.processResults.results.Count);
            Assert.True(uploadResult.processResults.results[0].Width <= 400);
            Assert.True(uploadResult.processResults.results[0].Height <= 400);
            Assert.NotNull(uploadResult.processResults.results[0].ETag);
            Assert.NotNull(uploadResult.processResults.results[0].Format);
            Assert.NotNull(uploadResult.processResults.results[0].Key);
            Assert.NotNull(uploadResult.processResults.results[0].Location);
            Assert.NotZero(uploadResult.processResults.results[0].Quality);
            Assert.NotZero(uploadResult.processResults.results[0].Size);
            Assert.Zero(uploadResult.processResults.results[0].WatermarkStatus);
        }
Ejemplo n.º 14
0
 public void TestBucketLifecycle()
 {
     PutBucketLifeCycle();
     Thread.Sleep(100);
     QCloudServer.TestWithServerFailTolerance(() =>
     {
         GetBucketLifeCycle();
     });
     DeleteBucketLifeCycle();
 }
Ejemplo n.º 15
0
        public void PartCopyObject()
        {
            string           key        = commonKey;
            CopySourceStruct copySource = new CopySourceStruct(QCloudServer.Instance().appid,
                                                               bucket, QCloudServer.Instance().region, copykey);

            try
            {
                InitMultipartUploadRequest initMultipartUploadRequest = new InitMultipartUploadRequest(bucket, key);

                //执行请求
                InitMultipartUploadResult initMultipartUploadResult = cosXml.InitMultipartUpload(initMultipartUploadRequest);

                Console.WriteLine(initMultipartUploadResult.GetResultInfo());

                string uploadId = initMultipartUploadResult.initMultipartUpload.uploadId;

                int partNumber = 1;

                UploadPartCopyRequest uploadPartCopyRequest = new UploadPartCopyRequest(bucket, key, partNumber, uploadId);

                //设置拷贝源
                uploadPartCopyRequest.SetCopySource(copySource);

                //设置拷贝范围
                uploadPartCopyRequest.SetCopyRange(0, 10);

                //执行请求
                UploadPartCopyResult uploadPartCopyResult = cosXml.PartCopy(uploadPartCopyRequest);

                Console.WriteLine(uploadPartCopyResult.GetResultInfo());

                string eTag = uploadPartCopyResult.copyObject.eTag;

                CompleteMultipartUploadRequest completeMultiUploadRequest = new CompleteMultipartUploadRequest(bucket, key, uploadId);

                //设置已上传的parts
                completeMultiUploadRequest.SetPartNumberAndETag(partNumber, eTag);

                //执行请求
                CompleteMultipartUploadResult completeMultiUploadResult = cosXml.CompleteMultiUpload(completeMultiUploadRequest);

                Console.WriteLine(completeMultiUploadResult.GetResultInfo());
            }
            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);
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
 public static QCloudServer Instance()
 {
     lock (typeof(QCloudServer))
     {
         if (instance == null)
         {
             instance = new QCloudServer();
         }
     }
     return(instance);
 }
        public void TestSetSign()
        {
            GetBucketRequest request = new GetBucketRequest(QCloudServer.Instance().bucketForObjectTest);

            request.SetSign(TimeUtils.GetCurrentTime(TimeUnit.Seconds), 600);

            ///执行请求
            GetBucketResult result = QCloudServer.Instance().cosXml.GetBucket(request);

            Assert.AreEqual(result.httpCode, 200);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public void Setup()
        {
            notExistBucket = "not-exist-bucket-suwjsdjwujehdfkd-" + QCloudServer.Instance().appid;
            cosXml         = QCloudServer.Instance().cosXml;
            var config = new TransferConfig();

            config.DivisionForUpload  = 1 * 1024 * 1024;
            config.DdivisionForCopy   = 1 * 1024 * 1024;
            config.SliceSizeForCopy   = 1 * 1024 * 1024;
            config.SliceSizeForUpload = 1 * 1024 * 1024;
            transferManager           = new TransferManager(cosXml, config);
            localFilePath             = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.Seconds) + ".txt", 1024 * 1024 * 1);
        }
Ejemplo n.º 21
0
        public void TestCopySourceNotExisted()
        {
            COSXMLCopyTask copyTask = new COSXMLCopyTask(notExistBucket, "remote_key", null);

            Assert.ThrowsAsync <CosClientException>(async() => await transferManager.CopyAsync(copyTask));

            CopySourceStruct notExistSource = new CopySourceStruct(QCloudServer.Instance().appid,
                                                                   notExistBucket, QCloudServer.Instance().region, "example_key");

            COSXMLCopyTask copyTask2 = new COSXMLCopyTask(notExistBucket, "remote_key", notExistSource);

            Assert.ThrowsAsync <CosServerException>(async() => await transferManager.CopyAsync(copyTask2));
        }
Ejemplo n.º 22
0
        public void Setup()
        {
            bucket   = QCloudServer.Instance().bucketForObjectTest;
            photoKey = "example_photo.jpg";

            localTempPhotoFilePath = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.Seconds) + ".jpg", 1);
            FileInfo fileInfo = new FileInfo(localTempPhotoFilePath);

            DirectoryInfo directoryInfo = fileInfo.Directory;


            GetObjectRequest request = new GetObjectRequest(bucket, photoKey, directoryInfo.FullName, fileInfo.Name);

            QCloudServer.Instance().cosXml.GetObject(request);
        }
Ejemplo n.º 23
0
        public void generateSignUrl()
        {
            QCloudServer       instance        = QCloudServer.Instance();
            string             key             = commonKey;
            PreSignatureStruct signatureStruct = new PreSignatureStruct();

            signatureStruct.bucket     = instance.bucketForObjectTest;
            signatureStruct.appid      = instance.appid;
            signatureStruct.region     = instance.region;
            signatureStruct.key        = key;
            signatureStruct.httpMethod = "GET";
            signatureStruct.headers    = new Dictionary <string, string>();
            string url = instance.cosXml.GenerateSignURL(signatureStruct);

            Console.WriteLine(url);
            Assert.NotNull(url);
        }
Ejemplo n.º 24
0
        public void TestBucketLogging()
        {
            try
            {
                PutBucketLoggingRequest request = new PutBucketLoggingRequest(bucket);

                request.SetTarget(QCloudServer.Instance().bucketForLoggingTarget, "/");
                PutBucketLoggingResult putResult = cosXml.PutBucketLogging(request);

                Assert.IsTrue(putResult.httpCode == 200);

                GetBucketLoggingResult getResult = cosXml.GetBucketLogging(new GetBucketLoggingRequest(bucket));
                Assert.AreEqual(getResult.httpCode, 200);

                // Console.WriteLine(getResult.GetResultInfo());
                Assert.IsNotEmpty((getResult.GetResultInfo()));
                Assert.IsNotEmpty(getResult.RawContentBodyString);

                BucketLoggingStatus status = getResult.bucketLoggingStatus;

                Assert.NotNull(status);
                Assert.NotNull(status.loggingEnabled);
                Assert.NotNull(status.GetInfo());

                string targetBucket = status.loggingEnabled.targetBucket;
                string targetPrefix = status.loggingEnabled.targetPrefix;
                Assert.NotNull(targetBucket);
                Assert.NotNull(targetPrefix);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());

                if (serverEx.statusCode != 409 && serverEx.statusCode != 451)
                {
                    Assert.Fail();
                }
            }
        }
Ejemplo n.º 25
0
        public void init()
        {
            cosXml           = QCloudServer.Instance().cosXml;
            bucket           = QCloudServer.Instance().bucketForObjectTest;
            transferManager  = new TransferManager(cosXml, new TransferConfig());
            smallFileSrcPath = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.SECONDS) + ".txt", 1024 * 1024 * 1);
            bigFileSrcPath   = QCloudServer.CreateFile(TimeUtils.GetCurrentTime(TimeUnit.SECONDS) + ".txt", 1024 * 1024 * 10);
            FileInfo      fileInfo      = new FileInfo(smallFileSrcPath);
            DirectoryInfo directoryInfo = fileInfo.Directory;

            localDir      = directoryInfo.FullName;
            localFileName = "local.txt";

            commonKey = "simpleObject" + TimeUtils.GetCurrentTime(TimeUnit.SECONDS);
            multiKey  = "bigObject" + TimeUtils.GetCurrentTime(TimeUnit.SECONDS);
            copykey   = commonKey;
            imageKey  = commonKey;

            PutObject();
        }
Ejemplo n.º 26
0
        public void TestBucketReplication()
        {
            PutBucketVersioning(true);
            Thread.Sleep(200);
            QCloudServer.TestWithServerFailTolerance(() =>
            {
                GetBucketVersioning();
            }
                                                     );

            PutBucketReplication();
            Thread.Sleep(100);
            QCloudServer.TestWithServerFailTolerance(() =>
            {
                GetBucketReplication();
            }
                                                     );
            DeleteBucketReplication();

            PutBucketVersioning(false);
        }
Ejemplo n.º 27
0
 public void TestGetSnapshot()
 {
     try
     {
         string             key     = videoKey;
         GetSnapshotRequest request = new GetSnapshotRequest(bucket, key, 1.5F, localSnapshotFilePath);
         GetSnapshotResult  result  = QCloudServer.Instance().cosXml.GetSnapshot(request);
         Assert.True(File.Exists(localSnapshotFilePath));
         Assert.AreEqual(result.httpCode, 200);
     }
     catch (COSXML.CosException.CosClientException clientEx)
     {
         Console.WriteLine("CosClientException: " + clientEx.Message);
         Assert.Fail();
     }
     catch (COSXML.CosException.CosServerException serverEx)
     {
         Console.WriteLine("CosServerException: " + serverEx.GetInfo());
         Assert.Fail();
     }
 }
Ejemplo n.º 28
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);
     }
 }
Ejemplo n.º 29
0
        private void PutBucketReplication()
        {
            try
            {
                PutBucketReplicationRequest request = new PutBucketReplicationRequest(bucket);


                //设置replication
                PutBucketReplicationRequest.RuleStruct ruleStruct = new PutBucketReplicationRequest.RuleStruct();

                ruleStruct.appid        = QCloudServer.Instance().appid;
                ruleStruct.bucket       = QCloudServer.Instance().bucketVersioning;
                ruleStruct.region       = QCloudServer.Instance().regionForBucketVersioning;
                ruleStruct.isEnable     = true;
                ruleStruct.storageClass = "STANDARD";
                ruleStruct.id           = "replication1";
                ruleStruct.prefix       = "dir/";

                request.SetReplicationConfiguration("2832742109", "2832742109", new List <PutBucketReplicationRequest.RuleStruct>()
                {
                    ruleStruct
                });

                //执行请求
                PutBucketReplicationResult result = cosXml.PutBucketReplication(request);

                Assert.AreEqual(result.httpCode, 200);
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.Fail();
            }
        }
Ejemplo n.º 30
0
        public void testCopyTask()
        {
            CopySourceStruct copySource = new CopySourceStruct(QCloudServer.Instance().appid,
                                                               bucket, QCloudServer.Instance().region, copykey);

            COSXMLCopyTask copyTask = new COSXMLCopyTask(bucket, multiKey, copySource);

            var autoEvent = new AutoResetEvent(false);

            copyTask.progressCallback = delegate(long completed, long total)
            {
                Console.WriteLine(String.Format("progress = {0:##.##}%", completed * 100.0 / total));
            };

            copyTask.successCallback = delegate(CosResult cosResult)
            {
                COSXML.Transfer.COSXMLCopyTask.CopyTaskResult result = cosResult as COSXML.Transfer.COSXMLCopyTask.CopyTaskResult;
                Console.WriteLine(result.GetResultInfo());
                autoEvent.Set();
                Assert.True(cosResult.httpCode == 200);
            };

            copyTask.failCallback = delegate(CosClientException clientEx, CosServerException serverEx)
            {
                if (clientEx != null)
                {
                    Console.WriteLine("CosClientException: " + clientEx);
                }
                if (serverEx != null)
                {
                    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                }
                autoEvent.Set();
                Assert.True(false);
            };

            transferManager.Copy(copyTask);
            autoEvent.WaitOne();
        }