ServiceThrottlingElement.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Configuration;
  7. using System.ServiceModel.Dispatcher;
  8. using System.ServiceModel.Description;
  9. using System.ServiceModel;
  10. public sealed partial class ServiceThrottlingElement : BehaviorExtensionElement
  11. {
  12. public ServiceThrottlingElement()
  13. {
  14. }
  15. [ConfigurationProperty(ConfigurationStrings.MaxConcurrentCalls, DefaultValue = ServiceThrottle.DefaultMaxConcurrentCalls)]
  16. [IntegerValidator(MinValue = 1)]
  17. public int MaxConcurrentCalls
  18. {
  19. get { return (int)base[ConfigurationStrings.MaxConcurrentCalls]; }
  20. set { base[ConfigurationStrings.MaxConcurrentCalls] = value; }
  21. }
  22. [ConfigurationProperty(ConfigurationStrings.MaxConcurrentSessions, DefaultValue = ServiceThrottle.DefaultMaxConcurrentSessions)]
  23. [IntegerValidator(MinValue = 1)]
  24. public int MaxConcurrentSessions
  25. {
  26. get { return (int)base[ConfigurationStrings.MaxConcurrentSessions]; }
  27. set { base[ConfigurationStrings.MaxConcurrentSessions] = value; }
  28. }
  29. [ConfigurationProperty(ConfigurationStrings.MaxConcurrentInstances, DefaultValue = ServiceThrottle.DefaultMaxConcurrentCalls + ServiceThrottle.DefaultMaxConcurrentSessions)]
  30. [IntegerValidator(MinValue = 1)]
  31. public int MaxConcurrentInstances
  32. {
  33. get { return (int)base[ConfigurationStrings.MaxConcurrentInstances]; }
  34. set { base[ConfigurationStrings.MaxConcurrentInstances] = value; }
  35. }
  36. public override void CopyFrom(ServiceModelExtensionElement from)
  37. {
  38. base.CopyFrom(from);
  39. ServiceThrottlingElement source = (ServiceThrottlingElement)from;
  40. #pragma warning suppress 56506 //[....]; base.CopyFrom() checks for 'from' being null
  41. this.MaxConcurrentCalls = source.MaxConcurrentCalls;
  42. this.MaxConcurrentSessions = source.MaxConcurrentSessions;
  43. this.MaxConcurrentInstances = source.MaxConcurrentInstances;
  44. }
  45. protected internal override object CreateBehavior()
  46. {
  47. ServiceThrottlingBehavior behavior = new ServiceThrottlingBehavior();
  48. PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;
  49. if (propertyInfo[ConfigurationStrings.MaxConcurrentCalls].ValueOrigin != PropertyValueOrigin.Default)
  50. {
  51. behavior.MaxConcurrentCalls = this.MaxConcurrentCalls;
  52. }
  53. if (propertyInfo[ConfigurationStrings.MaxConcurrentSessions].ValueOrigin != PropertyValueOrigin.Default)
  54. {
  55. behavior.MaxConcurrentSessions = this.MaxConcurrentSessions;
  56. }
  57. if (propertyInfo[ConfigurationStrings.MaxConcurrentInstances].ValueOrigin != PropertyValueOrigin.Default)
  58. {
  59. behavior.MaxConcurrentInstances = this.MaxConcurrentInstances;
  60. }
  61. return behavior;
  62. }
  63. public override Type BehaviorType
  64. {
  65. get { return typeof(ServiceThrottlingBehavior); }
  66. }
  67. }
  68. }