コード例 #1
0
        public static void AddEndpoint(String endpointName, String regionId, String product, String domain, bool isNeverExpire)
        {
            //unity3d could not "Assembly GetManifestResourceStream XML", so skip "GetEndpoints" ...
            endpoints = new List <Endpoint>();

            if (null == endpoints)
            {
                endpoints = GetProfile().GetEndpoints(regionId, product);
            }

            Endpoint endpoint = FindEndpointByRegionId(regionId);

            if (null == endpoint)
            {
                AddEndpoint_(endpointName, regionId, product, domain);
            }
            else
            {
                UpdateEndpoint(regionId, product, domain, endpoint);
            }

            if (isNeverExpire)
            {
                DateTime date = DateTime.Now.AddYears(100);
                CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, date);
            }
        }
コード例 #2
0
        public static void AddEndpoint(string endpointName, string regionId, string product, string domain,
                                       bool isNeverExpire)
        {
            if (null == endpoints)
            {
                endpoints = GetProfile().GetEndpoints(regionId, product);
            }

            var endpoint = FindEndpointByRegionId(regionId);

            if (null == endpoint)
            {
                AddEndpoint_(endpointName, regionId, product, domain);
            }
            else
            {
                UpdateEndpoint(regionId, product, domain, endpoint);
            }

            if (isNeverExpire)
            {
                var date = DateTime.Now.AddYears(100);
                CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, date);
            }
        }
コード例 #3
0
        private List <Endpoint> GetEndpointsFromLocation(String regionId, String product, Credential credential, String locationProduct, String locationEndpointType)
        {
            if (null == locationEndpoints)
            {
                locationEndpoints = new List <Endpoint>();
            }

            Endpoint endpoint = FindLocationEndpointByRegionId(regionId);

            if (null == endpoint || CacheTimeHelper.CheckCacheIsExpire(product, regionId))
            {
                FillEndpointFromLocation(regionId, product, credential, locationProduct, locationEndpointType);
            }
            else
            {
                List <ProductDomain> productDomains = endpoint.ProductDomains;
                ProductDomain        productDomain  = FindProductDomain(productDomains, product);
                if (null == productDomain)
                {
                    FillEndpointFromLocation(regionId, product, credential, locationProduct, locationEndpointType);
                }
            }

            return(locationEndpoints);
        }
コード例 #4
0
        public List <Endpoint> GetEndpoints(string product, string regionId, string serviceCode, string endpointType)

        {
            if (product == null)
            {
                return(endpoints);
            }

            if (null == endpoints)
            {
                Endpoint endpoint = null;
                if (serviceCode != null)
                {
                    endpoint = GetEndpointByRemoteProvider(regionId, product, serviceCode, endpointType);
                }
                if (endpoint == null)
                {
                    endpoint = GetEndpointByIEndpoints(regionId, product);
                }
                if (endpoint != null)
                {
                    endpoints = new List <Endpoint>
                    {
                        endpoint
                    };
                    CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, DateTime.Now);
                }
                else
                {
                    throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access.");
                }
            }
            else if (Endpoint.FindProductDomain(regionId, product, endpoints) == null || CacheTimeHelper.CheckCacheIsExpire(product, regionId))
            {
                Endpoint endpoint = null;
                if (serviceCode != null)
                {
                    endpoint = GetEndpointByRemoteProvider(regionId, product, serviceCode, endpointType);
                }
                if (endpoint == null)
                {
                    endpoint = GetEndpointByIEndpoints(regionId, product);
                }
                if (endpoint != null)
                {
                    foreach (string region in endpoint.RegionIds)
                    {
                        foreach (ProductDomain productDomain in endpoint.ProductDomains.ToList())
                        {
                            AddEndpoint(endpoint.Name, region, product, productDomain.DomianName, false);
                            CacheTimeHelper.AddLastClearTimePerProduct(product, region, DateTime.Now);
                        }
                    }
                }
            }
            return(endpoints);
        }
