System.Configuration.MgmtConfigurationRecord.UpdateRecords C# (CSharp) Method

UpdateRecords() private method

private UpdateRecords ( ) : void
return void
        private void UpdateRecords() {
            if (_factoryRecords != null) {
                foreach (FactoryRecord factoryRecord in _factoryRecords.Values) {
                    // Update stream information
                    if (String.IsNullOrEmpty(factoryRecord.Filename)) {
                        factoryRecord.Filename = ConfigStreamInfo.StreamName;
                    }

                    factoryRecord.LineNumber = 0;

                    ConfigurationSection configSection = GetConfigSection(factoryRecord.ConfigKey);
                    if (configSection != null) {
                        if (configSection.SectionInformation.Type != null) {
                            factoryRecord.FactoryTypeName = configSection.SectionInformation.Type;
                        }

                        factoryRecord.AllowLocation = configSection.SectionInformation.AllowLocation;
                        factoryRecord.RestartOnExternalChanges = configSection.SectionInformation.RestartOnExternalChanges;
                        factoryRecord.RequirePermission = configSection.SectionInformation.RequirePermission;
                        factoryRecord.AllowDefinition = configSection.SectionInformation.AllowDefinition;
                        factoryRecord.AllowExeDefinition = configSection.SectionInformation.AllowExeDefinition;
                    }
                }
            }

            if (_sectionRecords != null) {
                string definitionConfigPath = (IsLocationConfig) ? _parent.ConfigPath : ConfigPath;
                foreach (SectionRecord sectionRecord in _sectionRecords.Values) {
                    string configSource;
                    string configSourceStreamName;
                    object configSourceStreamVersion;
                    ConfigurationSection configSection;

                    if (sectionRecord.HasResult) {
                        configSection = (ConfigurationSection) sectionRecord.Result;
                        configSource = configSection.SectionInformation.ConfigSource;
                        if (String.IsNullOrEmpty(configSource)) {
                            configSource = null;
                        }

                        configSourceStreamName = configSection.SectionInformation.ConfigSourceStreamName;
                        if (String.IsNullOrEmpty(configSourceStreamName)) {
                            configSourceStreamName = null;
                        }
                    }
                    else {
                        configSection = null;
                        configSource = null;
                        configSourceStreamName = null;

                        // If there is no result, then the only way there could be a 
                        // section record is:
                        // 1. For there to be input in the file.
                        // 2. A location tag applies to this record
                        Debug.Assert(sectionRecord.HasFileInput || sectionRecord.HasLocationInputs, "sectionRecord.HasFileInput || sectionRecord.HasLocationInputs");

                        // Note that if it's a location input, we don't need to monitor the configSource because
                        // that stream is monitored by one of our parent's config record 
                        if (sectionRecord.HasFileInput) {
                            SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo;
                            configSource = sectionXmlInfo.ConfigSource;
                            configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
                        }
                    }

                    if (!String.IsNullOrEmpty(configSource)) {
                        configSourceStreamVersion = MonitorStream(sectionRecord.ConfigKey, configSource, configSourceStreamName);
                    }
                    else {
                        configSourceStreamVersion = null;
                    }

                    if (!sectionRecord.HasResult) {
                        Debug.Assert(sectionRecord.HasFileInput || sectionRecord.HasLocationInputs, "sectionRecord.HasFileInput || sectionRecord.HasLocationInputs");

                        // Note that if it's a location input, we don't need to monitor the configSource because
                        // that stream is monitored by one of our parent's config record 
                        if (sectionRecord.HasFileInput) {
                            SectionXmlInfo sectionXmlInfo = sectionRecord.FileInput.SectionXmlInfo;
                            sectionXmlInfo.StreamVersion = ConfigStreamInfo.StreamVersion;
                            sectionXmlInfo.ConfigSourceStreamVersion = configSourceStreamVersion;
                        }
                    }
                    else {
                        configSection.SectionInformation.RawXml = null;
                        bool addUpdate = sectionRecord.AddUpdate;
                        sectionRecord.AddUpdate = false;

                        if (addUpdate) {
                            SectionInput fileInput = sectionRecord.FileInput;
                            if (fileInput == null) {
                                SectionXmlInfo sectionXmlInfo = new SectionXmlInfo(
                                        sectionRecord.ConfigKey, definitionConfigPath, _configPath, _locationSubPath,
                                        ConfigStreamInfo.StreamName, 0, ConfigStreamInfo.StreamVersion, null, 
                                        configSource, configSourceStreamName, configSourceStreamVersion,
                                        configSection.SectionInformation.ProtectionProviderName, 
                                        !configSection.SectionInformation.AllowOverride, 
                                        !configSection.SectionInformation.InheritInChildApplications);

                                fileInput = new SectionInput(sectionXmlInfo, null);
                                fileInput.Result = configSection;
                                fileInput.ResultRuntimeObject = configSection;
                                sectionRecord.AddFileInput(fileInput);
                            }
                            else {
                                SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;
                                sectionXmlInfo.LineNumber = 0;
                                sectionXmlInfo.StreamVersion = ConfigStreamInfo.StreamVersion;

                                sectionXmlInfo.RawXml = null;
                                sectionXmlInfo.ConfigSource = configSource;
                                sectionXmlInfo.ConfigSourceStreamName = configSourceStreamName;
                                sectionXmlInfo.ConfigSourceStreamVersion = configSourceStreamVersion;
                                sectionXmlInfo.ProtectionProviderName = configSection.SectionInformation.ProtectionProviderName;
                                sectionXmlInfo.LockChildren = !configSection.SectionInformation.AllowOverride;
                                sectionXmlInfo.SkipInChildApps = !configSection.SectionInformation.InheritInChildApplications;
                            }

                            fileInput.ProtectionProvider = configSection.SectionInformation.ProtectionProvider;
                        }

                        try {
                            configSection.ResetModified();
                        }
                        catch (Exception e) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_in_config_section_handler, sectionRecord.ConfigKey), e, ConfigStreamInfo.StreamName, 0);
                        }
                        catch {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_in_config_section_handler, sectionRecord.ConfigKey), null, ConfigStreamInfo.StreamName, 0);
                        }
                    }
                }
            }

            // Copy remaining stream updates, which correspond to streams used by location sections
            foreach (StreamInfo streamInfo in _streamInfoUpdates.Values) {
                if (!ConfigStreamInfo.StreamInfos.Contains(streamInfo.StreamName)) {
                    MonitorStream(streamInfo.SectionName, streamInfo.ConfigSource, streamInfo.StreamName);
                }
            }

            // reinitialize _streamInfoUpdates
            InitStreamInfoUpdates();

            // Update namespace value
            _flags[ NamespacePresentInFile ] = _flags[ NamespacePresentCurrent ];

            // You only have one chance to force the location config, now you
            // will have to recreate the object
            _flags[ ForceLocationWritten ]   = false;
            _flags[ SuggestLocationRemoval ] = false;

            // Handle removed location sections
            if (!IsLocationConfig && _locationSections != null && _removedSections != null && _removedSections.Count > 0) {
                int i = 0;
                while (i < _locationSections.Count) {
                    LocationSectionRecord locationSectionRecord = (LocationSectionRecord) _locationSections[i];
                    if (_removedSections.Contains(locationSectionRecord.ConfigKey)) {
                        _locationSections.RemoveAt(i);
                    }
                    else {
                        i++;
                    }
                }
            }

            _removedSections = null;
            _removedSectionGroups = null;
        }