BinaryMessageEncodingElement.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. public sealed partial class BinaryMessageEncodingElement : BindingElementExtensionElement
  9. {
  10. public BinaryMessageEncodingElement()
  11. {
  12. }
  13. public override Type BindingElementType
  14. {
  15. get { return typeof(BinaryMessageEncodingBindingElement); }
  16. }
  17. [ConfigurationProperty(ConfigurationStrings.MaxReadPoolSize, DefaultValue = EncoderDefaults.MaxReadPoolSize)]
  18. [IntegerValidator(MinValue = 1)]
  19. public int MaxReadPoolSize
  20. {
  21. get { return (int)base[ConfigurationStrings.MaxReadPoolSize]; }
  22. set { base[ConfigurationStrings.MaxReadPoolSize] = value; }
  23. }
  24. [ConfigurationProperty(ConfigurationStrings.MaxWritePoolSize, DefaultValue = EncoderDefaults.MaxWritePoolSize)]
  25. [IntegerValidator(MinValue = 1)]
  26. public int MaxWritePoolSize
  27. {
  28. get { return (int)base[ConfigurationStrings.MaxWritePoolSize]; }
  29. set { base[ConfigurationStrings.MaxWritePoolSize] = value; }
  30. }
  31. [ConfigurationProperty(ConfigurationStrings.MaxSessionSize, DefaultValue = BinaryEncoderDefaults.MaxSessionSize)]
  32. [IntegerValidator(MinValue = 0)]
  33. public int MaxSessionSize
  34. {
  35. get { return (int)base[ConfigurationStrings.MaxSessionSize]; }
  36. set { base[ConfigurationStrings.MaxSessionSize] = value; }
  37. }
  38. [ConfigurationProperty(ConfigurationStrings.ReaderQuotas)]
  39. public XmlDictionaryReaderQuotasElement ReaderQuotas
  40. {
  41. get { return (XmlDictionaryReaderQuotasElement) base[ConfigurationStrings.ReaderQuotas]; }
  42. }
  43. [ConfigurationProperty(ConfigurationStrings.CompressionFormat, DefaultValue = EncoderDefaults.DefaultCompressionFormat)]
  44. [ServiceModelEnumValidator(typeof(CompressionFormatHelper))]
  45. public CompressionFormat CompressionFormat
  46. {
  47. get { return (CompressionFormat)base[ConfigurationStrings.CompressionFormat]; }
  48. set { base[ConfigurationStrings.CompressionFormat] = value; }
  49. }
  50. public override void ApplyConfiguration(BindingElement bindingElement)
  51. {
  52. base.ApplyConfiguration(bindingElement);
  53. BinaryMessageEncodingBindingElement binding = (BinaryMessageEncodingBindingElement)bindingElement;
  54. binding.MaxSessionSize = this.MaxSessionSize;
  55. binding.MaxReadPoolSize = this.MaxReadPoolSize;
  56. binding.MaxWritePoolSize = this.MaxWritePoolSize;
  57. #pragma warning suppress 56506 //[....]; base.ApplyConfiguration() checks for 'binding' being null
  58. this.ReaderQuotas.ApplyConfiguration(binding.ReaderQuotas);
  59. binding.CompressionFormat = this.CompressionFormat;
  60. }
  61. public override void CopyFrom(ServiceModelExtensionElement from)
  62. {
  63. base.CopyFrom(from);
  64. BinaryMessageEncodingElement source = (BinaryMessageEncodingElement)from;
  65. #pragma warning suppress 56506 //[....]; base.CopyFrom() checks for 'from' being null
  66. this.MaxSessionSize = source.MaxSessionSize;
  67. this.MaxReadPoolSize = source.MaxReadPoolSize;
  68. this.MaxWritePoolSize = source.MaxWritePoolSize;
  69. this.CompressionFormat = source.CompressionFormat;
  70. }
  71. protected internal override void InitializeFrom(BindingElement bindingElement)
  72. {
  73. base.InitializeFrom(bindingElement);
  74. BinaryMessageEncodingBindingElement binding = (BinaryMessageEncodingBindingElement)bindingElement;
  75. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxSessionSize, binding.MaxSessionSize);
  76. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxReadPoolSize, binding.MaxReadPoolSize);
  77. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxWritePoolSize, binding.MaxWritePoolSize);
  78. this.ReaderQuotas.InitializeFrom(binding.ReaderQuotas);
  79. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.CompressionFormat, binding.CompressionFormat);
  80. }
  81. protected internal override BindingElement CreateBindingElement()
  82. {
  83. BinaryMessageEncodingBindingElement binding = new BinaryMessageEncodingBindingElement();
  84. this.ApplyConfiguration(binding);
  85. return binding;
  86. }
  87. }
  88. }