コード例 #5
0
        public void AddLastClearTimePerProduct()
        {
            DateTime lastClearTime = DateTime.Now.AddDays(-1);

            CacheTimeHelper.AddLastClearTimePerProduct("ecs", "ch-hangzhou", lastClearTime);
            Assert.True(CacheTimeHelper.CheckCacheIsExpire("ecs", "ch-hangzhou"));

            lastClearTime = DateTime.Now.AddDays(1);
            CacheTimeHelper.AddLastClearTimePerProduct("ecs", "ch-hangzhou", lastClearTime);
            Assert.False(CacheTimeHelper.CheckCacheIsExpire("ecs", "ch-hangzhou"));
        }
コード例 #6
0
        public void CheckCacheIsExpire()
        {
            // When Not Exist
            Assert.False(CacheTimeHelper.CheckCacheIsExpire("someNotExist", "ch-hangzhou"));

            // When Exist
            DateTime lastClearTime = DateTime.Now.AddDays(-1);

            CacheTimeHelper.AddLastClearTimePerProduct("ecs", "ch-hangzhou", lastClearTime);
            Assert.True(CacheTimeHelper.CheckCacheIsExpire("ecs", "ch-hangzhou"));
        }
コード例 #7
0
        public List <Endpoint> GetEndpoints(String product, String regionId, String serviceCode, String endpointType)
        {
            if (product == null)
            {
                return(endpoints);
            }

            if (null == endpoints)
            {
                Endpoint endpoint = null;
                if (serviceCode != null)
                {
                    endpoint = remoteProvider.GetEndpoint(regionId, product, serviceCode, endpointType, credential, locationConfig);
                }
                if (endpoint == null)
                {
                    endpoint = iendpoints.GetEndpoint(regionId, product);
                }
                if (endpoint != null)
                {
                    endpoints = new List <Endpoint>();
                    endpoints.Add(endpoint);
                    CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, DateTime.Now);
                }
            }
            else if (Endpoint.FindProductDomain(regionId, product, endpoints) == null || CacheTimeHelper.CheckCacheIsExpire(product, regionId))
            {
                Endpoint endpoint = null;
                if (serviceCode != null)
                {
                    endpoint = remoteProvider.GetEndpoint(regionId, product, serviceCode, endpointType, credential, locationConfig);
                }
                if (endpoint == null)
                {
                    endpoint = iendpoints.GetEndpoint(regionId, product);
                }
                if (endpoint != null)
                {
                    foreach (String region in endpoint.RegionIds)
                    {
                        foreach (ProductDomain productDomain in endpoint.ProductDomains)
                        {
                            AddEndpoint(endpoint.Name, region, product, productDomain.DomianName, false);
                            CacheTimeHelper.AddLastClearTimePerProduct(product, region, DateTime.Now);
                        }
                    }
                }
            }
            return(endpoints);
        }
コード例 #8
0
        private void FillEndpointFromLocation(String regionId, String product, Credential credential, String locationProduct, String locationEndpointType)
        {
            Endpoint endpoint = remoteProvider.GetEndpoint(regionId, product, locationProduct, credential,
                                                           locationConfig, locationEndpointType);

            if (endpoint != null)
            {
                foreach (String region in endpoint.RegionIds)
                {
                    foreach (ProductDomain productDomain in endpoint.ProductDomains)
                    {
                        AddLocationEndpoint(endpoint.Name, region, product, productDomain.DomianName);
                        CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, DateTime.Now);
                    }
                }
            }
        }
コード例 #9
0
        public static void AddEndpoint(String endpointName, String regionId, String product, String domain)
        {
            if (null == endpoints)
            {
                endpoints = GetProfile().GetEndpoints();
            }
            Endpoint endpoint = FindEndpointByName(endpointName);

            if (null == endpoint)
            {
                AddEndpoint_(endpointName, regionId, product, domain);
            }
            else
            {
                UpdateEndpoint(regionId, product, domain, endpoint);
            }

            AddLocationEndpoint(endpointName, regionId, product, domain);
            DateTime expireTime = DateTime.Now.AddYears(100);

            CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, expireTime);
        }
