当前位置: 首页>>代码示例>>C#>>正文


C# AmazonS3Client.GetBucketLocation方法代码示例

本文整理汇总了C#中Amazon.S3.AmazonS3Client.GetBucketLocation方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.GetBucketLocation方法的具体用法?C# AmazonS3Client.GetBucketLocation怎么用?C# AmazonS3Client.GetBucketLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.S3.AmazonS3Client的用法示例。


在下文中一共展示了AmazonS3Client.GetBucketLocation方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestLocation

        public void TestLocation()
        {
            foreach (var location in new S3Region[] { S3Region.USW1, S3Region.EUC1 })
            {
                string bucketName = null;
                var region = RegionEndpoint.GetBySystemName(location.Value);

                using (var client = new AmazonS3Client(region))
                {
                    try
                    {
                        bucketName = UtilityMethods.SDK_TEST_PREFIX + DateTime.Now.Ticks;

                        client.PutBucket(new PutBucketRequest
                        {
                            BucketName = bucketName,
                            BucketRegion = location
                        });

                        var returnedLocation = client.GetBucketLocation(new GetBucketLocationRequest
                        {
                            BucketName = bucketName
                        }).Location;

                        Assert.AreEqual(location, returnedLocation);
                    }
                    finally
                    {
                        if (bucketName != null)
                            AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
                    }
                }
            }
        }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:34,代码来源:RegionsTest.cs

