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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ConnectionManagementSection.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.Collections;
  19.     using System.Threading;
  20.     public sealed class ConnectionManagementSection : ConfigurationSection
  21.     {
  22.         public ConnectionManagementSection()
  23.         {
  24.             this.properties.Add(this.connectionManagement);
  25.         }
  26.        
  27.         [ConfigurationProperty("", IsDefaultCollection = true)]
  28.         public ConnectionManagementElementCollection ConnectionManagement {
  29.             get { return (ConnectionManagementElementCollection)this[this.connectionManagement]; }
  30.         }
  31.        
  32.         protected override ConfigurationPropertyCollection Properties {
  33.             get { return this.properties; }
  34.         }
  35.        
  36.         ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
  37.        
  38.         readonly ConfigurationProperty connectionManagement = new ConfigurationProperty(null, typeof(ConnectionManagementElementCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);
  39.     }
  40.    
  41.     internal sealed class ConnectionManagementSectionInternal
  42.     {
  43.         internal ConnectionManagementSectionInternal(ConnectionManagementSection section)
  44.         {
  45.             if (section.ConnectionManagement.Count > 0) {
  46.                 this.connectionManagement = new Hashtable(section.ConnectionManagement.Count);
  47.                 foreach (ConnectionManagementElement connectionManagementElement in section.ConnectionManagement) {
  48.                     this.connectionManagement[connectionManagementElement.Address] = connectionManagementElement.MaxConnection;
  49.                 }
  50.             }
  51.         }
  52.        
  53.         internal Hashtable ConnectionManagement {
  54.             get {
  55.                 Hashtable retval = this.connectionManagement;
  56.                 if (retval == null) {
  57.                     retval = new Hashtable();
  58.                 }
  59.                 return retval;
  60.             }
  61.         }
  62.        
  63.         static internal object ClassSyncObject {
  64.             get {
  65.                 if (classSyncObject == null) {
  66.                     object o = new object();
  67.                     Interlocked.CompareExchange(ref classSyncObject, o, null);
  68.                 }
  69.                 return classSyncObject;
  70.             }
  71.         }
  72.        
  73.         static internal ConnectionManagementSectionInternal GetSection()
  74.         {
  75.             lock (ConnectionManagementSectionInternal.ClassSyncObject) {
  76.                 ConnectionManagementSection section = PrivilegedConfigurationManager.GetSection(ConfigurationStrings.ConnectionManagementSectionPath) as ConnectionManagementSection;
  77.                 if (section == null)
  78.                     return null;
  79.                
  80.                 return new ConnectionManagementSectionInternal(section);
  81.             }
  82.         }
  83.        
  84.         Hashtable connectionManagement = null;
  85.         static object classSyncObject = null;
  86.     }
  87. }

Developer Fusion