コード例 #10
0
        public async Task AddEndpointAsync(string endpointName, string regionId, string product, string domain,
                                           bool isNeverExpire = false,
                                           CancellationToken cancellationToken = default(CancellationToken))
        {
            if (0 == _endpoints.Count)
            {
                _endpoints = await GetEndpointsAsync(regionId, product, cancellationToken).ConfigureAwait(false);
            }

            var endpoint = FindEndpointByRegionId(regionId);

            if (null == endpoint)
            {
                var regions = new HashSet <string> {
                    regionId
                };

                var productDomains = new List <ProductDomain> {
                    new ProductDomain(product, domain)
                };
                endpoint = new Endpoint(endpointName, regions, productDomains);
                if (_endpoints == null)
                {
                    _endpoints = new List <Endpoint>();
                }

                _endpoints.Add(endpoint);
            }
            else
            {
                UpdateEndpoint(regionId, product, domain, endpoint);
            }

            if (isNeverExpire)
            {
                var date = DateTime.UtcNow.AddYears(100);
                CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, date);
            }
        }
コード例 #11
0
        public void AddEndpoint(string endpointName, string regionId, string product, string domain,
                                bool isNeverExpire = false)
        {
            if (0 == _endpoints.Count)
            {
                _endpoints = GetEndpoints(regionId, product);
            }

            var endpoint = FindEndpointByRegionId(regionId);

            if (null == endpoint)
            {
                var regions = new HashSet <string> {
                    regionId
                };

                var productDomains = new List <ProductDomain> {
                    new ProductDomain(product, domain)
                };
                endpoint = new Endpoint(endpointName, regions, productDomains);
                if (_endpoints == null)
                {
                    _endpoints = new List <Endpoint>();
                }

                _endpoints.Add(endpoint);
            }
            else
            {
                UpdateEndpoint(regionId, product, domain, endpoint);
            }

            if (isNeverExpire)
            {
                var date = DateTime.UtcNow.AddYears(100);
                CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, date);
            }
        }
コード例 #12
0
        public List <Endpoint> Resolve(string product, string regionId, string serviceCode, string endpointType,
                                       Credential credential, LocationConfig locationConfig)
        {
            try
            {
                if (product == null)
                {
                    return(_endpoints);
                }

                if (_endpoints.FirstOrDefault(x => x.Name == product) != null)
                {
                    var endpoint = internalEndpointProvider.GetEndpoint(regionId, product);

                    if (serviceCode != null && endpoint == null)
                    {
                        endpoint = remoteEndpointProvider.GetEndpoint(regionId, product, serviceCode, endpointType,
                                                                      credential, locationConfig);
                    }

                    if (endpoint != null)
                    {
                        _endpoints.Add(endpoint);
                        CacheTimeHelper.AddLastClearTimePerProduct(product, regionId, DateTime.UtcNow);
                    }
                    else
                    {
                        throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access.");
                    }
                }
                else if (Endpoint.FindProductDomain(regionId, product, _endpoints) == null ||
                         CacheTimeHelper.CheckCacheIsExpire(product, regionId))
                {
                    var endpoint = internalEndpointProvider.GetEndpoint(regionId, product);

                    if (serviceCode != null && endpoint == null)
                    {
                        endpoint = remoteEndpointProvider.GetEndpoint(regionId, product, serviceCode, endpointType,
                                                                      credential, locationConfig);
                    }

                    if (endpoint != null)
                    {
                        foreach (var region in endpoint.RegionIds)
                        {
                            foreach (var productDomain in endpoint.ProductDomains.ToList())
                            {
                                AddEndpoint(endpoint.Name, region, product, productDomain.DomainName);
                                CacheTimeHelper.AddLastClearTimePerProduct(product, region, DateTime.UtcNow);
                            }
                        }
                    }
                }
            }
            catch (ClientException ex)
            {
                CommonLog.LogException(ex, ex.ErrorCode, ex.ErrorMessage);
                throw new ClientException(ex.ErrorCode, ex.ErrorMessage);
            }

            return(_endpoints);
        }