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