XmlDictionaryReaderQuotasElement.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------------------------
  4. namespace System.ServiceModel.Configuration
  5. {
  6. using System.Configuration;
  7. using System.Globalization;
  8. using System.Net;
  9. using System.Xml;
  10. using System.ServiceModel;
  11. using System.ComponentModel;
  12. using System.ServiceModel.Channels;
  13. public sealed partial class XmlDictionaryReaderQuotasElement : ServiceModelConfigurationElement
  14. {
  15. // for all properties, a value of 0 means "just use the default"
  16. [ConfigurationProperty(ConfigurationStrings.MaxDepth, DefaultValue = 0)]
  17. [IntegerValidator(MinValue = 0)]
  18. public int MaxDepth
  19. {
  20. get { return (int)base[ConfigurationStrings.MaxDepth]; }
  21. set { base[ConfigurationStrings.MaxDepth] = value; }
  22. }
  23. [ConfigurationProperty(ConfigurationStrings.MaxStringContentLength, DefaultValue = 0)]
  24. [IntegerValidator(MinValue = 0)]
  25. public int MaxStringContentLength
  26. {
  27. get { return (int)base[ConfigurationStrings.MaxStringContentLength]; }
  28. set { base[ConfigurationStrings.MaxStringContentLength] = value; }
  29. }
  30. [ConfigurationProperty(ConfigurationStrings.MaxArrayLength, DefaultValue = 0)]
  31. [IntegerValidator(MinValue = 0)]
  32. public int MaxArrayLength
  33. {
  34. get { return (int)base[ConfigurationStrings.MaxArrayLength]; }
  35. set { base[ConfigurationStrings.MaxArrayLength] = value; }
  36. }
  37. [ConfigurationProperty(ConfigurationStrings.MaxBytesPerRead, DefaultValue = 0)]
  38. [IntegerValidator(MinValue = 0)]
  39. public int MaxBytesPerRead
  40. {
  41. get { return (int)base[ConfigurationStrings.MaxBytesPerRead]; }
  42. set { base[ConfigurationStrings.MaxBytesPerRead] = value; }
  43. }
  44. [ConfigurationProperty(ConfigurationStrings.MaxNameTableCharCount, DefaultValue = 0)]
  45. [IntegerValidator(MinValue = 0)]
  46. public int MaxNameTableCharCount
  47. {
  48. get { return (int)base[ConfigurationStrings.MaxNameTableCharCount]; }
  49. set { base[ConfigurationStrings.MaxNameTableCharCount] = value; }
  50. }
  51. internal void ApplyConfiguration(XmlDictionaryReaderQuotas readerQuotas)
  52. {
  53. if (readerQuotas == null)
  54. {
  55. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("readerQuotas");
  56. }
  57. if (this.MaxDepth != 0)
  58. {
  59. readerQuotas.MaxDepth = this.MaxDepth;
  60. }
  61. if (this.MaxStringContentLength != 0)
  62. {
  63. readerQuotas.MaxStringContentLength = this.MaxStringContentLength;
  64. }
  65. if (this.MaxArrayLength != 0)
  66. {
  67. readerQuotas.MaxArrayLength = this.MaxArrayLength;
  68. }
  69. if (this.MaxBytesPerRead != 0)
  70. {
  71. readerQuotas.MaxBytesPerRead = this.MaxBytesPerRead;
  72. }
  73. if (this.MaxNameTableCharCount != 0)
  74. {
  75. readerQuotas.MaxNameTableCharCount = this.MaxNameTableCharCount;
  76. }
  77. }
  78. internal void InitializeFrom(XmlDictionaryReaderQuotas readerQuotas)
  79. {
  80. if (readerQuotas == null)
  81. {
  82. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("readerQuotas");
  83. }
  84. if (readerQuotas.MaxDepth != EncoderDefaults.MaxDepth)
  85. {
  86. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxDepth, readerQuotas.MaxDepth);
  87. }
  88. if (readerQuotas.MaxStringContentLength != EncoderDefaults.MaxStringContentLength)
  89. {
  90. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxStringContentLength, readerQuotas.MaxStringContentLength);
  91. }
  92. if (readerQuotas.MaxArrayLength != EncoderDefaults.MaxArrayLength)
  93. {
  94. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxArrayLength, readerQuotas.MaxArrayLength);
  95. }
  96. if (readerQuotas.MaxBytesPerRead != EncoderDefaults.MaxBytesPerRead)
  97. {
  98. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxBytesPerRead, readerQuotas.MaxBytesPerRead);
  99. }
  100. if (readerQuotas.MaxNameTableCharCount != EncoderDefaults.MaxNameTableCharCount)
  101. {
  102. SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MaxNameTableCharCount, readerQuotas.MaxNameTableCharCount);
  103. }
  104. }
  105. }
  106. }