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);
        }
        private void RemoveConfigImpl(string configPath, BaseConfigurationRecord configRecord)
        {
            BaseConfigurationRecord record;

            if (!ConfigPathUtility.IsValid(configPath))
            {
                throw ExceptionUtil.ParameterInvalid("configPath");
            }
            string[] parts = ConfigPathUtility.GetParts(configPath);
            try
            {
                int num;
                this.AcquireHierarchyLockForWrite();
                this.hlFindConfigRecord(parts, out num, out record);
                if ((num != parts.Length) || ((configRecord != null) && !object.ReferenceEquals(configRecord, record)))
                {
                    return;
                }
                record.Parent.hlRemoveChild(parts[parts.Length - 1]);
            }
            finally
            {
                this.ReleaseHierarchyLockForWrite();
            }
            this.OnConfigRemoved(new InternalConfigEventArgs(configPath));
            record.CloseRecursive();
        }
 public void ClearResult(BaseConfigurationRecord configRecord, string configKey, bool forceEvaluation)
 {
     string[] parts = ConfigPathUtility.GetParts(configRecord.ConfigPath);
     try
     {
         int num;
         BaseConfigurationRecord record;
         this.AcquireHierarchyLockForRead();
         this.hlFindConfigRecord(parts, out num, out record);
         if ((num == parts.Length) && object.ReferenceEquals(configRecord, record))
         {
             record.hlClearResultRecursive(configKey, forceEvaluation);
         }
     }
     finally
     {
         this.ReleaseHierarchyLockForRead();
     }
 }
示例#4
0
        //
        // Clear the result of a configSection evaluation at a particular point
        // in the hierarchy.
        //
        public void ClearResult(BaseConfigurationRecord configRecord, string configKey, bool forceEvaluation)
        {
            string[] parts = ConfigPathUtility.GetParts(configRecord.ConfigPath);

            try {
                int index;
                BaseConfigurationRecord currentRecord;

                AcquireHierarchyLockForRead();

                hlFindConfigRecord(parts, out index, out currentRecord);

                // clear result only if configRecord it is still in the hierarchy
                if (index == parts.Length && Object.ReferenceEquals(configRecord, currentRecord))
                {
                    currentRecord.hlClearResultRecursive(configKey, forceEvaluation);
                }
            }
            finally {
                ReleaseHierarchyLockForRead();
            }
        }
示例#5
0
        // Find and remove the config record and all its children for the config path.
        // Optionally ensure the config record matches a desired config record.
        private void RemoveConfigImpl(string configPath, BaseConfigurationRecord configRecord)
        {
            if (!ConfigPathUtility.IsValid(configPath))
            {
                throw ExceptionUtil.ParameterInvalid("configPath");
            }

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

            BaseConfigurationRecord currentRecord;

            // search under exclusive writer lock
            try
            {
                int index;

                AcquireHierarchyLockForWrite();

                HlFindConfigRecord(parts, out index, out currentRecord);

                // Return if not found, or does not match the one we are trying to remove.
                if ((index != parts.Length) || ((configRecord != null) && !ReferenceEquals(configRecord, currentRecord)))
                {
                    return;
                }

                // Remove it from the hierarchy.
                currentRecord.Parent.HlRemoveChild(parts[parts.Length - 1]);
            }
            finally
            {
                ReleaseHierarchyLockForWrite();
            }

            OnConfigRemoved(new InternalConfigEventArgs(configPath));

            // Close the record. This is safe to do outside the lock.
            currentRecord.CloseRecursive();
        }
 public void GetParts(string configPath, string[] expected)
 {
     Assert.Equal(expected, ConfigPathUtility.GetParts(configPath));
 }
示例#7
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();
            }
        }