internal void DeserializeConfigSource(string basePath)
        {
            var configSource = SectionInformation.ConfigSource;

            if (string.IsNullOrEmpty(configSource))
            {
                return;
            }

            if (Path.IsPathRooted(configSource))
            {
                throw new ConfigurationErrorsException("The configSource attribute must be a relative physical path.");
            }

            if (HasLocalModifications())
            {
                throw new ConfigurationErrorsException(
                          "A section using 'configSource' may contain no other attributes or elements.");
            }

            string path = Path.Combine(basePath, configSource);

            if (!File.Exists(path))
            {
                RawXml = null;
                SectionInformation.SetRawXml(null);
                throw new ConfigurationErrorsException(string.Format("Unable to open configSource file '{0}'.", path));
            }

            RawXml = File.ReadAllText(path);
            SectionInformation.SetRawXml(RawXml);
            DeserializeElement(XmlReader.Create(new StringReader(RawXml)), false);
        }
        private void DoDeserializeSection(XmlReader reader)
        {
            reader.MoveToContent();

            string configSource = null;

            while (reader.MoveToNextAttribute())
            {
                var localName = reader.LocalName;
                if (localName == "configSource")
                {
                    configSource = reader.Value;
                }
            }

            if (configSource != null)
            {
                SectionInformation.ConfigSource = configSource;
            }

            SectionInformation.SetRawXml(RawXml);
            if (SectionHandler == null)
            {
                DeserializeElement(reader, false);
            }
        }
Example #3
0
 public SectionInfo(string sectionName, SectionInformation info)
 {
     Name                      = sectionName;
     TypeName                  = info.Type;
     _allowLocation            = info.AllowLocation;
     _allowDefinition          = info.AllowDefinition;
     _allowExeDefinition       = info.AllowExeDefinition;
     _requirePermission        = info.RequirePermission;
     _restartOnExternalChanges = info.RestartOnExternalChanges;
 }
Example #4
0
		public SectionInfo (string sectionName, SectionInformation info)
		{
			Name = sectionName;
			TypeName = info.Type;
			this.allowLocation = info.AllowLocation;
			this.allowDefinition = info.AllowDefinition;
			this.allowExeDefinition = info.AllowExeDefinition;
			this.requirePermission = info.RequirePermission;
			this.restartOnExternalChanges = info.RestartOnExternalChanges;
		}
        void DoDeserializeSection(XmlReader reader)
        {
            reader.MoveToContent();

            string protection_provider = null;
            string config_source       = null;
            string localName;

            while (reader.MoveToNextAttribute())
            {
                localName = reader.LocalName;
                if (localName == "configProtectionProvider")
                {
                    protection_provider = reader.Value;
                }
                else if (localName == "configSource")
                {
                    config_source = reader.Value;
                }
            }

            /* XXX this stuff shouldn't be here */
            {
                if (protection_provider != null)
                {
                    ProtectedConfigurationProvider prov = ProtectedConfiguration.GetProvider(protection_provider, true);
                    XmlDocument doc = new ConfigurationXmlDocument();

                    reader.MoveToElement();

                    doc.Load(new StringReader(reader.ReadInnerXml()));

                    XmlNode n = prov.Decrypt(doc);

                    reader = new XmlNodeReader(n);

                    SectionInformation.ProtectSection(protection_provider);

                    reader.MoveToContent();
                }
            }

            if (config_source != null)
            {
                SectionInformation.ConfigSource = config_source;
            }

            SectionInformation.SetRawXml(RawXml);
            if (SectionHandler == null)
            {
                DeserializeElement(reader, false);
            }
        }
