PeerNodeAddress.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel
  5. {
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.Collections.ObjectModel;
  9. using System.Net;
  10. using System.Runtime.Serialization;
  11. using System.ServiceModel.Channels;
  12. [DataContract(Name = "PeerNodeAddress", Namespace = PeerStrings.Namespace)]
  13. [KnownType(typeof(IPAddress[]))]
  14. public sealed class PeerNodeAddress
  15. {
  16. [DataMember(Name = "EndpointAddress")]
  17. internal EndpointAddress10 InnerEPR
  18. {
  19. get { return this.endpointAddress == null ? null : EndpointAddress10.FromEndpointAddress(this.endpointAddress); }
  20. set { this.endpointAddress = (value == null ? null : value.ToEndpointAddress()); }
  21. }
  22. EndpointAddress endpointAddress;
  23. string servicePath;
  24. ReadOnlyCollection<IPAddress> ipAddresses;
  25. [DataMember(Name = "IPAddresses")]
  26. internal IList<IPAddress> ipAddressesDataMember
  27. {
  28. get { return ipAddresses; }
  29. set { ipAddresses = new ReadOnlyCollection<IPAddress>((value == null) ? new IPAddress[0] : value); }
  30. }
  31. //NOTE: if a default constructor is provided, make sure to review ServicePath property getter.
  32. public PeerNodeAddress(EndpointAddress endpointAddress, ReadOnlyCollection<IPAddress> ipAddresses)
  33. {
  34. if (endpointAddress == null)
  35. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("endpointAddress"));
  36. if (ipAddresses == null)
  37. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("ipAddresses"));
  38. Initialize(endpointAddress, ipAddresses);
  39. }
  40. void Initialize(EndpointAddress endpointAddress, ReadOnlyCollection<IPAddress> ipAddresses)
  41. {
  42. this.endpointAddress = endpointAddress;
  43. servicePath = this.endpointAddress.Uri.PathAndQuery.ToUpperInvariant();
  44. this.ipAddresses = ipAddresses;
  45. }
  46. public EndpointAddress EndpointAddress
  47. {
  48. get { return this.endpointAddress; }
  49. }
  50. internal string ServicePath
  51. {
  52. get
  53. {
  54. if (this.servicePath == null)
  55. {
  56. this.servicePath = this.endpointAddress.Uri.PathAndQuery.ToUpperInvariant();
  57. }
  58. return this.servicePath;
  59. }
  60. }
  61. public ReadOnlyCollection<IPAddress> IPAddresses
  62. {
  63. get
  64. {
  65. if (this.ipAddresses == null)
  66. {
  67. this.ipAddresses = new ReadOnlyCollection<IPAddress>(new IPAddress[0]);
  68. }
  69. return this.ipAddresses;
  70. }
  71. }
  72. }
  73. }