Endpoint.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. using Aliyun.Acs.Core.Regions.Location.Model;
  20. using System;
  21. using System.Collections.Generic;
  22. namespace Aliyun.Acs.Core.Regions
  23. {
  24. public class Endpoint
  25. {
  26. public string Name { get; set; }
  27. public ISet<string> RegionIds { get; set; }
  28. public List<ProductDomain> ProductDomains { get; set; }
  29. public Endpoint(String name, ISet<string> regionIds, List<ProductDomain> productDomains)
  30. {
  31. this.Name = name;
  32. this.RegionIds = regionIds;
  33. this.ProductDomains = productDomains;
  34. }
  35. public static ProductDomain FindProductDomain(String regionId, String product,
  36. List<Endpoint> endpoints, IAcsClient acsClient)
  37. {
  38. if (null == regionId || null == product || null == endpoints)
  39. {
  40. return null;
  41. }
  42. foreach (Endpoint endpoint in endpoints)
  43. {
  44. if (endpoint.RegionIds.Contains(regionId))
  45. {
  46. ProductDomain domain = FindProductDomainByProduct(endpoint.ProductDomains, product);
  47. return domain;
  48. }
  49. }
  50. if ("Location".Equals(product))
  51. {
  52. return new ProductDomain("Location", "location.aliyuncs.com");
  53. }
  54. return null;
  55. }
  56. private static ProductDomain FindProductDomainByProduct(List<ProductDomain> productDomains, String product)
  57. {
  58. if (null == productDomains)
  59. {
  60. return null;
  61. }
  62. foreach (ProductDomain productDomain in productDomains)
  63. {
  64. if (product.Equals(productDomain.ProductName))
  65. {
  66. return productDomain;
  67. }
  68. }
  69. return null;
  70. }
  71. }
  72. }