DeserializeSection() private method

private DeserializeSection ( XmlReader reader ) : void
reader XmlReader
return void
Beispiel #1
0
 private object CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     if (this._sectionCtor != null)
     {
         ConfigurationSection section = (ConfigurationSection)System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(this._sectionCtor);
         section.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
         section.CallInit();
         ConfigurationSection parentElement = (ConfigurationSection)parentConfig;
         section.Reset(parentElement);
         if (reader != null)
         {
             section.DeserializeSection(reader);
         }
         ConfigurationErrorsException errors = section.GetErrors();
         if (errors != null)
         {
             throw errors;
         }
         section.SetReadOnly();
         section.ResetModified();
         return(section);
     }
     if (reader != null)
     {
         XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader);
         CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode);
         object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath);
         return(this._sectionHandler.Create(parentConfig, configContext, xmlNode));
     }
     return(null);
 }
Beispiel #2
0
            internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord,
                                          FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
            {
                object config;

                if (_sectionCtor != null)
                {
                    ConfigurationSection configSection =
                        (ConfigurationSection)_sectionCtor.Invoke(null);

                    configSection.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord,
                                                                                        sectionRecord);

                    configSection.CallInit();

                    ConfigurationSection parentSection = (ConfigurationSection)parentConfig;
                    configSection.Reset(parentSection);

                    if (reader != null)
                    {
                        configSection.DeserializeSection(reader);
                    }

                    // throw if there are any cached errors
                    ConfigurationErrorsException errors = configSection.GetErrors();
                    if (errors != null)
                    {
                        throw errors;
                    }

                    // don't allow changes to sections at runtime
                    configSection.SetReadOnly();

                    // reset the modified bit
                    configSection.ResetModified();

                    config = configSection;
                }
                else
                {
                    if (reader != null)
                    {
                        XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader);

                        CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode);

                        // In v1, our old section handler expects a context that contains the virtualPath from the configPath
                        object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath);

                        config = _sectionHandler.Create(parentConfig, configContext, xmlNode);
                    }
                    else
                    {
                        config = null;
                    }
                }

                return(config);
            }
Beispiel #3
0
        internal ConfigurationSection GetSectionInstance(SectionInfo config, bool createDefaultInstance)
        {
            object data = elementData [config];
            ConfigurationSection sec = data as ConfigurationSection;

            if (sec != null || !createDefaultInstance)
            {
                return(sec);
            }

            object secObj = config.CreateInstance();

            sec = secObj as ConfigurationSection;
            if (sec == null)
            {
                DefaultSection ds = new DefaultSection();
                ds.SectionHandler = secObj as IConfigurationSectionHandler;
                sec = ds;
            }
            sec.Configuration = this;

            ConfigurationSection parentSection = null;

            if (parent != null)
            {
                parentSection = parent.GetSectionInstance(config, true);
                sec.SectionInformation.SetParentSection(parentSection);
            }
            sec.SectionInformation.ConfigFilePath = FilePath;

            sec.ConfigContext = system.Host.CreateDeprecatedConfigContext(configPath);

            string xml = data as string;

            sec.RawXml = xml;
            sec.Reset(parentSection);

            if (xml != null)
            {
                XmlTextReader r = new ConfigXmlTextReader(new StringReader(xml), FilePath);
                sec.DeserializeSection(r);
                r.Close();

                if (!String.IsNullOrEmpty(sec.SectionInformation.ConfigSource) && !String.IsNullOrEmpty(FilePath))
                {
                    sec.DeserializeConfigSource(Path.GetDirectoryName(FilePath));
                }
            }

            elementData [config] = sec;
            return(sec);
        }
        //
        // Update the section with the XML provided.
        //
        // This method will throw out any changes made to the section up to this point.
        //
        // If xmlElement is null or empty, it is equivalent to calling RevertToParent
        //
        internal void SetRawXml(ConfigurationSection configSection, string xmlElement) {

            // Null or empty is equivalent to RevertToParent().
            if (string.IsNullOrEmpty(xmlElement)) {
                RevertToParent(configSection);
                return;
            }

            ValidateSectionXml(xmlElement, configSection.SectionInformation.Name);

            // Reset the ConfigurationSection with the XML.
            ConfigurationSection parentConfigSection = FindImmediateParentSection(configSection);
            ConfigXmlReader reader = new ConfigXmlReader(xmlElement, null, 0);

            // Store the raw XML.
            configSection.SectionInformation.RawXml = xmlElement;

            // Update the section with the xml
            try {
                try {
                    bool wasPresent = configSection.ElementPresent;
                    PropertySourceInfo saveInfo = configSection.ElementInformation.PropertyInfoInternal();

                    configSection.Reset(parentConfigSection);
                    configSection.DeserializeSection(reader);
                    configSection.ResetModified();

                    configSection.ElementPresent = wasPresent;
                    configSection.ElementInformation.ChangeSourceAndLineNumber(saveInfo);
                }
                catch {
                    configSection.SectionInformation.RawXml = null;
                    throw;
                }
            }
            catch (Exception e) {
                throw new ConfigurationErrorsException(SR.GetString(SR.Config_exception_in_config_section_handler, configSection.SectionInformation.SectionName),
                        e, null, 0);
            }

            // Ignore previous attempts to remove the section.
            configSection.SectionInformation.Removed = false;
        }
 internal void SetRawXml(ConfigurationSection configSection, string xmlElement)
 {
     if (string.IsNullOrEmpty(xmlElement))
     {
         this.RevertToParent(configSection);
     }
     else
     {
         this.ValidateSectionXml(xmlElement, configSection.SectionInformation.Name);
         ConfigurationSection parentElement = this.FindImmediateParentSection(configSection);
         ConfigXmlReader reader = new ConfigXmlReader(xmlElement, null, 0);
         configSection.SectionInformation.RawXml = xmlElement;
         try
         {
             try
             {
                 bool elementPresent = configSection.ElementPresent;
                 PropertySourceInfo sourceInformation = configSection.ElementInformation.PropertyInfoInternal();
                 configSection.Reset(parentElement);
                 configSection.DeserializeSection(reader);
                 configSection.ResetModified();
                 configSection.ElementPresent = elementPresent;
                 configSection.ElementInformation.ChangeSourceAndLineNumber(sourceInformation);
             }
             catch
             {
                 configSection.SectionInformation.RawXml = null;
                 throw;
             }
         }
         catch (Exception exception)
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_exception_in_config_section_handler", new object[] { configSection.SectionInformation.SectionName }), exception, null, 0);
         }
         configSection.SectionInformation.Removed = false;
     }
 }