Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Configuration / TcpTransportElement.cs
1 //------------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------------------------
4
5 namespace System.ServiceModel.Configuration
6 {
7     using System.Configuration;
8     using System.Net.Sockets;
9     using System.ServiceModel.Channels;
10     using System.Security.Authentication.ExtendedProtection.Configuration;
11
12     public sealed partial class TcpTransportElement : ConnectionOrientedTransportElement
13     {
14         public TcpTransportElement() 
15             : base()
16         {
17         }
18
19         public override void ApplyConfiguration(BindingElement bindingElement)
20         {
21             base.ApplyConfiguration(bindingElement);
22 #pragma warning suppress 56506 // Microsoft, base.ApplyConfiguration() validates the argument
23             TcpTransportBindingElement binding = (TcpTransportBindingElement)bindingElement;
24             PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
25             if (this.ListenBacklog != TcpTransportDefaults.ListenBacklogConst)
26             {
27                 binding.ListenBacklog = this.ListenBacklog;                
28             }
29             binding.PortSharingEnabled = this.PortSharingEnabled;
30             binding.TeredoEnabled = this.TeredoEnabled;
31 #pragma warning suppress 56506 // Microsoft, base.ApplyConfiguration() validates the argument
32             this.ConnectionPoolSettings.ApplyConfiguration(binding.ConnectionPoolSettings);
33             binding.ExtendedProtectionPolicy = ChannelBindingUtility.BuildPolicy(this.ExtendedProtectionPolicy);
34         }
35
36         public override Type BindingElementType
37         {
38             get { return typeof(TcpTransportBindingElement); }
39         }
40
41         public override void CopyFrom(ServiceModelExtensionElement from)
42         {
43             base.CopyFrom(from);
44
45             TcpTransportElement source = (TcpTransportElement)from;
46 #pragma warning suppress 56506 // Microsoft, base.CopyFrom() validates the argument
47             this.ListenBacklog = source.ListenBacklog;
48             this.PortSharingEnabled = source.PortSharingEnabled;
49             this.TeredoEnabled = source.TeredoEnabled;
50             this.ConnectionPoolSettings.CopyFrom(source.ConnectionPoolSettings);
51             ChannelBindingUtility.CopyFrom(source.ExtendedProtectionPolicy, this.ExtendedProtectionPolicy);
52         }
53
54         protected override TransportBindingElement CreateDefaultBindingElement()
55         {
56             return new TcpTransportBindingElement();
57         }
58         
59         protected internal override void InitializeFrom(BindingElement bindingElement)
60         {
61             base.InitializeFrom(bindingElement);
62 #pragma warning suppress 56506 // Microsoft, base.CopyFrom() validates the argument
63             TcpTransportBindingElement binding = (TcpTransportBindingElement)bindingElement;
64             if (binding.IsListenBacklogSet)
65             {
66                 ConfigurationProperty listenBacklogProperty = this.Properties[ConfigurationStrings.ListenBacklog];
67                 SetPropertyValue(listenBacklogProperty, binding.ListenBacklog, false /*ignore locks*/);
68             }
69             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.PortSharingEnabled, binding.PortSharingEnabled);
70             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.TeredoEnabled, binding.TeredoEnabled);
71             this.ConnectionPoolSettings.InitializeFrom(binding.ConnectionPoolSettings);
72             ChannelBindingUtility.InitializeFrom(binding.ExtendedProtectionPolicy, this.ExtendedProtectionPolicy);
73         }
74
75         [ConfigurationProperty(ConfigurationStrings.ListenBacklog, DefaultValue = TcpTransportDefaults.ListenBacklogConst)]
76         [IntegerValidator(MinValue = 0)]
77         public int ListenBacklog
78         {
79             get { return (int)base[ConfigurationStrings.ListenBacklog]; }
80             set { base[ConfigurationStrings.ListenBacklog] = value; }
81         }
82
83         [ConfigurationProperty(ConfigurationStrings.PortSharingEnabled, DefaultValue = TcpTransportDefaults.PortSharingEnabled)]
84         public bool PortSharingEnabled
85         {
86             get { return (bool)base[ConfigurationStrings.PortSharingEnabled]; }
87             set { base[ConfigurationStrings.PortSharingEnabled] = value; }
88         }
89
90         [ConfigurationProperty(ConfigurationStrings.TeredoEnabled, DefaultValue = TcpTransportDefaults.TeredoEnabled)]
91         public bool TeredoEnabled
92         {
93             get { return (bool)base[ConfigurationStrings.TeredoEnabled]; }
94             set { base[ConfigurationStrings.TeredoEnabled] = value; }
95         }
96
97         [ConfigurationProperty(ConfigurationStrings.ConnectionPoolSettings)]
98         public TcpConnectionPoolSettingsElement ConnectionPoolSettings
99         {
100             get { return (TcpConnectionPoolSettingsElement)base[ConfigurationStrings.ConnectionPoolSettings]; }
101             set { base[ConfigurationStrings.ConnectionPoolSettings] = value; }
102         }
103
104         [ConfigurationProperty(ConfigurationStrings.ExtendedProtectionPolicy)]
105         public ExtendedProtectionPolicyElement ExtendedProtectionPolicy
106         {
107             get { return (ExtendedProtectionPolicyElement)base[ConfigurationStrings.ExtendedProtectionPolicy]; }
108             private set { base[ConfigurationStrings.ExtendedProtectionPolicy] = value; }
109         }
110     }
111 }
112
113
114