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);
        }
 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);
     }
 }
示例#3
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);
            }
        }
示例#4
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();
            }
        }