예제 #1
0
    /// <summary>
    ///     Resolve region of the bucket.
    /// </summary>
    /// <param name="bucketName"></param>
    /// <returns></returns>
    private async Task <string> GetRegion(string bucketName)
    {
        var rgn = "";

        // Use user specified region in client constructor if present
        if (Region != string.Empty)
        {
            return(Region);
        }

        // pick region from endpoint if present
        if (!string.IsNullOrEmpty(Endpoint))
        {
            rgn = Regions.GetRegionFromEndpoint(Endpoint);
        }

        // Pick region from location HEAD request
        if (rgn == string.Empty)
        {
            if (!BucketRegionCache.Instance.Exists(bucketName))
            {
                rgn = await BucketRegionCache.Instance.Update(this, bucketName).ConfigureAwait(false);
            }
            else
            {
                rgn = BucketRegionCache.Instance.Region(bucketName);
            }
        }

        // Defaults to us-east-1 if region could not be found
        return(rgn == string.Empty ? "us-east-1" : rgn);
    }
예제 #2
0
파일: RegionTest.cs 프로젝트: jflzbest/C-
        public void TestGetRegion()
        {
            Dictionary <string, string> endpoint2Region = new Dictionary <string, string>
            {
                { "s3.us-east-2.amazonaws.com", "us-east-2" },
                { "s3.amazonaws.com", "" },
                { "testbucket.s3-ca-central-1.amazonaws.com", "ca-central-1" },
                { "mybucket-s3-us-east-2.amazonaws.com", "us-east-2" },
                { "s3.us-west-1.amazonaws.com", "us-west-1" },
                { "mybucket-s3-us-west-1.amazonaws.com", "us-west-1" },
            };

            foreach (KeyValuePair <string, string> testCase in endpoint2Region)
            {
                Assert.AreEqual(Regions.GetRegionFromEndpoint(testCase.Key), testCase.Value);
            }
        }
예제 #3
0
 public void TestGetRegion(string endpoint, string expectedRegion)
 {
     Assert.AreEqual(expectedRegion, Regions.GetRegionFromEndpoint(endpoint));
 }