Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Configuration / OneWayElement.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.ServiceModel.Channels;
9     using System.ServiceModel;
10
11     public sealed partial class OneWayElement : BindingElementExtensionElement
12     {
13         public OneWayElement() 
14         {
15         }
16
17         public override Type BindingElementType
18         {
19             get { return typeof(OneWayBindingElement); }
20         }
21
22         [ConfigurationProperty(ConfigurationStrings.ChannelPoolSettings)]
23         public ChannelPoolSettingsElement ChannelPoolSettings
24         {
25             get { return (ChannelPoolSettingsElement)base[ConfigurationStrings.ChannelPoolSettings]; }
26         }
27
28         [ConfigurationProperty(ConfigurationStrings.MaxAcceptedChannels, DefaultValue = OneWayDefaults.MaxAcceptedChannels)]
29         [IntegerValidator(MinValue = 1)]
30         public int MaxAcceptedChannels
31         {
32             get { return (int)base[ConfigurationStrings.MaxAcceptedChannels]; }
33             set { base[ConfigurationStrings.MaxAcceptedChannels] = value; }
34         }
35
36         [ConfigurationProperty(ConfigurationStrings.PacketRoutable, DefaultValue = OneWayDefaults.PacketRoutable)]
37         public bool PacketRoutable
38         {
39             get { return (bool)base[ConfigurationStrings.PacketRoutable]; }
40             set { base[ConfigurationStrings.PacketRoutable] = value; }
41         }
42         
43         public override void ApplyConfiguration(BindingElement bindingElement)
44         {
45             base.ApplyConfiguration(bindingElement);
46             OneWayBindingElement oneWayBindingElement = (OneWayBindingElement)bindingElement;
47             PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
48             if (propertyInfo[ConfigurationStrings.ChannelPoolSettings].ValueOrigin != PropertyValueOrigin.Default)
49             {
50 #pragma warning suppress 56506 // Microsoft, base.ApplyConfiguration() validates the argument
51                 this.ChannelPoolSettings.ApplyConfiguration(oneWayBindingElement.ChannelPoolSettings);
52             }
53             oneWayBindingElement.MaxAcceptedChannels = this.MaxAcceptedChannels;
54             oneWayBindingElement.PacketRoutable = this.PacketRoutable;
55         }
56
57         public override void CopyFrom(ServiceModelExtensionElement from)
58         {
59             base.CopyFrom(from);
60
61             OneWayElement source = (OneWayElement)from;
62 #pragma warning suppress 56506 // Microsoft, base.CopyFrom() validates the argument
63             PropertyInformationCollection propertyInfo = source.ElementInformation.Properties;
64             if (propertyInfo[ConfigurationStrings.ChannelPoolSettings].ValueOrigin != PropertyValueOrigin.Default)
65             {
66                 this.ChannelPoolSettings.CopyFrom(source.ChannelPoolSettings);
67             }
68             this.MaxAcceptedChannels = source.MaxAcceptedChannels;
69             this.PacketRoutable = source.PacketRoutable;
70         }
71
72         protected internal override void InitializeFrom(BindingElement bindingElement)
73         {
74             base.InitializeFrom(bindingElement);
75             OneWayBindingElement source = (OneWayBindingElement)bindingElement;
76             this.ChannelPoolSettings.InitializeFrom(source.ChannelPoolSettings);
77             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxAcceptedChannels, source.MaxAcceptedChannels);
78             SetPropertyValueIfNotDefaultValue(ConfigurationStrings.PacketRoutable, source.PacketRoutable);
79         }
80
81         protected internal override BindingElement CreateBindingElement()
82         {
83             OneWayBindingElement result = new OneWayBindingElement();
84             this.ApplyConfiguration(result);
85             return result;
86         }
87     }
88 }
89
90
91