コード例 #1
0
ファイル: BucketRegionCache.cs プロジェクト: jflzbest/C-
        /// <summary>
        /// Updates Region cache for given bucket.
        /// </summary>
        /// <param name="bucketName"></param>
        internal async Task <string> Update(MinioClient client, string bucketName)
        {
            string region = null;

            if (bucketName != null && client.AccessKey != null &&
                client.SecretKey != null && !Instance.Exists(bucketName))
            {
                string location = null;
                var    path     = utils.UrlEncode(bucketName) + "?location";
                // Initialize client
                Uri requestUrl = RequestUtil.MakeTargetURL(client.BaseUrl, client.Secure);
                client.SetTargetURL(requestUrl);

                var request = new RestRequest(path, Method.GET);

                var response = await client.ExecuteTaskAsync(client.NoErrorHandlers, request).ConfigureAwait(false);

                if (HttpStatusCode.OK.Equals(response.StatusCode))
                {
                    var       contentBytes = System.Text.Encoding.UTF8.GetBytes(response.Content);
                    var       stream       = new MemoryStream(contentBytes);
                    XDocument root         = XDocument.Parse(response.Content);
                    location = root.Root.Value;
                }
                if (location == null || location == "")
                {
                    region = "us-east-1";
                }
                else
                {
                    // eu-west-1 can be sometimes 'EU'.
                    if ("EU".Equals(location))
                    {
                        region = "eu-west-1";
                    }
                    else
                    {
                        region = location;
                    }
                }

                // Add the new location.
                Instance.Add(bucketName, region);
            }
            return(region);
        }