OneWayElement.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Configuration;
  7. using System.ServiceModel.Channels;
  8. using System.ServiceModel;
  9. public sealed partial class OneWayElement : BindingElementExtensionElement
  10. {
  11. public OneWayElement()
  12. {
  13. }
  14. public override Type BindingElementType
  15. {
  16. get { return typeof(OneWayBindingElement); }
  17. }
  18. [ConfigurationProperty(ConfigurationStrings.ChannelPoolSettings)]
  19. public ChannelPoolSettingsElement ChannelPoolSettings
  20. {
  21. get { return (ChannelPoolSettingsElement)base[ConfigurationStrings.ChannelPoolSettings]; }
  22. }
  23. [ConfigurationProperty(ConfigurationStrings.MaxAcceptedChannels, DefaultValue = OneWayDefaults.MaxAcceptedChannels)]
  24. [IntegerValidator(MinValue = 1)]
  25. public int MaxAcceptedChannels
  26. {
  27. get { return (int)base[ConfigurationStrings.MaxAcceptedChannels]; }
  28. set { base[ConfigurationStrings.MaxAcceptedChannels] = value; }
  29. }
  30. [ConfigurationProperty(ConfigurationStrings.PacketRoutable, DefaultValue = OneWayDefaults.PacketRoutable)]
  31. public bool PacketRoutable
  32. {
  33. get { return (bool)base[ConfigurationStrings.PacketRoutable]; }
  34. set { base[ConfigurationStrings.PacketRoutable] = value; }
  35. }
  36. public override void ApplyConfiguration(BindingElement bindingElement)
  37. {
  38. base.ApplyConfiguration(bindingElement);
  39. OneWayBindingElement oneWayBindingElement = (OneWayBindingElement)bindingElement;
  40. PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
  41. if (propertyInfo[ConfigurationStrings.ChannelPoolSettings].ValueOrigin != PropertyValueOrigin.Default)
  42. {
  43. #pragma warning suppress 56506 // [....], base.ApplyConfiguration() validates the argument
  44. this.ChannelPoolSettings.ApplyConfiguration(oneWayBindingElement.ChannelPoolSettings);
  45. }
  46. oneWayBindingElement.MaxAcceptedChannels = this.MaxAcceptedChannels;
  47. oneWayBindingElement.PacketRoutable = this.PacketRoutable;
  48. }
  49. public override void CopyFrom(ServiceModelExtensionElement from)
  50. {
  51. base.CopyFrom(from);
  52. OneWayElement source = (OneWayElement)from;
  53. #pragma warning suppress 56506 // [....], base.CopyFrom() validates the argument
  54. PropertyInformationCollection propertyInfo = source.ElementInformation.Properties;
  55. if (propertyInfo[ConfigurationStrings.ChannelPoolSettings].ValueOrigin != PropertyValueOrigin.Default)
  56. {
  57. this.ChannelPoolSettings.CopyFrom(source.ChannelPoolSettings);
  58. }
  59. this.MaxAcceptedChannels = source.MaxAcceptedChannels;
  60. this.PacketRoutable = source.PacketRoutable;
  61. }
  62. protected internal override void InitializeFrom(BindingElement bindingElement)
  63. {
  64. base.InitializeFrom(bindingElement);
  65. OneWayBindingElement source = (OneWayBindingElement)bindingElement;
  66. this.ChannelPoolSettings.InitializeFrom(source.ChannelPoolSettings);
  67. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxAcceptedChannels, source.MaxAcceptedChannels);
  68. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.PacketRoutable, source.PacketRoutable);
  69. }
  70. protected internal override BindingElement CreateBindingElement()
  71. {
  72. OneWayBindingElement result = new OneWayBindingElement();
  73. this.ApplyConfiguration(result);
  74. return result;
  75. }
  76. }
  77. }