Example #1
0
        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
        {
            string str;
            string str2;

            this._typeConfigHost = typeConfigHost;
            this._hostInitConfigurationParams = hostInitConfigurationParams;
            this._configRoot = new InternalConfigRoot(this);
            IInternalConfigHost host  = (IInternalConfigHost)System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);
            IInternalConfigHost host2 = new UpdateConfigHost(host);

            ((IInternalConfigRoot)this._configRoot).Init(host2, true);
            host.InitForConfiguration(ref locationSubPath, out str, out str2, this._configRoot, hostInitConfigurationParams);
            if (!string.IsNullOrEmpty(locationSubPath) && !host2.SupportsLocation)
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }
            if (string.IsNullOrEmpty(locationSubPath) != string.IsNullOrEmpty(str2))
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }
            this._configRecord = (MgmtConfigurationRecord)this._configRoot.GetConfigRecord(str);
            if (!string.IsNullOrEmpty(locationSubPath))
            {
                this._configRecord = MgmtConfigurationRecord.Create(this._configRoot, this._configRecord, str2, locationSubPath);
            }
            this._configRecord.ThrowIfInitErrors();
        }
        public IInternalConfigRecord GetConfigRecord(string configPath)
        {
            IInternalConfigRecord record4;

            if (!ConfigPathUtility.IsValid(configPath))
            {
                throw ExceptionUtil.ParameterInvalid("configPath");
            }
            string[] parts = ConfigPathUtility.GetParts(configPath);
            try
            {
                int num;
                BaseConfigurationRecord record;
                this.AcquireHierarchyLockForRead();
                this.hlFindConfigRecord(parts, out num, out record);
                if ((num == parts.Length) || !record.hlNeedsChildFor(parts[num]))
                {
                    return(record);
                }
            }
            finally
            {
                this.ReleaseHierarchyLockForRead();
            }
            try
            {
                int num2;
                BaseConfigurationRecord record2;
                this.AcquireHierarchyLockForWrite();
                this.hlFindConfigRecord(parts, out num2, out record2);
                if (num2 == parts.Length)
                {
                    return(record2);
                }
                string parentConfigPath = string.Join("/", parts, 0, num2);
                while ((num2 < parts.Length) && record2.hlNeedsChildFor(parts[num2]))
                {
                    BaseConfigurationRecord record3;
                    string childConfigPath = parts[num2];
                    parentConfigPath = ConfigPathUtility.Combine(parentConfigPath, childConfigPath);
                    if (this._isDesignTime)
                    {
                        record3 = MgmtConfigurationRecord.Create(this, record2, parentConfigPath, null);
                    }
                    else
                    {
                        record3 = (BaseConfigurationRecord)RuntimeConfigurationRecord.Create(this, record2, parentConfigPath);
                    }
                    record2.hlAddChild(childConfigPath, record3);
                    num2++;
                    record2 = record3;
                }
                record4 = record2;
            }
            finally
            {
                this.ReleaseHierarchyLockForWrite();
            }
            return(record4);
        }
Example #3
0
        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
        {
            _typeConfigHost = typeConfigHost;
            _hostInitConfigurationParams = hostInitConfigurationParams;

            IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstance(typeConfigHost);

            // Wrap the host with the UpdateConfigHost to support SaveAs.
            UpdateConfigHost updateConfigHost = new UpdateConfigHost(configHost);

            // Now wrap in ImplicitMachineConfigHost so we can stub in a simple machine.config if needed.
            IInternalConfigHost implicitMachineConfigHost = new ImplicitMachineConfigHost(updateConfigHost);

            InternalConfigRoot configRoot = new InternalConfigRoot(this, updateConfigHost);

            ((IInternalConfigRoot)configRoot).Init(implicitMachineConfigHost, isDesignTime: true);

            // Set the configuration paths for this Configuration.
            //
            // We do this in a separate step so that the WebConfigurationHost
            // can use this object's _configRoot to get the <sites> section,
            // which is used in it's MapPath implementation.
            string configPath, locationConfigPath;

            implicitMachineConfigHost.InitForConfiguration(
                ref locationSubPath,
                out configPath,
                out locationConfigPath,
                configRoot,
                hostInitConfigurationParams);

            if (!string.IsNullOrEmpty(locationSubPath) && !implicitMachineConfigHost.SupportsLocation)
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            if (string.IsNullOrEmpty(locationSubPath) != string.IsNullOrEmpty(locationConfigPath))
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            // Get the configuration record for this config file.
            _configRecord = (MgmtConfigurationRecord)configRoot.GetConfigRecord(configPath);

            // Create another MgmtConfigurationRecord for the location that is a child of the above record.
            // Note that this does not match the resolution hiearchy that is used at runtime.
            if (!string.IsNullOrEmpty(locationSubPath))
            {
                _configRecord = MgmtConfigurationRecord.Create(
                    configRoot, _configRecord, locationConfigPath, locationSubPath);
            }

            // Throw if the config record we created contains global errors.
            _configRecord.ThrowIfInitErrors();
        }
