EndpointDiscoveryElement.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.Xml;
  31. using System.Xml.Linq;
  32. namespace System.ServiceModel.Discovery.Configuration
  33. {
  34. public sealed class EndpointDiscoveryElement : BehaviorExtensionElement
  35. {
  36. static ConfigurationPropertyCollection properties;
  37. static ConfigurationProperty types, enabled, extensions, scopes;
  38. static EndpointDiscoveryElement ()
  39. {
  40. types = new ConfigurationProperty ("types", typeof (ContractTypeNameElementCollection), null, null, null, ConfigurationPropertyOptions.None);
  41. enabled = new ConfigurationProperty ("enabled", typeof (bool), null, null, null, ConfigurationPropertyOptions.None);
  42. extensions = new ConfigurationProperty ("extensions", typeof (XmlElementElementCollection), null, null, null, ConfigurationPropertyOptions.None);
  43. scopes = new ConfigurationProperty ("scopes", typeof (ScopeElementCollection), null, null, null, ConfigurationPropertyOptions.None);
  44. properties = new ConfigurationPropertyCollection ();
  45. properties.Add (types);
  46. properties.Add (enabled);
  47. properties.Add (extensions);
  48. properties.Add (scopes);
  49. }
  50. public EndpointDiscoveryElement ()
  51. {
  52. }
  53. public override Type BehaviorType {
  54. get { return typeof (EndpointDiscoveryBehavior); }
  55. }
  56. [ConfigurationProperty ("types")]
  57. public ContractTypeNameElementCollection ContractTypeNames {
  58. get { return (ContractTypeNameElementCollection) base [types]; }
  59. }
  60. [ConfigurationPropertyAttribute("enabled", DefaultValue = true)]
  61. public bool Enabled {
  62. get { return (bool) base [enabled]; }
  63. set { base [enabled] = value; }
  64. }
  65. [ConfigurationPropertyAttribute("extensions")]
  66. public XmlElementElementCollection Extensions {
  67. get { return (XmlElementElementCollection) base [extensions]; }
  68. }
  69. [ConfigurationPropertyAttribute("scopes")]
  70. public ScopeElementCollection Scopes {
  71. get { return (ScopeElementCollection) base [scopes]; }
  72. }
  73. protected override ConfigurationPropertyCollection Properties {
  74. get { return properties; }
  75. }
  76. protected internal override object CreateBehavior ()
  77. {
  78. var ret = new EndpointDiscoveryBehavior () { Enabled = this.Enabled };
  79. foreach (ContractTypeNameElement ctn in ContractTypeNames)
  80. ret.ContractTypeNames.Add (new XmlQualifiedName (ctn.Name, ctn.Namespace));
  81. foreach (XmlElementElement xee in Extensions)
  82. ret.Extensions.Add (XElement.Load (new XmlNodeReader (xee.XmlElement)));
  83. foreach (ScopeElement se in Scopes)
  84. ret.Scopes.Add (se.Scope);
  85. return ret;
  86. }
  87. }
  88. }
  89. #endif