コード例 #1
0
        static void WriteBucketTags()
        {
            string bucket = Common.InputString("Bucket:", null, false);
            string key    = Common.InputString("Tag Key:", null, false);
            string val    = Common.InputString("Tag Value:", null, false);

            PutBucketTaggingRequest request = new PutBucketTaggingRequest();

            request.BucketName = bucket;
            request.TagSet     = new List <Tag>();
            Tag tag = new Tag();

            tag.Key   = key;
            tag.Value = val;
            request.TagSet.Add(tag);

            PutBucketTaggingResponse response = _S3Client.PutBucketTaggingAsync(request).Result;

            if (response != null)
            {
                Console.WriteLine("Success");
            }
            else
            {
                Console.WriteLine("Failed");
            }
        }
コード例 #2
0
        /// 设置存储桶标签
        public void PutBucketTagging()
        {
            //.cssg-snippet-body-start:[put-bucket-tagging]
            try
            {
                string bucket = "examplebucket-1250000000"; //格式:BucketName-APPID
                PutBucketTaggingRequest request = new PutBucketTaggingRequest(bucket);
                string akey   = "aTagKey";
                string avalue = "aTagValue";
                string bkey   = "bTagKey";
                string bvalue = "bTagValue";

                request.AddTag(akey, avalue);
                request.AddTag(bkey, bvalue);

                //执行请求
                PutBucketTaggingResult result = cosXml.PutBucketTagging(request);

                //请求成功
                Console.WriteLine(result.GetResultInfo());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                //请求失败
                Console.WriteLine("CosClientException: " + clientEx);
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                //请求失败
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
            }
            //.cssg-snippet-body-end
        }
コード例 #3
0
        public void MarshallXMLWithExtraEncodingTest(string toEncode, string expectedEncoding)
        {
            var request = new PutBucketTaggingRequest()
            {
                AccountId = "0123456789",
                Bucket    = "foo",
                Tagging   = new Tagging()
                {
                    TagSet = new List <S3Tag>()
                    {
                        new S3Tag {
                            Key = "foo", Value = toEncode
                        }
                    }
                }
            };

            var internalRequest = S3ControlArnTestUtils.RunMockRequest(request, PutBucketTaggingRequestMarshaller.Instance, new AmazonS3ControlConfig {
                RegionEndpoint = RegionEndpoint.USEast1
            });
            var requestContent = System.Text.Encoding.UTF8.GetString(internalRequest.Content);

            Assert.IsFalse(requestContent.Contains(toEncode));
            Assert.IsTrue(requestContent.Contains(expectedEncoding));
        }
コード例 #4
0
        public void TagBucket()
        {
            var request = new PutBucketTaggingRequest
            {
                BucketName = bucketName,
                TagSet     = new List <Tag>
                {
                    new Tag
                    {
                        Key   = "TagBucketKey",
                        Value = "TagBucketValue"
                    }
                }
            };

            Client.PutBucketTagging(request);

            var tags = Client.GetBucketTagging(new GetBucketTaggingRequest {
                BucketName = bucketName
            }).TagSet;

            var tag = tags.FirstOrDefault(x => string.Equals(x.Key, "TagBucketKey"));

            Assert.IsNotNull(tag);
            Assert.AreEqual("TagBucketValue", tag.Value);
        }
コード例 #5
0
        public void TagBucket()
        {
            var request = new PutBucketTaggingRequest
            {
                BucketName = bucketName,
                TagSet     = new List <Tag>
                {
                    new Tag
                    {
                        Key   = "TagBucketKey",
                        Value = "TagBucketValue"
                    }
                }
            };

            Client.PutBucketTagging(request);

            var tags = S3TestUtils.WaitForConsistency(() =>
            {
                var res = Client.GetBucketTagging(new GetBucketTaggingRequest {
                    BucketName = bucketName
                });
                return(res.TagSet?.FirstOrDefault(x => string.Equals(x.Key, "TagBucketKey")) != null ? res.TagSet : null);
            });

            var tag = tags.FirstOrDefault(x => string.Equals(x.Key, "TagBucketKey"));

            Assert.IsNotNull(tag);
            Assert.AreEqual("TagBucketValue", tag.Value);
        }
コード例 #6
0
        public Task <PutBucketTaggingResponse> PutBucketTaggingAsync(string bucketName, IDictionary <string, string> tags, Action <PutBucketTaggingRequest>?config = null, CancellationToken token = default)
        {
            PutBucketTaggingRequest request = new PutBucketTaggingRequest(bucketName, tags);

            config?.Invoke(request);

            return(BucketOperations.PutBucketTaggingAsync(request, token));
        }