Example #4
0
 internal void DetachFromConfigurationRecord()
 {
     if (this._configSections != null)
     {
         this._configSections.DetachFromConfigurationRecord();
     }
     if (this._configSectionGroups != null)
     {
         this._configSectionGroups.DetachFromConfigurationRecord();
     }
     this._configRecord = null;
 }
        private ContextInformation _evalContext;                        // evaluation context

        internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams)
        {
            _typeConfigHost = typeConfigHost;
            _hostInitConfigurationParams = hostInitConfigurationParams;

            _configRoot = new InternalConfigRoot();

            IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost);

            // Wrap the host with the UpdateConfigHost to support SaveAs.
            IInternalConfigHost updateConfigHost = new UpdateConfigHost(configHost);

            _configRoot.Init(updateConfigHost, true);

            //
            // Set the configuration paths for this Configuration.
            // We do this in a separate step so that the WebConfigurationHost
            // can use this object's _configRoot to get the <sites> section,
            // which is used in it's MapPath implementation.
            //
            string configPath, locationConfigPath;

            configHost.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, _configRoot, hostInitConfigurationParams);

            if (!String.IsNullOrEmpty(locationSubPath) && !updateConfigHost.SupportsLocation)
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            if (String.IsNullOrEmpty(locationSubPath) != String.IsNullOrEmpty(locationConfigPath))
            {
                throw ExceptionUtil.UnexpectedError("Configuration::ctor");
            }

            // Get the configuration record for this config file.
            _configRecord = (MgmtConfigurationRecord)_configRoot.GetConfigRecord(configPath);

            //
            // Create another MgmtConfigurationRecord for the location that is a child of the above record.
            // Note that this does not match the resolution hiearchy that is used at runtime.
            //
            if (!String.IsNullOrEmpty(locationSubPath))
            {
                _configRecord = MgmtConfigurationRecord.Create(
                    _configRoot, _configRecord, locationConfigPath, locationSubPath);
            }

            //
            // Throw if the config record we created contains global errors.
            //
            _configRecord.ThrowIfInitErrors();
        }
 internal ConfigurationSectionGroupCollection(MgmtConfigurationRecord configRecord, ConfigurationSectionGroup configSectionGroup) : base(StringComparer.Ordinal)
 {
     this._configRecord       = configRecord;
     this._configSectionGroup = configSectionGroup;
     foreach (DictionaryEntry entry in this._configRecord.SectionGroupFactories)
     {
         FactoryId id = (FactoryId)entry.Value;
         if (id.Group == this._configSectionGroup.SectionGroupName)
         {
             base.BaseAdd(id.Name, id.Name);
         }
     }
 }
 void IInternalConfigRoot.Init(IInternalConfigHost host, bool isDesignTime)
 {
     this._host          = host;
     this._isDesignTime  = isDesignTime;
     this._hierarchyLock = new ReaderWriterLock();
     if (this._isDesignTime)
     {
         this._rootConfigRecord = MgmtConfigurationRecord.Create(this, null, string.Empty, null);
     }
     else
     {
         this._rootConfigRecord = (BaseConfigurationRecord)RuntimeConfigurationRecord.Create(this, null, string.Empty);
     }
 }
Example #8
0
        //
        // Create the collection of all sections in the section group.
        //
        internal ConfigurationSectionCollection(MgmtConfigurationRecord configRecord, ConfigurationSectionGroup configSectionGroup) :
            base(StringComparer.Ordinal)
        {
            _configRecord       = configRecord;
            _configSectionGroup = configSectionGroup;

            foreach (DictionaryEntry de in _configRecord.SectionFactories)
            {
                FactoryId factoryId = (FactoryId)de.Value;
                if (factoryId.Group == _configSectionGroup.SectionGroupName)
                {
                    BaseAdd(factoryId.Name, factoryId.Name);
                }
            }
        }
Example #9
0
        void IInternalConfigRoot.Init(IInternalConfigHost host, bool isDesignTime)
        {
            _host          = host;
            _isDesignTime  = isDesignTime;
            _hierarchyLock = new ReaderWriterLock();

            // Dummy record to hold _children for root
            if (_isDesignTime)
            {
                _rootConfigRecord = MgmtConfigurationRecord.Create(this, null, string.Empty, null);
            }
            else
            {
                _rootConfigRecord = (BaseConfigurationRecord)RuntimeConfigurationRecord.Create(this, null, string.Empty);
            }
        }
Example #10
0
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     this._configRecord = configRecord;
     this._configKey    = factoryRecord.ConfigKey;
     this._group        = factoryRecord.Group;
     this._name         = factoryRecord.Name;
     this._typeName     = factoryRecord.FactoryTypeName;
     if (this._typeName != null)
     {
         FactoryRecord record = null;
         if (!configRecord.Parent.IsRootConfig)
         {
             record = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
         }
         this._declarationRequired = (record == null) || (record.FactoryTypeName == null);
         this._declared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
     }
 }
