AnnouncementEndpointElement.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // Author: Atsushi Enomoto <[email protected]>
  3. //
  4. // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining
  7. // a copy of this software and associated documentation files (the
  8. // "Software"), to deal in the Software without restriction, including
  9. // without limitation the rights to use, copy, modify, merge, publish,
  10. // distribute, sublicense, and/or sell copies of the Software, and to
  11. // permit persons to whom the Software is furnished to do so, subject to
  12. // the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be
  15. // included in all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. //
  25. #if NET_4_0
  26. using System;
  27. using System.ComponentModel;
  28. using System.Configuration;
  29. using System.ServiceModel.Configuration;
  30. using System.ServiceModel.Description;
  31. namespace System.ServiceModel.Discovery.Configuration
  32. {
  33. public class AnnouncementEndpointElement : StandardEndpointElement
  34. {
  35. static ConfigurationPropertyCollection properties;
  36. static ConfigurationProperty discovery_version, max_announcement_delay;
  37. static AnnouncementEndpointElement ()
  38. {
  39. discovery_version = new ConfigurationProperty ("discoveryVersion", typeof (DiscoveryVersion), "WSDiscovery11", new DiscoveryVersionConverter (), null, ConfigurationPropertyOptions.None);
  40. max_announcement_delay = new ConfigurationProperty ("maxAnnouncementDelay", typeof (TimeSpan), "00:00:00", new TimeSpanConverter (), null, ConfigurationPropertyOptions.None);
  41. properties = new ConfigurationPropertyCollection ();
  42. properties.Add (discovery_version);
  43. properties.Add (max_announcement_delay);
  44. }
  45. public AnnouncementEndpointElement ()
  46. {
  47. }
  48. [TypeConverter (typeof (DiscoveryVersionConverter))]
  49. [ConfigurationProperty ("discoveryVersion", DefaultValue = "WSDiscovery11")]
  50. public DiscoveryVersion DiscoveryVersion {
  51. get { return (DiscoveryVersion) base [discovery_version]; }
  52. set { base [discovery_version] = value; }
  53. }
  54. protected internal override Type EndpointType {
  55. get { return typeof (AnnouncementEndpoint); }
  56. }
  57. [TypeConverter (typeof (TimeSpanConverter))]
  58. [ConfigurationProperty ("maxAnnouncementDelay", DefaultValue = "00:00:00")]
  59. public TimeSpan MaxAnnouncementDelay {
  60. get { return (TimeSpan) base [max_announcement_delay]; }
  61. set { base [max_announcement_delay] = value; }
  62. }
  63. protected override ConfigurationPropertyCollection Properties {
  64. get { return properties; }
  65. }
  66. protected internal override ServiceEndpoint CreateServiceEndpoint (ContractDescription contractDescription)
  67. {
  68. if (contractDescription == null)
  69. throw new ArgumentNullException ("contractDescription");
  70. var ret = new AnnouncementEndpoint (DiscoveryVersion) { MaxAnnouncementDelay = this.MaxAnnouncementDelay };
  71. if (ret.Contract.ContractType != contractDescription.ContractType)
  72. throw new ArgumentException ("The argument contractDescription does not represent the expected Announcement contract");
  73. return ret;
  74. }
  75. protected internal override void InitializeFrom (ServiceEndpoint endpoint)
  76. {
  77. if (endpoint == null)
  78. throw new ArgumentNullException ("endpoint");
  79. AnnouncementEndpoint ae = (AnnouncementEndpoint) endpoint;
  80. DiscoveryVersion = ae.DiscoveryVersion;
  81. MaxAnnouncementDelay = ae.MaxAnnouncementDelay;
  82. }
  83. protected override void OnApplyConfiguration (ServiceEndpoint endpoint, ChannelEndpointElement serviceEndpointElement)
  84. {
  85. if (endpoint == null)
  86. throw new ArgumentNullException ("endpoint");
  87. AnnouncementEndpoint ae = (AnnouncementEndpoint) endpoint;
  88. if (!ae.DiscoveryVersion.Equals (DiscoveryVersion))
  89. throw new ArgumentException ("Argument AnnouncementEndpoint is initialized with different DiscoveryVersion");
  90. ae.MaxAnnouncementDelay = MaxAnnouncementDelay;
  91. ae.Address = serviceEndpointElement.CreateEndpointAddress (); // it depends on InternalVisibleTo(System.ServiceModel)
  92. ae.Binding = ConfigUtil.CreateBinding (serviceEndpointElement.Binding, serviceEndpointElement.BindingConfiguration); // it depends on InternalVisibleTo(System.ServiceModel)
  93. }
  94. protected override void OnApplyConfiguration (ServiceEndpoint endpoint, ServiceEndpointElement serviceEndpointElement)
  95. {
  96. if (endpoint == null)
  97. throw new ArgumentNullException ("endpoint");
  98. AnnouncementEndpoint ae = (AnnouncementEndpoint) endpoint;
  99. if (!ae.DiscoveryVersion.Equals (DiscoveryVersion))
  100. throw new ArgumentException ("Argument AnnouncementEndpoint is initialized with different DiscoveryVersion");
  101. ae.MaxAnnouncementDelay = MaxAnnouncementDelay;
  102. ae.Address = serviceEndpointElement.CreateEndpointAddress (); // it depends on InternalVisibleTo(System.ServiceModel)
  103. ae.Binding = ConfigUtil.CreateBinding (serviceEndpointElement.Binding, serviceEndpointElement.BindingConfiguration); // it depends on InternalVisibleTo(System.ServiceModel)
  104. }
  105. protected override void OnInitializeAndValidate (ChannelEndpointElement channelEndpointElement)
  106. {
  107. // It seems to do nothing.
  108. }
  109. protected override void OnInitializeAndValidate (ServiceEndpointElement serviceEndpointElement)
  110. {
  111. // It seems to do nothing.
  112. }
  113. }
  114. }
  115. #endif