コード例 #1
0
        /// <summary>
        /// Returns the Region the bucket resides in.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public List <string> GetBucketLocation(GetBucketLocationRequest request)
        {
            ListRegionSubscriptionsRequest listRegionSubscriptionsRequest = new ListRegionSubscriptionsRequest
            {
                TenancyId = base.Config.TenancyId
            };
            var regions = IdentityClient.ListRegionSubscriptions(listRegionSubscriptionsRequest);

            var nameSpaceName = GetNamespace(request);

            List <string> res = new List <string>();

            foreach (var region in regions.Items)
            {
                ObjectStorageClient.SetRegion(region.RegionName);

                GetBucketRequest getBucketRequest = new GetBucketRequest
                {
                    NamespaceName = nameSpaceName,
                    BucketName    = request.BucketName
                };

                try
                {
                    var b = ObjectStorageClient.GetBucket(getBucketRequest);

                    if (b.Bucket != null)
                    {
                        res.Add(region.RegionName);
                    }
                }
                catch (WebException we)
                {
                    if (!(we.Status.Equals(WebExceptionStatus.ProtocolError) && ((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.NotFound))
                    {
                        throw;
                    }
                }
            }

            if (res.Count <= 0)
            {
                throw new Exception("NoSuchBucket");
            }

            return(res);
        }
コード例 #2
0
        private string GetNamespace(GetBucketLocationRequest request)
        {
            string nameSpaceName;

            if (string.IsNullOrEmpty(request.NamespaceName))
            {
                nameSpaceName = ObjectStorageClient.GetNamespace(new GetNamespaceRequest());
            }
            else
            {
                nameSpaceName = request.NamespaceName;
            }

            if (string.IsNullOrEmpty(nameSpaceName))
            {
                throw new Exception("NamespaceNotFound");
            }

            return(nameSpaceName);
        }