Example #6
0
        protected internal virtual object GetRuntimeObject()
        {
            if (SectionHandler != null)
            {
                ConfigurationSection parentSection = sectionInformation != null?sectionInformation.GetParentSection() : null;

                object parent = parentSection != null?parentSection.GetRuntimeObject() : null;

                if (RawXml == null)
                {
                    return(parent);
                }

                try
                {
                    // This code requires some re-thinking...
                    XmlReader reader = new ConfigXmlTextReader(
                        new StringReader(RawXml),
                        Configuration.FilePath);

                    DoDeserializeSection(reader);

                    if (!String.IsNullOrEmpty(SectionInformation.ConfigSource))
                    {
                        string fileDir = SectionInformation.ConfigFilePath;
                        if (!String.IsNullOrEmpty(fileDir))
                        {
                            fileDir = Path.GetDirectoryName(fileDir);
                        }
                        else
                        {
                            fileDir = String.Empty;
                        }

                        string path = Path.Combine(fileDir, SectionInformation.ConfigSource);
                        if (File.Exists(path))
                        {
                            RawXml = File.ReadAllText(path);
                            SectionInformation.SetRawXml(RawXml);
                        }
                    }
                }
                catch
                {
                    // ignore, it can fail - we deserialize only in order to get
                    // the configSource attribute
                }
                XmlDocument doc = new ConfigurationXmlDocument();
                doc.LoadXml(RawXml);
                return(SectionHandler.Create(parent, ConfigContext, doc.DocumentElement));
            }
            return(this);
        }
Example #7
0
        private SectionInfo CreateSectionInfo(IConfigSystem system, string configPath, string sectionName, string sectionType)
        {
            var sectionInformation = new SectionInformation
            {
                Type           = sectionType,
                ConfigFilePath = configPath
            };

            sectionInformation.SetName(sectionName);

            var sectionInfo = new SectionInfo(sectionName, sectionInformation)
            {
                StreamName = FileName,
                ConfigHost = system.Host
            };

            return(sectionInfo);
        }
Example #8
0
        internal void DeserializeConfigSource(string basePath)
        {
            string config_source = SectionInformation.ConfigSource;

            if (String.IsNullOrEmpty (config_source))
                return;

            if (Path.IsPathRooted (config_source))
                throw new ConfigurationException ("The configSource attribute must be a relative physical path.");

            if (HasLocalModifications ())
                throw new ConfigurationException ("A section using 'configSource' may contain no other attributes or elements.");

            string path = Path.Combine (basePath, config_source);
            if (!File.Exists (path)) {
                RawXml = null;
                SectionInformation.SetRawXml (null);
                return;
            }

            RawXml = File.ReadAllText (path);
            SectionInformation.SetRawXml (RawXml);
            DeserializeElement (new ConfigXmlTextReader (new StringReader (RawXml), path), false);
        }
 // Constructor
 //
 protected ConfigurationSection() {
     _section = new SectionInformation( this );
 }
Example #10
0
 // Constructor
 //
 protected ConfigurationSection()
 {
     _section = new SectionInformation(this);
 }
        //
        // Set the configSource attribute on a ConfigurationSection
        //
        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;
        }
 internal void ChangeConfigSource(SectionInformation sectionInformation, string oldConfigSource, string oldConfigSourceStreamName, string newConfigSource)
 {
     if (string.IsNullOrEmpty(oldConfigSource))
     {
         oldConfigSource = null;
     }
     if (string.IsNullOrEmpty(newConfigSource))
     {
         newConfigSource = null;
     }
     if (!StringUtil.EqualsIgnoreCase(oldConfigSource, newConfigSource))
     {
         if (string.IsNullOrEmpty(base.ConfigStreamInfo.StreamName))
         {
             throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_source_requires_file"));
         }
         string configSourceStreamName = null;
         if (newConfigSource != null)
         {
             configSourceStreamName = base.Host.GetStreamNameForConfigSource(base.ConfigStreamInfo.StreamName, newConfigSource);
         }
         if (configSourceStreamName != null)
         {
             base.ValidateUniqueChildConfigSource(sectionInformation.ConfigKey, configSourceStreamName, newConfigSource, null);
             StreamInfo info = (StreamInfo) this._streamInfoUpdates[configSourceStreamName];
             if (info != null)
             {
                 if (info.SectionName != sectionInformation.ConfigKey)
                 {
                     throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_source_cannot_be_shared", new object[] { newConfigSource }));
                 }
             }
             else
             {
                 info = new StreamInfo(sectionInformation.ConfigKey, newConfigSource, configSourceStreamName);
                 this._streamInfoUpdates.Add(configSourceStreamName, info);
             }
         }
         if ((oldConfigSourceStreamName != null) && !this.IsStreamUsed(oldConfigSourceStreamName))
         {
             this._streamInfoUpdates.Remove(oldConfigSourceStreamName);
         }
         sectionInformation.ConfigSourceStreamName = configSourceStreamName;
     }
 }