The Labs \ Source Viewer \ SSCLI \ System.Net.Configuration \ SettingsSectionInternal

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SettingsSection.cs" company="Microsoft Corporation">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Net.Configuration
  16. {
  17.     using System.Configuration;
  18.     using System.Threading;
  19.    
  20.     public sealed class SettingsSection : ConfigurationSection
  21.     {
  22.        
  23.         // Placeholder for ChadMu to add code to load all configuration
  24.         // required in download scenarios.
  25.         static internal void EnsureConfigLoaded()
  26.         {
  27.             try {
  28.                 //AuthenticationModules section
  29.                 System.Net.AuthenticationManager.EnsureConfigLoaded();
  30.                 //Requestcachingsection section
  31.                 object o = System.Net.Cache.RequestCacheManager.IsCachingEnabled;
  32.                 //ConnectionManagement section
  33.                 o = System.Net.ServicePointManager.DefaultConnectionLimit;
  34.                 //Settings section
  35.                 o = System.Net.ServicePointManager.Expect100Continue;
  36.                 //webrequestmodules section
  37.                 o = System.Net.WebRequest.PrefixList;
  38.                 //DefaultProxy section
  39.                 o = System.Net.WebRequest.InternalDefaultWebProxy;
  40.             }
  41.             catch {
  42.             }
  43.         }
  44.        
  45.        
  46.         public SettingsSection()
  47.         {
  48.             this.properties.Add(this.httpWebRequest);
  49.             this.properties.Add(this.ipv6);
  50.             this.properties.Add(this.servicePointManager);
  51.             this.properties.Add(this.socket);
  52.             this.properties.Add(this.webProxyScript);
  53.             this.properties.Add(this.performanceCounters);
  54.         }
  55.        
  56.        
  57.         [ConfigurationProperty(ConfigurationStrings.HttpWebRequest)]
  58.         public HttpWebRequestElement HttpWebRequest {
  59.             get { return (HttpWebRequestElement)this[this.httpWebRequest]; }
  60.         }
  61.        
  62.         [ConfigurationProperty(ConfigurationStrings.Ipv6)]
  63.         public Ipv6Element Ipv6 {
  64.             get { return (Ipv6Element)this[this.ipv6]; }
  65.         }
  66.        
  67.         [ConfigurationProperty(ConfigurationStrings.ServicePointManager)]
  68.         public ServicePointManagerElement ServicePointManager {
  69.             get { return (ServicePointManagerElement)this[this.servicePointManager]; }
  70.         }
  71.        
  72.         [ConfigurationProperty(ConfigurationStrings.Socket)]
  73.         public SocketElement Socket {
  74.             get { return (SocketElement)this[this.socket]; }
  75.         }
  76.        
  77.         [ConfigurationProperty(ConfigurationStrings.WebProxyScript)]
  78.         public WebProxyScriptElement WebProxyScript {
  79.             get { return (WebProxyScriptElement)this[this.webProxyScript]; }
  80.         }
  81.        
  82.        
  83.         [ConfigurationProperty(ConfigurationStrings.PerformanceCounters)]
  84.         public PerformanceCountersElement PerformanceCounters {
  85.             get { return (PerformanceCountersElement)this[this.performanceCounters]; }
  86.         }
  87.        
  88.         protected override ConfigurationPropertyCollection Properties {
  89.             get { return this.properties; }
  90.         }
  91.        
  92.         ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
  93.        
  94.         readonly ConfigurationProperty httpWebRequest = new ConfigurationProperty(ConfigurationStrings.HttpWebRequest, typeof(HttpWebRequestElement), null, ConfigurationPropertyOptions.None);
  95.        
  96.         readonly ConfigurationProperty ipv6 = new ConfigurationProperty(ConfigurationStrings.Ipv6, typeof(Ipv6Element), null, ConfigurationPropertyOptions.None);
  97.        
  98.         readonly ConfigurationProperty servicePointManager = new ConfigurationProperty(ConfigurationStrings.ServicePointManager, typeof(ServicePointManagerElement), null, ConfigurationPropertyOptions.None);
  99.        
  100.         readonly ConfigurationProperty socket = new ConfigurationProperty(ConfigurationStrings.Socket, typeof(SocketElement), null, ConfigurationPropertyOptions.None);
  101.        
  102.         readonly ConfigurationProperty webProxyScript = new ConfigurationProperty(ConfigurationStrings.WebProxyScript, typeof(WebProxyScriptElement), null, ConfigurationPropertyOptions.None);
  103.        
  104.         readonly ConfigurationProperty performanceCounters = new ConfigurationProperty(ConfigurationStrings.PerformanceCounters, typeof(PerformanceCountersElement), null, ConfigurationPropertyOptions.None);
  105.     }
  106.    
  107.     internal sealed class SettingsSectionInternal
  108.     {
  109.         private static object s_InternalSyncObject = null;
  110.         internal SettingsSectionInternal(SettingsSection section)
  111.         {
  112.             TimeSpan ts;
  113.            
  114.             if (section == null)
  115.                 section = new SettingsSection();
  116.            
  117.             this.alwaysUseCompletionPortsForConnect = section.Socket.AlwaysUseCompletionPortsForConnect;
  118.             this.alwaysUseCompletionPortsForAccept = section.Socket.AlwaysUseCompletionPortsForAccept;
  119.             this.checkCertificateName = section.ServicePointManager.CheckCertificateName;
  120.             this.CheckCertificateRevocationList = section.ServicePointManager.CheckCertificateRevocationList;
  121.             this.DnsRefreshTimeout = section.ServicePointManager.DnsRefreshTimeout;
  122.             this.ipv6Enabled = section.Ipv6.Enabled;
  123.             this.EnableDnsRoundRobin = section.ServicePointManager.EnableDnsRoundRobin;
  124.             this.Expect100Continue = section.ServicePointManager.Expect100Continue;
  125.             this.maximumUnauthorizedUploadLength = section.HttpWebRequest.MaximumUnauthorizedUploadLength;
  126.             this.maximumResponseHeadersLength = section.HttpWebRequest.MaximumResponseHeadersLength;
  127.             this.maximumErrorResponseLength = section.HttpWebRequest.MaximumErrorResponseLength;
  128.             this.useUnsafeHeaderParsing = section.HttpWebRequest.UseUnsafeHeaderParsing;
  129.             this.UseNagleAlgorithm = section.ServicePointManager.UseNagleAlgorithm;
  130.             ts = section.WebProxyScript.DownloadTimeout;
  131.             this.downloadTimeout = (ts == TimeSpan.MaxValue || ts == TimeSpan.Zero) ? Timeout.Infinite : (int)ts.TotalMilliseconds;
  132.             /* Not used with Managed JScript
  133.             ts = section.WebProxyScript.ExecutionTimeout;
  134.             this.executionTimeout = (ts == TimeSpan.MaxValue || ts == TimeSpan.Zero) ? Timeout.Infinite : (int) ts.TotalMilliseconds;
  135. */           
  136. this.performanceCountersEnabled = section.PerformanceCounters.Enabled;
  137.         }
  138.        
  139.        
  140.         static internal SettingsSectionInternal Section {
  141.             get {
  142.                
  143.                 if (s_settings == null) {
  144.                     lock (InternalSyncObject) {
  145.                         if (s_settings == null) {
  146.                             s_settings = new SettingsSectionInternal((SettingsSection)PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SettingsSectionPath));
  147.                         }
  148.                     }
  149.                 }
  150.                 return s_settings;
  151.             }
  152.         }
  153.        
  154.        
  155.         private static object InternalSyncObject {
  156.             get {
  157.                 if (s_InternalSyncObject == null) {
  158.                     object o = new object();
  159.                     Interlocked.CompareExchange(ref s_InternalSyncObject, o, null);
  160.                 }
  161.                 return s_InternalSyncObject;
  162.             }
  163.         }
  164.        
  165.        
  166.         // This method is required - it gets called through reflection, matching all the other XxxSectionInternal classes.
  167.         // This one gets it fresh for each call. Generally it shouldn't be used.
  168.         static internal SettingsSectionInternal GetSection()
  169.         {
  170.             return new SettingsSectionInternal((SettingsSection)PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SettingsSectionPath));
  171.         }
  172.        
  173.        
  174.         internal bool AlwaysUseCompletionPortsForAccept {
  175.             get { return this.alwaysUseCompletionPortsForAccept; }
  176.         }
  177.        
  178.         internal bool AlwaysUseCompletionPortsForConnect {
  179.             get { return this.alwaysUseCompletionPortsForConnect; }
  180.         }
  181.        
  182.         internal bool CheckCertificateName {
  183.             get { return this.checkCertificateName; }
  184.         }
  185.        
  186.         internal bool CheckCertificateRevocationList {
  187.             get { return this.checkCertificateRevocationList; }
  188.             set { this.checkCertificateRevocationList = value; }
  189.         }
  190.        
  191.         internal int DnsRefreshTimeout {
  192.             get { return this.dnsRefreshTimeout; }
  193.             set { this.dnsRefreshTimeout = value; }
  194.         }
  195.        
  196.         internal int DownloadTimeout {
  197.             get { return this.downloadTimeout; }
  198.         }
  199.        
  200.         internal bool EnableDnsRoundRobin {
  201.             get { return this.enableDnsRoundRobin; }
  202.             set { this.enableDnsRoundRobin = value; }
  203.         }
  204.        
  205. /* Not used with Managed JScript
  206.         internal int ExecutionTimeout
  207.         {
  208.             get { return this.executionTimeout; }
  209.         }
  210. */       
  211.        
  212.         internal bool Expect100Continue {
  213.             get { return this.expect100Continue; }
  214.             set { this.expect100Continue = value; }
  215.         }
  216.        
  217.         internal bool Ipv6Enabled {
  218.             get { return this.ipv6Enabled; }
  219.         }
  220.        
  221.         internal int MaximumResponseHeadersLength {
  222.             get { return this.maximumResponseHeadersLength; }
  223.             set { this.maximumResponseHeadersLength = value; }
  224.         }
  225.        
  226.         internal int MaximumUnauthorizedUploadLength {
  227.             get { return this.maximumUnauthorizedUploadLength; }
  228.         }
  229. /*
  230.             //                                   
  231.             set { this.maximumUnauthorizedUploadLength = value; }
  232.             */       
  233.        
  234.         internal int MaximumErrorResponseLength {
  235.             get { return this.maximumErrorResponseLength; }
  236.             set { this.maximumErrorResponseLength = value; }
  237.         }
  238.        
  239.         internal bool UseUnsafeHeaderParsing {
  240.             get { return this.useUnsafeHeaderParsing; }
  241.         }
  242.        
  243.         internal bool UseNagleAlgorithm {
  244.             get { return this.useNagleAlgorithm; }
  245.             set { this.useNagleAlgorithm = value; }
  246.         }
  247.        
  248.         internal bool PerformanceCountersEnabled {
  249.             get { return this.performanceCountersEnabled; }
  250.         }
  251.        
  252.         private static SettingsSectionInternal s_settings;
  253.         bool alwaysUseCompletionPortsForAccept;
  254.         bool alwaysUseCompletionPortsForConnect;
  255.         bool checkCertificateName;
  256.         bool checkCertificateRevocationList;
  257.         int downloadTimeout;
  258.         int dnsRefreshTimeout;
  259.         bool enableDnsRoundRobin;
  260. /* Not used with Managed JScript
  261.         int executionTimeout;
  262. */       
  263.         bool expect100Continue;
  264.         bool ipv6Enabled;
  265.         int maximumResponseHeadersLength;
  266.         int maximumErrorResponseLength;
  267.         int maximumUnauthorizedUploadLength;
  268.         bool useUnsafeHeaderParsing;
  269.         bool useNagleAlgorithm;
  270.         bool performanceCountersEnabled;
  271.     }
  272. }

Developer Fusion