Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Configuration / ServiceThrottlingElement.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.Dispatcher;
9     using System.ServiceModel.Description;
10     using System.ServiceModel;
11
12     public sealed partial class ServiceThrottlingElement : BehaviorExtensionElement
13     {
14         public ServiceThrottlingElement()
15         {
16         }
17
18         [ConfigurationProperty(ConfigurationStrings.MaxConcurrentCalls, DefaultValue = ServiceThrottle.DefaultMaxConcurrentCalls)]
19         [IntegerValidator(MinValue = 1)]
20         public int MaxConcurrentCalls
21         {
22             get { return (int)base[ConfigurationStrings.MaxConcurrentCalls]; }
23             set { base[ConfigurationStrings.MaxConcurrentCalls] = value; }
24         }
25
26         [ConfigurationProperty(ConfigurationStrings.MaxConcurrentSessions, DefaultValue = ServiceThrottle.DefaultMaxConcurrentSessions)]
27         [IntegerValidator(MinValue = 1)]
28         public int MaxConcurrentSessions
29         {
30             get { return (int)base[ConfigurationStrings.MaxConcurrentSessions]; }
31             set { base[ConfigurationStrings.MaxConcurrentSessions] = value; }
32         }
33
34         [ConfigurationProperty(ConfigurationStrings.MaxConcurrentInstances, DefaultValue = ServiceThrottle.DefaultMaxConcurrentCalls + ServiceThrottle.DefaultMaxConcurrentSessions)]
35         [IntegerValidator(MinValue = 1)]
36         public int MaxConcurrentInstances
37         {
38             get { return (int)base[ConfigurationStrings.MaxConcurrentInstances]; }
39             set { base[ConfigurationStrings.MaxConcurrentInstances] = value; }
40         }
41
42         public override void CopyFrom(ServiceModelExtensionElement from)
43         {
44             base.CopyFrom(from);
45
46             ServiceThrottlingElement source = (ServiceThrottlingElement)from;
47 #pragma warning suppress 56506 //[....]; base.CopyFrom() checks for 'from' being null
48             this.MaxConcurrentCalls = source.MaxConcurrentCalls;
49             this.MaxConcurrentSessions = source.MaxConcurrentSessions;
50             this.MaxConcurrentInstances = source.MaxConcurrentInstances;
51         }
52
53         protected internal override object CreateBehavior()
54         {
55             ServiceThrottlingBehavior behavior = new ServiceThrottlingBehavior();
56
57             PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
58             if (propertyInfo[ConfigurationStrings.MaxConcurrentCalls].ValueOrigin != PropertyValueOrigin.Default)
59             {
60                 behavior.MaxConcurrentCalls = this.MaxConcurrentCalls;
61             }
62
63             if (propertyInfo[ConfigurationStrings.MaxConcurrentSessions].ValueOrigin != PropertyValueOrigin.Default)
64             {
65                 behavior.MaxConcurrentSessions = this.MaxConcurrentSessions;
66             }
67
68             if (propertyInfo[ConfigurationStrings.MaxConcurrentInstances].ValueOrigin != PropertyValueOrigin.Default)
69             {
70                 behavior.MaxConcurrentInstances = this.MaxConcurrentInstances;
71             }
72
73             return behavior;
74         }
75
76         public override Type BehaviorType
77         {
78             get { return typeof(ServiceThrottlingBehavior); }
79         }
80
81     }
82 }
83
84
85