PeerTransportElement.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Net;
  7. using System.Configuration;
  8. using System.ServiceModel;
  9. using System.ServiceModel.Channels;
  10. [ObsoleteAttribute ("PeerChannel feature is obsolete and will be removed in the future.", false)]
  11. public partial class PeerTransportElement : BindingElementExtensionElement
  12. {
  13. public PeerTransportElement()
  14. {
  15. }
  16. public override Type BindingElementType
  17. {
  18. get { return typeof(PeerTransportBindingElement); }
  19. }
  20. [ConfigurationProperty(ConfigurationStrings.ListenIPAddress, DefaultValue = PeerTransportDefaults.ListenIPAddress)]
  21. [System.ComponentModel.TypeConverter(typeof(PeerTransportListenAddressConverter))]
  22. [PeerTransportListenAddressValidator()]
  23. public IPAddress ListenIPAddress
  24. {
  25. get { return (IPAddress)base[ConfigurationStrings.ListenIPAddress]; }
  26. set { base[ConfigurationStrings.ListenIPAddress] = value; }
  27. }
  28. [ConfigurationProperty(ConfigurationStrings.MaxBufferPoolSize, DefaultValue = TransportDefaults.MaxBufferPoolSize)]
  29. [LongValidator(MinValue = 1)]
  30. public long MaxBufferPoolSize
  31. {
  32. get { return (long)base[ConfigurationStrings.MaxBufferPoolSize]; }
  33. set { base[ConfigurationStrings.MaxBufferPoolSize] = value; }
  34. }
  35. [ConfigurationProperty(ConfigurationStrings.MaxReceivedMessageSize, DefaultValue = TransportDefaults.MaxReceivedMessageSize)]
  36. [LongValidator(MinValue = 1)]
  37. public long MaxReceivedMessageSize
  38. {
  39. get { return (long)base[ConfigurationStrings.MaxReceivedMessageSize]; }
  40. set { base[ConfigurationStrings.MaxReceivedMessageSize] = value; }
  41. }
  42. [ConfigurationProperty(ConfigurationStrings.Port, DefaultValue = PeerTransportDefaults.Port)]
  43. [IntegerValidator(MinValue = PeerTransportConstants.MinPort, MaxValue = PeerTransportConstants.MaxPort)]
  44. public int Port
  45. {
  46. get { return (int)base[ConfigurationStrings.Port]; }
  47. set { base[ConfigurationStrings.Port] = value; }
  48. }
  49. [ConfigurationProperty(ConfigurationStrings.Security)]
  50. public PeerSecurityElement Security
  51. {
  52. get { return (PeerSecurityElement)base[ConfigurationStrings.Security]; }
  53. }
  54. public override void ApplyConfiguration(BindingElement bindingElement)
  55. {
  56. base.ApplyConfiguration(bindingElement);
  57. PeerTransportBindingElement binding = (PeerTransportBindingElement)bindingElement;
  58. binding.ListenIPAddress = this.ListenIPAddress;
  59. binding.Port = this.Port;
  60. binding.MaxBufferPoolSize = this.MaxBufferPoolSize;
  61. binding.MaxReceivedMessageSize = this.MaxReceivedMessageSize;
  62. #pragma warning suppress 56506 //[....]; base.ApplyConfiguration() checks for 'binding' being null
  63. this.Security.ApplyConfiguration(binding.Security);
  64. }
  65. public override void CopyFrom(ServiceModelExtensionElement from)
  66. {
  67. base.CopyFrom(from);
  68. PeerTransportElement source = (PeerTransportElement)from;
  69. #pragma warning suppress 56506 // [....], base.CopyFrom() validates the argument
  70. this.ListenIPAddress = source.ListenIPAddress;
  71. this.Port = source.Port;
  72. this.MaxBufferPoolSize = source.MaxBufferPoolSize;
  73. this.MaxReceivedMessageSize = source.MaxReceivedMessageSize;
  74. this.Security.CopyFrom(source.Security);
  75. }
  76. protected internal override BindingElement CreateBindingElement()
  77. {
  78. PeerTransportBindingElement binding = new PeerTransportBindingElement();
  79. this.ApplyConfiguration(binding);
  80. return binding;
  81. }
  82. protected internal override void InitializeFrom(BindingElement bindingElement)
  83. {
  84. base.InitializeFrom(bindingElement);
  85. PeerTransportBindingElement binding = (PeerTransportBindingElement)bindingElement;
  86. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ListenIPAddress, binding.ListenIPAddress);
  87. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Port, binding.Port);
  88. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBufferPoolSize, binding.MaxBufferPoolSize);
  89. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxReceivedMessageSize, binding.MaxReceivedMessageSize);
  90. this.Security.InitializeFrom(binding.Security);
  91. }
  92. }
  93. }