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

ChangeConfigSource() private method

private ChangeConfigSource ( SectionInformation sectionInformation, string oldConfigSource, string oldConfigSourceStreamName, string newConfigSource ) : void
sectionInformation SectionInformation
oldConfigSource string
oldConfigSourceStreamName string
newConfigSource string
return void
        internal void ChangeConfigSource(
                SectionInformation sectionInformation, 
                string oldConfigSource, 
                string oldConfigSourceStreamName,
                string newConfigSource) {

            if (String.IsNullOrEmpty(oldConfigSource)) {
                oldConfigSource = null;
            }

            if (String.IsNullOrEmpty(newConfigSource)) {
                newConfigSource = null;
            }

            // Check if there is a change to config source
            if (StringUtil.EqualsIgnoreCase(oldConfigSource, newConfigSource))
                return;

            if (String.IsNullOrEmpty(ConfigStreamInfo.StreamName)) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_requires_file));
            }

            string newConfigSourceStreamName = null;
            if (newConfigSource != null) {
                newConfigSourceStreamName = Host.GetStreamNameForConfigSource(ConfigStreamInfo.StreamName, newConfigSource);
            }

            // Add the stream to the updates
            if (newConfigSourceStreamName != null) {
                //
                // Ensure that no parent is using the same config source stream
                //
                ValidateUniqueChildConfigSource(sectionInformation.ConfigKey, newConfigSourceStreamName, newConfigSource, null);

                StreamInfo streamInfo = (StreamInfo) _streamInfoUpdates[newConfigSourceStreamName];
                if (streamInfo != null) {
                    //
                    // Detect if another section in this file is using the same configSource 
                    // with has a different section name.
                    //
                    if (streamInfo.SectionName != sectionInformation.ConfigKey) {
                        throw new ConfigurationErrorsException(
                            SR.GetString(SR.Config_source_cannot_be_shared, newConfigSource));
                    }
                }
                else {
                    //
                    // Add stream to updates
                    //
                    streamInfo = new StreamInfo(sectionInformation.ConfigKey, newConfigSource, newConfigSourceStreamName);
                    _streamInfoUpdates.Add(newConfigSourceStreamName, streamInfo);
                }
            }

            // remove old streamname if no longer referenced
            if (oldConfigSourceStreamName != null && !IsStreamUsed(oldConfigSourceStreamName)) {
                _streamInfoUpdates.Remove(oldConfigSourceStreamName);
            }

            // update the configSourceStreamName
            sectionInformation.ConfigSourceStreamName = newConfigSourceStreamName;
        }