Example #11
0
        internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord)
        {
            _configRecord    = configRecord;
            SectionGroupName = factoryRecord.ConfigKey;
            Name             = factoryRecord.Name;
            _typeName        = factoryRecord.FactoryTypeName;

            if (_typeName != null)
            {
                FactoryRecord parentFactoryRecord = null;
                if (!configRecord.Parent.IsRootConfig)
                {
                    parentFactoryRecord = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
                }

                IsDeclarationRequired = parentFactoryRecord?.FactoryTypeName == null;
                IsDeclared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
            }
        }
        internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord)
        {
            _configRecord = configRecord;
            _configKey    = factoryRecord.ConfigKey;
            _group        = factoryRecord.Group;
            _name         = factoryRecord.Name;
            _typeName     = factoryRecord.FactoryTypeName;

            if (_typeName != null)
            {
                FactoryRecord parentFactoryRecord = null;
                if (!configRecord.Parent.IsRootConfig)
                {
                    parentFactoryRecord = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
                }

                _declarationRequired = (parentFactoryRecord == null || parentFactoryRecord.FactoryTypeName == null);
                _declared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
            }
        }
 internal void DetachFromConfigurationRecord()
 {
     this._configRecord = null;
     base.BaseClear();
 }
Example #14
0
 internal void DetachFromConfigurationRecord()
 {
     _configSections?.DetachFromConfigurationRecord();
     _configSectionGroups?.DetachFromConfigurationRecord();
     _configRecord = null;
 }
 // Remove the collection from configuration system, and remove all entries
 // in the base collection so that enumeration will return an empty collection.
 internal void DetachFromConfigurationRecord()
 {
     _configRecord = null;
     BaseClear();
 }
Example #16
0
        //
        // Get the config record for a path.
        // If the record does not exist, create it if it is needed.
        //
        public IInternalConfigRecord GetConfigRecord(string configPath)
        {
            if (!ConfigPathUtility.IsValid(configPath))
            {
                throw ExceptionUtil.ParameterInvalid("configPath");
            }

            string[] parts = ConfigPathUtility.GetParts(configPath);

            //
            // First search under the reader lock, so that multiple searches
            // can proceed in parallel.
            //
            try {
                int index;
                BaseConfigurationRecord currentRecord;

                AcquireHierarchyLockForRead();

                hlFindConfigRecord(parts, out index, out currentRecord);

                // check if found
                if (index == parts.Length || !currentRecord.hlNeedsChildFor(parts[index]))
                {
                    return(currentRecord);
                }
            }
            finally {
                ReleaseHierarchyLockForRead();
            }

            //
            // Not found, so search again under exclusive writer lock so that
            // we can create the record.
            //
            try {
                int index;
                BaseConfigurationRecord currentRecord;

                AcquireHierarchyLockForWrite();

                hlFindConfigRecord(parts, out index, out currentRecord);

                if (index == parts.Length)
                {
                    return(currentRecord);
                }

                string currentConfigPath = String.Join(BaseConfigurationRecord.ConfigPathSeparatorString, parts, 0, index);

                //
                // create new records
                //

                while (index < parts.Length && currentRecord.hlNeedsChildFor(parts[index]))
                {
                    string configName = parts[index];
                    currentConfigPath = ConfigPathUtility.Combine(currentConfigPath, configName);
                    BaseConfigurationRecord childRecord;

                    Debug.Trace("ConfigurationCreate", "Creating config record for " + currentConfigPath);
                    if (_isDesignTime)
                    {
                        childRecord = MgmtConfigurationRecord.Create(this, currentRecord, currentConfigPath, null);
                    }
                    else
                    {
                        childRecord = (BaseConfigurationRecord)RuntimeConfigurationRecord.Create(this, currentRecord, currentConfigPath);
                    }

                    currentRecord.hlAddChild(configName, childRecord);

                    index++;
                    currentRecord = childRecord;
                }

                return(currentRecord);
            }
            finally {
                ReleaseHierarchyLockForWrite();
            }
        }
Example #17
0
 internal void DetachFromConfigurationRecord()
 {
     RevertToParent();
     _flags[FlagAttached] = false;
     _configRecord        = null;
 }
Example #18
0
 internal void DetachFromConfigurationRecord()
 {
     this.RevertToParent();
     this._flags[1]     = false;
     this._configRecord = null;
 }
Example #19
0
 internal void RootAttachToConfigurationRecord(MgmtConfigurationRecord configRecord)
 {
     this._configRecord = configRecord;
     this._isRoot       = true;
 }
Example #20
0
 // for instantiation of a ConfigurationSection from GetConfig
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord,
                                           SectionRecord sectionRecord)
 {
     SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
     _configRecord = configRecord;
 }