コード例 #7
0
        static void Main(string[] args)
        {
            string AccessKey         = "";
            string SecretKey         = "";
            string NameOftheBucket   = "";
            string NameOfTheObject   = "";
            string RegionOfTheBucket = "";
            string TagKey            = "";
            string TagValue          = "";
            string UseTagIn          = " **** Object OR Bucket **** Eg: Bucket";

            try
            {
                AmazonS3Client client = new AmazonS3Client(AccessKey, SecretKey, Amazon.RegionEndpoint.GetBySystemName(ClientRegion(RegionOfTheBucket)));
                if (UseTagIn == "Bucket")
                {
                    PutBucketTaggingRequest Request = new PutBucketTaggingRequest
                    {
                        BucketName = NameOftheBucket,
                        TagSet     = new List <Tag>
                        {
                            new Tag {
                                Key = TagKey, Value = TagValue
                            }
                        }
                    };
                    client.PutBucketTagging(Request);
                    Console.WriteLine("Tag added to the bucket");
                }
                else if (UseTagIn == "Object")
                {
                    Tagging NewTagSet = new Tagging();
                    NewTagSet.TagSet = new List <Tag>
                    {
                        new Tag {
                            Key = TagKey, Value = TagValue
                        }
                    };
                    PutObjectTaggingRequest Request = new PutObjectTaggingRequest
                    {
                        BucketName = NameOftheBucket,
                        Key        = NameOfTheObject,
                        Tagging    = NewTagSet
                    };
                    client.PutObjectTagging(Request);
                    Console.WriteLine("Tag added to the object");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR MESSAGE : " + e.Message);
            }
            Console.ReadLine();
        }
コード例 #8
0
        public void TestBucketTagging()
        {
            try
            {
                // 设置 tag
                PutBucketTaggingRequest request = new PutBucketTaggingRequest(bucket);


                string akey   = "aTagKey";
                string avalue = "aTagValue";
                string bkey   = "bTagKey";
                string bvalue = "bTagValue";

                request.AddTag(akey, avalue);
                request.AddTag(bkey, bvalue);

                PutBucketTaggingResult result = cosXml.PutBucketTagging(request);

                Assert.True(result.IsSuccessful());

                // 获取 tag
                GetBucketTaggingRequest getRequest = new GetBucketTaggingRequest(bucket);

                GetBucketTaggingResult getResult = cosXml.GetBucketTagging(getRequest);

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

                Tagging tagging = getResult.tagging;

                Assert.AreEqual(getResult.httpCode, 200);
                Assert.AreEqual(tagging.tagSet.tags.Count, 2);

                foreach (Tagging.Tag tag in tagging.tagSet.tags)
                {
                    if (tag.key.Equals(akey))
                    {
                        Assert.AreEqual(avalue, tag.value);
                    }
                    else if (tag.key.Equals(bkey))
                    {
                        Assert.AreEqual(bvalue, tag.value);
                    }
                    else
                    {
                        Assert.Fail();
                    }
                }

                // 删除 tag
                DeleteBucketTaggingRequest deleteRequest = new DeleteBucketTaggingRequest(bucket);

                DeleteBucketTaggingResult deleteResult = cosXml.DeleteBucketTagging(deleteRequest);
                Assert.True(deleteResult.IsSuccessful());
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Console.WriteLine("CosServerException: " + serverEx.GetInfo());
                Assert.Fail();
            }

            try
            {
                // 验证删除成功
                GetBucketTaggingRequest getRequest = new GetBucketTaggingRequest(bucket);

                GetBucketTaggingResult getResult = cosXml.GetBucketTagging(getRequest);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosClientException clientEx)
            {
                Console.WriteLine("CosClientException: " + clientEx.Message);
                Assert.Fail();
            }
            catch (COSXML.CosException.CosServerException serverEx)
            {
                Assert.AreEqual(serverEx.statusCode, 404);
            }
        }
コード例 #9
0
 public void PutBucketTaggingAsync(PutBucketTaggingRequest request, COSXML.Callback.OnSuccessCallback <CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback)
 {
     Schedue(request, new Model.Bucket.PutBucketTaggingResult(), successCallback, failCallback);
 }
コード例 #10
0
 public PutBucketTaggingResult PutBucketTagging(PutBucketTaggingRequest request)
 {
     return((Model.Bucket.PutBucketTaggingResult)Excute(request, new Model.Bucket.PutBucketTaggingResult()));
 }
コード例 #11
0
 public Task <PutBucketTaggingResponse> PutBucketTaggingAsync(PutBucketTaggingRequest request, CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
 public PutBucketTaggingResponse PutBucketTagging(PutBucketTaggingRequest request)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
ファイル: BucketOperations.cs プロジェクト: Genbox/SimpleS3
 public Task <PutBucketTaggingResponse> PutBucketTaggingAsync(PutBucketTaggingRequest request, CancellationToken token = default)
 {
     return(_requestHandler.SendRequestAsync <PutBucketTaggingRequest, PutBucketTaggingResponse>(request, token));
 }
コード例 #14
0
 public void PutBucketTaggingAsync(PutBucketTaggingRequest request, AmazonServiceCallback <PutBucketTaggingRequest, PutBucketTaggingResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }