1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4 
5 namespace System.ServiceModel.Channels
6 {
7     using System.ComponentModel;
8     using System.Runtime;
9     using System.ServiceModel;
10 
11     public class ChannelPoolSettings
12     {
13         TimeSpan idleTimeout;
14         TimeSpan leaseTimeout;
15         int maxOutboundChannelsPerEndpoint;
16 
ChannelPoolSettings()17         public ChannelPoolSettings()
18         {
19             this.idleTimeout = OneWayDefaults.IdleTimeout;
20             this.leaseTimeout = OneWayDefaults.LeaseTimeout;
21             this.maxOutboundChannelsPerEndpoint = OneWayDefaults.MaxOutboundChannelsPerEndpoint;
22         }
23 
ChannelPoolSettings(ChannelPoolSettings poolToBeCloned)24         ChannelPoolSettings(ChannelPoolSettings poolToBeCloned)
25         {
26             this.idleTimeout = poolToBeCloned.idleTimeout;
27             this.leaseTimeout = poolToBeCloned.leaseTimeout;
28             this.maxOutboundChannelsPerEndpoint = poolToBeCloned.maxOutboundChannelsPerEndpoint;
29         }
30 
31         [DefaultValue(typeof(TimeSpan), OneWayDefaults.IdleTimeoutString)]
32         public TimeSpan IdleTimeout
33         {
34             get
35             {
36                 return this.idleTimeout;
37             }
38 
39             set
40             {
41                 if (value < TimeSpan.Zero)
42                 {
43                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
44                         SR.GetString(SR.SFxTimeoutOutOfRange0)));
45                 }
46 
47                 if (TimeoutHelper.IsTooLarge(value))
48                 {
49                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
50                         SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
51                 }
52 
53                 this.idleTimeout = value;
54             }
55         }
56 
57         [DefaultValue(typeof(TimeSpan), OneWayDefaults.LeaseTimeoutString)]
58         public TimeSpan LeaseTimeout
59         {
60             get
61             {
62                 return leaseTimeout;
63             }
64             set
65             {
66                 if (value < TimeSpan.Zero)
67                 {
68                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
69                         SR.GetString(SR.SFxTimeoutOutOfRange0)));
70                 }
71 
72                 if (TimeoutHelper.IsTooLarge(value))
73                 {
74                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
75                         SR.GetString(SR.SFxTimeoutOutOfRangeTooBig)));
76                 }
77 
78                 this.leaseTimeout = value;
79             }
80         }
81 
82         [DefaultValue(OneWayDefaults.MaxOutboundChannelsPerEndpoint)]
83         public int MaxOutboundChannelsPerEndpoint
84         {
85             get
86             {
87                 return this.maxOutboundChannelsPerEndpoint;
88             }
89             set
90             {
91                 if (value <= 0)
92                 {
93                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value,
94                         SR.GetString(SR.ValueMustBePositive)));
95                 }
96 
97                 this.maxOutboundChannelsPerEndpoint = value;
98             }
99         }
100 
Clone()101         internal ChannelPoolSettings Clone()
102         {
103             return new ChannelPoolSettings(this);
104         }
105 
IsMatch(ChannelPoolSettings channelPoolSettings)106         internal bool IsMatch(ChannelPoolSettings channelPoolSettings)
107         {
108             if (channelPoolSettings == null)
109             {
110                 return false;
111             }
112 
113             if (this.idleTimeout != channelPoolSettings.idleTimeout)
114             {
115                 return false;
116             }
117 
118             if (this.leaseTimeout != channelPoolSettings.leaseTimeout)
119             {
120                 return false;
121             }
122 
123             if (this.maxOutboundChannelsPerEndpoint != channelPoolSettings.maxOutboundChannelsPerEndpoint)
124             {
125                 return false;
126             }
127 
128             return true;
129         }
130 
InternalShouldSerialize()131         internal bool InternalShouldSerialize()
132         {
133             return (this.maxOutboundChannelsPerEndpoint != OneWayDefaults.MaxOutboundChannelsPerEndpoint
134                     || this.idleTimeout != OneWayDefaults.IdleTimeout
135                     || this.leaseTimeout != OneWayDefaults.LeaseTimeout);
136         }
137     }
138 }
139