Esempio n. 1
0
        public List <Endpoint> GetEndpoints()
        {
            XmlDocument     doc           = LoadEndpointDocument();
            List <Endpoint> endpoints     = new List <Endpoint>();
            XmlNodeList     endpointNodes = doc.GetElementsByTagName("Endpoint");

            foreach (XmlNode node in endpointNodes)
            {
                HashSet <string> regionIds = new HashSet <string>();

                List <ProductDomain> products      = new List <ProductDomain>();
                XmlNodeList          regionIdNodes = node.SelectSingleNode("RegionIds").SelectNodes("RegionId");
                XmlNodeList          productNodes  = node.SelectSingleNode("Products").SelectNodes("Product");
                foreach (XmlNode regionIdNode in regionIdNodes)
                {
                    regionIds.Add(regionIdNode.InnerText);
                }

                foreach (XmlNode productNode in productNodes)
                {
                    ProductDomain productDomain = new ProductDomain();
                    productDomain.DomianName  = productNode.SelectSingleNode("DomainName").InnerText;
                    productDomain.ProductName = productNode.SelectSingleNode("ProductName").InnerText;
                    products.Add(productDomain);
                }
                endpoints.Add(new Endpoint(node.Attributes["name"].InnerText, regionIds, products));
            }

            return(endpoints);
        }
        public DescribeEndpointResponse DescribeEndpoint(String regionId, String locationProduct,
                                                         Credential credential, LocationConfig locationConfig, String locationEndpointType)
        {
            if (isEmpty(locationProduct))
            {
                return(null);
            }

            DescribeEndpointRequest request = new DescribeEndpointRequest();

            request.AcceptFormat    = FormatType.JSON;
            request.Id              = regionId;
            request.RegionId        = locationConfig.RegionId;
            request.LocationProduct = locationProduct;
            if (isEmpty(locationEndpointType))
            {
                request.EndpointType = DEFAULT_ENDPOINT_TYPE;
            }
            else
            {
                request.EndpointType = locationEndpointType;
            }


            ProductDomain domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            try
            {
                HttpRequest  httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
                HttpResponse httpResponse = HttpResponse.GetResponse(httpRequest);
                if (httpResponse.isSuccess())
                {
                    String data = System.Text.Encoding.UTF8.GetString(httpResponse.Content);
                    DescribeEndpointResponse response = getEndpointResponse(data, request.EndpointType);
                    if (null == response || isEmpty(response.Endpoint))
                    {
                        return(null);
                    }
                    return(response);
                }
                AcsError error = readError(httpResponse, FormatType.JSON);
                if (500 <= httpResponse.Status)
                {
                    Console.WriteLine("Invoke_Error, requestId: " + error.RequestId + "; code: " + error.ErrorCode
                                      + "; Msg: " + error.ErrorMessage);
                    return(null);
                }
                Console.WriteLine("Invoke_Error, requestId: " + error.RequestId + "; code: " + error.ErrorCode
                                  + "; Msg: " + error.ErrorMessage);
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invoke Remote Error,Msg" + e.Message);
                return(null);
            }
        }
Esempio n. 3
0
        public async Task <DescribeEndpointResponse> DescribeEndpointAsync(String regionId, String locationProduct,
                                                                           Credential credential, LocationConfig locationConfig)
        {
            if (IsEmpty(locationProduct))
            {
                return(null);
            }

            var request = new DescribeEndpointRequest
            {
                AcceptFormat    = FormatType.JSON,
                Id              = regionId,
                RegionId        = locationConfig.RegionId,
                LocationProduct = locationProduct,
                EndpointType    = DEFAULT_ENDPOINT_TYPE
            };

            var domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            try
            {
                var httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
                var httpResponse = await HttpResponse.GetResponseAsync(httpRequest);

                if (httpResponse.IsSuccess())
                {
                    var data = Encoding.UTF8.GetString(httpResponse.Content);
                    DescribeEndpointResponse response = GetEndpointResponse(data, DEFAULT_ENDPOINT_TYPE);
                    if (null == response || IsEmpty(response.Endpoint))
                    {
                        return(null);
                    }

                    return(response);
                }

                var error = ReadError(httpResponse, FormatType.JSON);
                if (500 <= httpResponse.Status)
                {
                    Console.WriteLine("Invoke_Error, requestId:" + error.RequestId + "; code:" + error.ErrorCode
                                      + "; Msg" + error.ErrorMessage);
                    return(null);
                }

                Console.WriteLine("Invoke_Error, requestId:" + error.RequestId + "; code:" + error.ErrorCode
                                  + "; Msg" + error.ErrorMessage);

                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invoke Remote Error,Msg" + e.Message);
                return(null);
            }
        }
        public static ProductDomain GetProductDomain(string product, string regionId)
        {
            string        key           = product + "_" + regionId;
            ProductDomain productDomain = null;

            if (endpoints.ContainsKey(key))
            {
                productDomain = endpoints[key];
            }
            return(productDomain);
        }