示例2: TestLocation

        public void TestLocation()
        {
            // Disable EUW2 for now until we figure out why we are hitting the bucket number limit.
            foreach (var location in new S3Region[] { S3Region.USW1, S3Region.EUC1, S3Region.EUW1/*, S3Region.EUW2*/})
            {
                string bucketName = null;
                var region = RegionEndpoint.GetBySystemName(location.Value);

                using (var client = new AmazonS3Client(region))
                {
                    try
                    {
                        bucketName = S3TestUtils.CreateBucketWithWait(client);
                        var returnedLocation = client.GetBucketLocation(new GetBucketLocationRequest
                        {
                            BucketName = bucketName
                        }).Location;

                        //Map S3Region.EUW1 to S3Region.EU
                        //S3 considers this as the same region.
                        if (location == S3Region.EUW1)
                        {
                            Assert.AreEqual(S3Region.EU, returnedLocation);
                        }
                        else
                        {
                            Assert.AreEqual(location, returnedLocation);
                        }
                        
                    }
                    finally
                    {
                        if (bucketName != null)
                            AmazonS3Util.DeleteS3BucketWithObjects(client, bucketName);
                    }
                }
            }
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:38,代码来源:RegionsTest.cs

示例3: GenerateS3Client

        // Create one client to get region.. then create real one?
        // Seems dumb, but will see how it goes.
        public static IAmazonS3 GenerateS3Client( string accessKey, string secretKey, string bucketName = null)
        {
            IAmazonS3 client = new AmazonS3Client( accessKey, secretKey);
            if (!string.IsNullOrEmpty(bucketName))
            {
                var regionForBucket = client.GetBucketLocation(bucketName);

                // if default US region then location will be null. Replace it with string.Empty for region lookup.
                client = new AmazonS3Client(accessKey, secretKey, RegionDict[regionForBucket.Location ?? string.Empty]);
            }

            return client;
        }
开发者ID:kpfaulkner,项目名称:azurecopy,代码行数:15,代码来源:S3Helper.cs

示例4: executeSomeBucketOperations

        private void executeSomeBucketOperations(AmazonS3Config s3Config)
        {
            using (var s3Client = new AmazonS3Client(s3Config))
            {
                // Call ListBuckets first to verify that AmazonS3PostMarshallHandler.ProcessRequestHandlers
                // correctly computes the endpoint when no bucket name is present.
                var listBucketsResponse = s3Client.ListBuckets();
                Assert.IsNotNull(listBucketsResponse);
                Assert.IsFalse(string.IsNullOrEmpty(listBucketsResponse.ResponseMetadata.RequestId));

                // Bonus call on ListObjects if we can find a bucket compatible with the test region (to avoid 301
                // errors due to addressing bucket on wrong endpoint). This verifies that  
                // AmazonS3PostMarshallHandler.ProcessRequestHandlers correctly computes the endpoint when 
                // a bucket name is present.
                string bucketName = null;
                foreach (var bucket in listBucketsResponse.Buckets)
                {
                    try
                    {
                        var bucketLocationResponse = s3Client.GetBucketLocation(bucket.BucketName);
                        if (string.IsNullOrEmpty(bucketLocationResponse.Location) && s3Config.RegionEndpoint == RegionEndpoint.USEast1)
                            bucketName = bucket.BucketName;
                        else if (string.Equals(s3Config.RegionEndpoint.SystemName, bucketLocationResponse.Location, StringComparison.OrdinalIgnoreCase))
                            bucketName = bucket.BucketName;

                        if (!string.IsNullOrEmpty(bucketName))
                            break;
                    }
                    catch(AmazonS3Exception e)
                    {
                        if (e.StatusCode != System.Net.HttpStatusCode.NotFound)
                            throw;
                    }
                }

                if (!string.IsNullOrEmpty(bucketName))
                {
                    var listObjectsResponse = s3Client.ListObjects(new ListObjectsRequest { BucketName = bucketName });
                    Assert.IsNotNull(listObjectsResponse);
                    Assert.IsNotNull(listObjectsResponse.ResponseMetadata);
                }
            }
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:43,代码来源:DualstackTests.cs

示例5: GetS3Buckets

        public DataTable GetS3Buckets(string aprofile,string Region2Scan)
        {
            string accountid = GetAccountID(aprofile);
            Amazon.Runtime.AWSCredentials credential;
            DataTable ToReturn = AWSTables.GetComponentTable("S3");
            RegionEndpoint Endpoint2scan = RegionEndpoint.USEast1;
            //Convert the Region2Scan to an AWS Endpoint.
            foreach (var aregion in RegionEndpoint.EnumerableAllRegions)
            {
                if (aregion.DisplayName.Equals(Region2Scan))
                {
                    Endpoint2scan = aregion;
                    continue;
                }
            }


            //Query Cloudwatch to get list of buckets and sizes in this here region
            var Sizetable = S3SizeCloudWatch(aprofile, Region2Scan);
            int sizerows = Sizetable.Rows.Count;



            try
            {
                credential = new Amazon.Runtime.StoredProfileAWSCredentials(aprofile);


                
                
                AmazonS3Client S3Client = new AmazonS3Client(credential, Endpoint2scan);
                ListBucketsResponse response = S3Client.ListBuckets();

                //Why are we getting USEast buckets?  Because the Cloudwatch returns buckets by region, but list buckets does care about regions!


                foreach (S3Bucket abucket in response.Buckets)
                {
                    DataRow abucketrow = ToReturn.NewRow();
                    var name = abucket.BucketName;
                    DataRow bucketsizedata = AWSTables.GetS3SizesTable().NewRow();
                    Boolean havesize = true;

                    try//Lookup the record in the Sizetable for this bucket.
                    {
                        //This is equivalent to the LINQ query.
                        Boolean foundinsizetable = false;
                        List<string> bn = new List<string>();
                        foreach(var rabbit in Sizetable.AsEnumerable())
                        {
                            String thisun = rabbit["Bucket"].ToString();
                            bn.Add(thisun);
                            if (thisun.Equals(name))
                            {
                                bucketsizedata = rabbit;
                                foundinsizetable = true;
                            }
                        }
                        if(!foundinsizetable)
                        {
                            bn.Sort();
                            if (bn.Contains(name))
                            {
                                string rabbit = "Yes it does!";
                            }
                            //why not?
                        }



                        if (bucketsizedata == null)
                        {
                            abucketrow["EndDate"] = AWSTables.Shrug;
                            havesize = false;
                        }

                    }
                    catch
                    {

                    }


                    try
                    {
                        GetBucketLocationRequest gbr = new GetBucketLocationRequest();
                        gbr.BucketName = name;
                        GetBucketLocationResponse location = S3Client.GetBucketLocation(gbr);

                        var region = location.Location.Value;

                        if (region.Equals(""))
                        {
                            
                            region = "us-east-1";
                        }

                        if (!region.Contains(Endpoint2scan.SystemName))
                        {
                            name = name;//Bucketname
//.........这里部分代码省略.........
开发者ID:StivOstenberg,项目名称:AWSTrycorder,代码行数:101,代码来源:AWSFunctions.cs

示例6: BucketSamples

        public void BucketSamples()
        {
            {
                #region ListBuckets Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Issue call
                ListBucketsResponse response = client.ListBuckets();

                // View response data
                Console.WriteLine("Buckets owner - {0}", response.Owner.DisplayName);
                foreach (S3Bucket bucket in response.Buckets)
                {
                    Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate);
                }

                #endregion
            }

            {
                #region BucketPolicy Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Put sample bucket policy (overwrite an existing policy)
                string newPolicy = @"{ 
    ""Statement"":[{ 
    ""Sid"":""BasicPerms"", 
    ""Effect"":""Allow"", 
    ""Principal"": ""*"", 
    ""Action"":[""s3:PutObject"",""s3:GetObject""], 
    ""Resource"":[""arn:aws:s3:::samplebucketname/*""] 
}]}";
                PutBucketPolicyRequest putRequest = new PutBucketPolicyRequest
                {
                    BucketName = "SampleBucket",
                    Policy = newPolicy
                };
                client.PutBucketPolicy(putRequest);


                // Retrieve current policy
                GetBucketPolicyRequest getRequest = new GetBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                string policy = client.GetBucketPolicy(getRequest).Policy;

                Console.WriteLine(policy);
                Debug.Assert(policy.Contains("BasicPerms"));


                // Delete current policy
                DeleteBucketPolicyRequest deleteRequest = new DeleteBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                client.DeleteBucketPolicy(deleteRequest);


                // Retrieve current policy and verify that it is null
                policy = client.GetBucketPolicy(getRequest).Policy;
                Debug.Assert(policy == null);

                #endregion
            }

            {
                #region GetBucketLocation Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                GetBucketLocationRequest request = new GetBucketLocationRequest
                {
                    BucketName = "SampleBucket"
                };

                // Issue call
                GetBucketLocationResponse response = client.GetBucketLocation(request);

                // View response data
                Console.WriteLine("Bucket location - {0}", response.Location);

                #endregion
            }

            {
                #region PutBucket Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                PutBucketRequest request = new PutBucketRequest
                {
//.........这里部分代码省略.........
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:101,代码来源:BaseS3Samples.cs

示例7: ScanProfile


//.........这里部分代码省略.........
                    groopsreq.UserName = username;
                    ListGroupsForUserResult LG = iam.ListGroupsForUser(groopsreq);
                    foreach (var agroup in LG.Groups)
                    {
                        if (groups.Length > 1) groups += "\n";
                        groups += agroup.GroupName;
                    }

                    foreach (DataRow myrow in UserDetailsTable.Rows)
                    {
                        if (myrow["ARN"].Equals(arn))
                        {
                            myrow["UserID"] = auserid;
                            myrow["User-Policies"] = policylist;
                            myrow["Access-Keys"] = aklist;
                            myrow["Groups"] = groups;
                        }
                    }

                }
                #endregion

                #region S3Details
                try {

                AmazonS3Client S3Client = new AmazonS3Client(credential,Amazon.RegionEndpoint.USEast1);
                ListBucketsResponse response = S3Client.ListBuckets();
                foreach (S3Bucket abucket in response.Buckets)
                {

                    DataRow abucketrow = GetS3DetailsTable().NewRow();
                    var name = abucket.BucketName;

                    GetBucketLocationRequest gbr = new GetBucketLocationRequest();
                    gbr.BucketName=name;
                    GetBucketLocationResponse location = S3Client.GetBucketLocation(gbr);
                    var region = location.Location.Value;
                    if (region.Equals(""))region="us-east-1";
                    var pointy = RegionEndpoint.GetBySystemName(region);

                    //Build a config that references the buckets region.
                    AmazonS3Config S3C = new AmazonS3Config();
                    S3C.RegionEndpoint=pointy;
                    AmazonS3Client BS3Client = new AmazonS3Client(credential, S3C);

                    var createddate = abucket.CreationDate;
                    string owner = "";
                    string grants = "";
                    string tags = "";
                    string lastaccess = "";
                    string defaultpage = "";
                    string website = "";
                    //Now start pulling der einen data.

                    GetACLRequest GACR = new GetACLRequest();
                    GACR.BucketName = name;
                    var ACL = BS3Client.GetACL(GACR);
                    var grantlist = ACL.AccessControlList;
                    owner = grantlist.Owner.DisplayName;
                    foreach (var agrant in grantlist.Grants)
                    {
                        if (grants.Length > 1) grants += "\n";
                        var gName = agrant.Grantee.DisplayName;
                        var gType = agrant.Grantee.Type.Value;
                        var aMail = agrant.Grantee.EmailAddress;
开发者ID:ptierno,项目名称:AWSTrycorder,代码行数:66,代码来源:MainWindow.xaml.cs

示例8: ValidateS3Settings

 private static void ValidateS3Settings(string accessKeyId, string secretAccessKey, string bucket, string region)
 {
     if (string.IsNullOrEmpty(accessKeyId))
     {
         throw new ArgumentException("Empty access key id.", "accessKeyId");
     }
     if (string.IsNullOrEmpty(secretAccessKey))
     {
         throw new ArgumentException("Empty secret access key.", "secretAccessKey");
     }
     if (string.IsNullOrEmpty(bucket))
     {
         throw new ArgumentException("Empty s3 bucket.", "bucket");
     }
     if (string.IsNullOrEmpty(region))
     {
         throw new ArgumentException("Empty s3 region.", "region");
     }
     try
     {
         using (var s3 = new AmazonS3Client(accessKeyId, secretAccessKey, new AmazonS3Config {RegionEndpoint = RegionEndpoint.GetBySystemName(region)}))
         {
             s3.GetBucketLocation(new GetBucketLocationRequest {BucketName = bucket});
         }
     }
     catch(AmazonS3Exception error)
     {
         throw new Exception(error.ErrorCode);
     }
 }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:30,代码来源:BackupAjaxHandler.cs


注:本文中的Amazon.S3.AmazonS3Client.GetBucketLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。