Esempio n. 5
0
        public async Task <DescribeEndpointResponse> DescribeEndpointAsync(string regionId, string serviceCode, string endpointType,
                                                                           Credential credential, LocationConfig locationConfig,
                                                                           CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(serviceCode))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(endpointType))
            {
                endpointType = DEFAULT_ENDPOINT_TYPE;
            }

            var request = new DescribeEndpointRequest
            {
                AcceptFormat    = FormatType.JSON,
                Id              = regionId,
                RegionId        = locationConfig.RegionId,
                LocationProduct = serviceCode,
                SecurityToken   = credential.SecurityToken,
                EndpointType    = endpointType
            };

            var signer = Signer.GetSigner(new LegacyCredentials(credential));
            var domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            var httpRequest = request.SignRequest(signer, credential, FormatType.JSON, domain);

            httpRequest.SetConnectTimeoutInMilliSeconds(100000);
            httpRequest.SetReadTimeoutInMilliSeconds(100000);
            var httpResponse = await GetResponseAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            if (httpResponse.isSuccess())
            {
                var data     = Encoding.UTF8.GetString(httpResponse.Content);
                var response = GetEndpointResponse(data, endpointType);
                if (response == null || string.IsNullOrEmpty(response.Endpoint))
                {
                    return(null);
                }

                return(response);
            }

            var error = ReadError(httpResponse, FormatType.JSON);

            if (500 <= httpResponse.Status)
            {
                return(null);
            }

            return(null);
        }
        public static void AddEndpoint(string product, string regionId, string domain)
        {
            if (product == null || regionId == null || domain == null)
            {
                return;
            }
            string key = product + "_" + regionId;

            if (!endpoints.ContainsKey(key))
            {
                ProductDomain productDomain = new ProductDomain(product, domain);
                endpoints.Add(key, productDomain);
            }
        }
Esempio n. 7
0
        public DescribeEndpointResponse DescribeEndpoint(string regionId, string serviceCode, string endpointType,
                                                         Credential credential, LocationConfig locationConfig)
        {
            if (string.IsNullOrEmpty(serviceCode))
            {
                return(null);
            }

            if (string.IsNullOrEmpty(endpointType))
            {
                endpointType = DEFAULT_ENDPOINT_TYPE;
            }

            var request = new DescribeEndpointRequest
            {
                AcceptFormat    = FormatType.JSON,
                Id              = regionId,
                RegionId        = locationConfig.RegionId,
                LocationProduct = serviceCode,
                SecurityToken   = credential.SecurityToken,
                EndpointType    = endpointType
            };

            var signer = Signer.GetSigner(new LegacyCredentials(credential));
            var domain = new ProductDomain(locationConfig.Product, locationConfig.Endpoint);

            var httpRequest  = request.SignRequest(signer, credential, FormatType.JSON, domain);
            var httpResponse = GetResponse(httpRequest);

            if (httpResponse.isSuccess())
            {
                var data     = Encoding.UTF8.GetString(httpResponse.Content);
                var response = GetEndpointResponse(data, endpointType);
                if (response == null || string.IsNullOrEmpty(response.Endpoint))
                {
                    return(null);
                }

                return(response);
            }

            var error = ReadError(httpResponse, FormatType.JSON);

            if (500 <= httpResponse.Status)
            {
                return(null);
            }

            return(null);
        }
        public Endpoint GetEndpoint(string region, string product)
        {
            List <Product> allProducts = GetProducts();

            HashSet <String>     regionSet      = new HashSet <String>();
            List <ProductDomain> productDomains = new List <ProductDomain>();

            foreach (Product p in allProducts)
            {
                if (!string.Equals(product, p.Code, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                foreach (var e in p.RegionalEndpoints)
                {
                    if (!string.Equals(region, e.Key, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    regionSet.Add(region);

                    ProductDomain productDomain = new ProductDomain();
                    productDomain.ProductName = product;
                    productDomain.DomianName  = e.Value;
                    productDomains.Add(productDomain);
                }

                if (regionSet.Count == 0)
                {
                    if (string.IsNullOrEmpty(p.GlobalEndpoint))
                    {
                        return(null);
                    }

                    regionSet.Add(region);

                    ProductDomain productDomain = new ProductDomain();
                    productDomain.ProductName = product;
                    productDomain.DomianName  = p.GlobalEndpoint;
                    productDomains.Add(productDomain);
                }

                break;
            }

            return(new Endpoint(region, regionSet, productDomains));
        }
Esempio n. 9
0
 public static ProductDomain FindProductDomain(String regionId, String product,
                                               List <Endpoint> endpoints)
 {
     if (null == regionId || null == product || null == endpoints)
     {
         return(null);
     }
     foreach (Endpoint endpoint in endpoints)
     {
         if (endpoint.RegionIds.Contains(regionId))
         {
             ProductDomain domain = FindProductDomainByProduct(endpoint.ProductDomains, product);
             return(domain);
         }
     }
     return(null);
 }
Esempio n. 10
0
 public static ProductDomain FindProductDomain(String regionId, String product,
                                               List <Endpoint> endpoints, IAcsClient acsClient)
 {
     if (null == regionId || null == product || null == endpoints)
     {
         return(null);
     }
     foreach (Endpoint endpoint in endpoints)
     {
         if (endpoint.RegionIds.Contains(regionId))
         {
             ProductDomain domain = FindProductDomainByProduct(endpoint.ProductDomains, product);
             return(domain);
         }
     }
     if ("Location".Equals(product))
     {
         return(new ProductDomain("Location", "location.aliyuncs.com"));
     }
     return(null);
 }
        private static ProductDomain GetEndpointByLocation(String regionId, String product,
                                                           List <Endpoint> endpoints, IAcsClient acsClient)
        {
            ProductDomain productDomain = GetProductDomainByLocation(regionId, product, acsClient);

            foreach (Endpoint endpoint in endpoints)
            {
                if (endpoint.RegionIds.Contains(regionId))
                {
                    endpoint.ProductDomains.Add(productDomain);
                    return(productDomain);
                }
            }

            ISet <string> regionIds = new HashSet <String>();

            regionIds.Add(regionId);
            List <ProductDomain> productDomains = new List <ProductDomain>();

            productDomains.Add(productDomain);

            endpoints.Add(new Endpoint(regionId, regionIds, productDomains));
            return(productDomain);
        }