Наследование: IConfigErrorInfo
Пример #1
0
            private void Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
            {
                // Get the type of the factory
                Type type = TypeUtil.GetType(configRecord.Host, factoryRecord.FactoryTypeName,
                                             true);

                // If the type is a ConfigurationSection, that's the type.
                if (typeof(ConfigurationSection).IsAssignableFrom(type))
                {
                    _sectionCtor = TypeUtil.GetConstructor(type, typeof(ConfigurationSection),
                                                           true);
                }
                else
                {
                    // Note: in v1, IConfigurationSectionHandler is in effect a factory that has a Create method
                    // that creates the real section object.

                    // throws if type does not implement IConfigurationSectionHandler
                    TypeUtil.VerifyAssignableType(typeof(IConfigurationSectionHandler), type, true);

                    // Create an instance of the handler
                    _sectionHandler =
                        (IConfigurationSectionHandler)TypeUtil.CreateInstance(type);
                }
            }
Пример #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);
            }
Пример #3
0
        internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord,
                                                         FactoryRecord factoryRecord, SectionRecord sectionRecord)
        {
            _flags[FlagAttached] = true;

            // factory info
            ConfigKey                            = factoryRecord.ConfigKey;
            Name                                 = factoryRecord.Name;
            _typeName                            = factoryRecord.FactoryTypeName;
            _allowDefinition                     = factoryRecord.AllowDefinition;
            _allowExeDefinition                  = factoryRecord.AllowExeDefinition;
            _flags[FlagAllowLocation]            = factoryRecord.AllowLocation;
            _flags[FlagRestartOnExternalChanges] = factoryRecord.RestartOnExternalChanges;
            _flags[FlagRequirePermission]        = factoryRecord.RequirePermission;
            _overrideModeDefault                 = factoryRecord.OverrideModeDefault;

            if (factoryRecord.IsUndeclared)
            {
                _flags[FlagIsUndeclared]        = true;
                _flags[FlagDeclared]            = false;
                _flags[FlagDeclarationRequired] = false;
            }
            else
            {
                _flags[FlagIsUndeclared]        = false;
                _flags[FlagDeclared]            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null;
                _flags[FlagDeclarationRequired] = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false);
            }

            // section info
            _flags[FlagLocationLocked] = sectionRecord.Locked;
            _flags[FlagChildrenLocked] = sectionRecord.LockChildren;
            _flags[FlagChildrenLockWithoutFileInput] = sectionRecord.LockChildrenWithoutFileInput;

            if (sectionRecord.HasFileInput)
            {
                SectionInput fileInput = sectionRecord.FileInput;

                _flags[FlagProtectionProviderDetermined] = fileInput.IsProtectionProviderDetermined;
                _protectionProvider = fileInput.ProtectionProvider;

                SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;

                _configSource                  = sectionXmlInfo.ConfigSource;
                ConfigSourceStreamName         = sectionXmlInfo.ConfigSourceStreamName;
                _overrideMode                  = sectionXmlInfo.OverrideModeSetting;
                _flags[FlagInheritInChildApps] = !sectionXmlInfo.SkipInChildApps;
                ProtectionProviderName         = sectionXmlInfo.ProtectionProviderName;
            }
            else
            {
                _flags[FlagProtectionProviderDetermined] = false;
                _protectionProvider = null;
            }

            // element context information
            _configurationSection.AssociateContext(configRecord);
        }
        // parentConfig contains the config that we'd merge with.
        override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) {
            // Get the factory used to create a section.
            RuntimeConfigurationFactory factory = (RuntimeConfigurationFactory) factoryRecord.Factory;

            // Use the factory to create a section.
            object config = factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, parentConfig, reader);

            return config;
        }
Пример #5
0
        // parentConfig contains the config that we'd merge with.
        override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
        {
            // Get the factory used to create a section.
            RuntimeConfigurationFactory factory = (RuntimeConfigurationFactory)factoryRecord.Factory;

            // Use the factory to create a section.
            object config = factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, parentConfig, reader);

            return(config);
        }
Пример #6
0
        private FactoryRecord FindParentFactoryRecord(bool permitErrors)
        {
            FactoryRecord record = null;

            if ((this._configRecord != null) && !this._configRecord.Parent.IsRootConfig)
            {
                record = this._configRecord.Parent.FindFactoryRecord(this._configKey, permitErrors);
            }
            return(record);
        }
Пример #7
0
        private FactoryRecord FindParentFactoryRecord(bool permitErrors)
        {
            FactoryRecord factoryRecord = null;

            if ((_configRecord != null) && !_configRecord.Parent.IsRootConfig)
            {
                factoryRecord = _configRecord.Parent.FindFactoryRecord(SectionGroupName, permitErrors);
            }

            return(factoryRecord);
        }
        private FactoryRecord FindParentFactoryRecord(bool permitErrors)
        {
            FactoryRecord factoryRecord = null;

            if (_configRecord != null && !_configRecord.Parent.IsRootConfig)
            {
                factoryRecord = _configRecord.Parent.FindFactoryRecord(_configKey, permitErrors);
            }

            return(factoryRecord);
        }
 internal void AddConfigurationSection(string group, string name, ConfigurationSection configSection)
 {
     if (base.IsLocationConfig)
     {
         throw new InvalidOperationException(System.Configuration.SR.GetString("Config_add_configurationsection_in_location_config"));
     }
     BaseConfigurationRecord.VerifySectionName(name, null, false);
     if (configSection == null)
     {
         throw new ArgumentNullException("configSection");
     }
     if (configSection.SectionInformation.Attached)
     {
         throw new InvalidOperationException(System.Configuration.SR.GetString("Config_add_configurationsection_already_added"));
     }
     string configKey = BaseConfigurationRecord.CombineConfigKey(group, name);
     if (base.FindFactoryRecord(configKey, true) != null)
     {
         throw new ArgumentException(System.Configuration.SR.GetString("Config_add_configurationsection_already_exists"));
     }
     if (!string.IsNullOrEmpty(configSection.SectionInformation.ConfigSource))
     {
         this.ChangeConfigSource(configSection.SectionInformation, null, null, configSection.SectionInformation.ConfigSource);
     }
     if (this._sectionFactories != null)
     {
         this._sectionFactories.Add(configKey, new FactoryId(configKey, group, name));
     }
     string type = configSection.SectionInformation.Type;
     if (type == null)
     {
         type = base.Host.GetConfigTypeName(configSection.GetType());
     }
     FactoryRecord factoryRecord = new FactoryRecord(configKey, group, name, type, configSection.SectionInformation.AllowLocation, configSection.SectionInformation.AllowDefinition, configSection.SectionInformation.AllowExeDefinition, configSection.SectionInformation.OverrideModeDefaultSetting, configSection.SectionInformation.RestartOnExternalChanges, configSection.SectionInformation.RequirePermission, this._flags[0x2000], false, base.ConfigStreamInfo.StreamName, -1) {
         Factory = System.Configuration.TypeUtil.GetConstructorWithReflectionPermission(configSection.GetType(), typeof(ConfigurationSection), true),
         IsFactoryTrustedWithoutAptca = System.Configuration.TypeUtil.IsTypeFromTrustedAssemblyWithoutAptca(configSection.GetType())
     };
     base.EnsureFactories()[configKey] = factoryRecord;
     SectionRecord sectionRecord = base.EnsureSectionRecordUnsafe(configKey, false);
     sectionRecord.Result = configSection;
     sectionRecord.ResultRuntimeObject = configSection;
     if (this._removedSections != null)
     {
         this._removedSections.Remove(configKey);
     }
     configSection.SectionInformation.AttachToConfigurationRecord(this, factoryRecord, sectionRecord);
     string rawXml = configSection.SectionInformation.RawXml;
     if (!string.IsNullOrEmpty(rawXml))
     {
         configSection.SectionInformation.RawXml = null;
         configSection.SectionInformation.SetRawXml(rawXml);
     }
 }
Пример #10
0
 internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord,
                               FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     if (inputIsTrusted)
     {
         return(CreateSectionWithFullTrust(configRecord, factoryRecord, sectionRecord, parentConfig, reader));
     }
     else
     {
         return(CreateSectionWithRestrictedPermissions(configRecord, factoryRecord, sectionRecord, parentConfig, reader));
     }
 }
Пример #11
0
            private void Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
            {
                Type c = System.Configuration.TypeUtil.GetTypeWithReflectionPermission(configRecord.Host, factoryRecord.FactoryTypeName, true);

                if (typeof(ConfigurationSection).IsAssignableFrom(c))
                {
                    this._sectionCtor = System.Configuration.TypeUtil.GetConstructorWithReflectionPermission(c, typeof(ConfigurationSection), true);
                }
                else
                {
                    System.Configuration.TypeUtil.VerifyAssignableType(typeof(IConfigurationSectionHandler), c, true);
                    this._sectionHandler = (IConfigurationSectionHandler)System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(c);
                }
            }
        internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord) {
            _configRecord = configRecord;
            _configKey = factoryRecord.ConfigKey;
            _group = factoryRecord.Group;
            _name = factoryRecord.Name;
            _typeName = factoryRecord.FactoryTypeName;

            if (_typeName != null) {
                 FactoryRecord parentFactoryRecord = null;
                 if (!configRecord.Parent.IsRootConfig) {
                     parentFactoryRecord = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
                 }

                 _declarationRequired = (parentFactoryRecord == null || parentFactoryRecord.FactoryTypeName == null);
                 _declared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
            }
        }
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     this._configRecord = configRecord;
     this._configKey = factoryRecord.ConfigKey;
     this._group = factoryRecord.Group;
     this._name = factoryRecord.Name;
     this._typeName = factoryRecord.FactoryTypeName;
     if (this._typeName != null)
     {
         FactoryRecord record = null;
         if (!configRecord.Parent.IsRootConfig)
         {
             record = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
         }
         this._declarationRequired = (record == null) || (record.FactoryTypeName == null);
         this._declared = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
     }
 }
Пример #14
0
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     this._configRecord = configRecord;
     this._configKey    = factoryRecord.ConfigKey;
     this._group        = factoryRecord.Group;
     this._name         = factoryRecord.Name;
     this._typeName     = factoryRecord.FactoryTypeName;
     if (this._typeName != null)
     {
         FactoryRecord record = null;
         if (!configRecord.Parent.IsRootConfig)
         {
             record = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
         }
         this._declarationRequired = (record == null) || (record.FactoryTypeName == null);
         this._declared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
     }
 }
Пример #15
0
        internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord)
        {
            _configRecord    = configRecord;
            SectionGroupName = factoryRecord.ConfigKey;
            Name             = factoryRecord.Name;
            _typeName        = factoryRecord.FactoryTypeName;

            if (_typeName != null)
            {
                FactoryRecord parentFactoryRecord = null;
                if (!configRecord.Parent.IsRootConfig)
                {
                    parentFactoryRecord = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
                }

                IsDeclarationRequired = parentFactoryRecord?.FactoryTypeName == null;
                IsDeclared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
            }
        }
Пример #16
0
        internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord)
        {
            _configRecord = configRecord;
            _configKey    = factoryRecord.ConfigKey;
            _group        = factoryRecord.Group;
            _name         = factoryRecord.Name;
            _typeName     = factoryRecord.FactoryTypeName;

            if (_typeName != null)
            {
                FactoryRecord parentFactoryRecord = null;
                if (!configRecord.Parent.IsRootConfig)
                {
                    parentFactoryRecord = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
                }

                _declarationRequired = (parentFactoryRecord == null || parentFactoryRecord.FactoryTypeName == null);
                _declared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
            }
        }
Пример #17
0
            private object CreateSectionWithRestrictedPermissions(
                RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
                object parentConfig, ConfigXmlReader reader)
            {
                // run configuration section handlers as if user code was on the stack
                bool revertPermitOnly = false;

                try {
                    PermissionSet permissionSet = configRecord.GetRestrictedPermissions();
                    if (permissionSet != null)
                    {
                        permissionSet.PermitOnly();
                        revertPermitOnly = true;
                    }

                    return(CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader));
                }
                finally {
                    if (revertPermitOnly)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
 private void InitWithFullTrust(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) {
     Init(configRecord, factoryRecord);
 }
            private object CreateSectionImpl(
                    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
                    object parentConfig, ConfigXmlReader reader) {

                object config;

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

                    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;
            }
 private object CreateSectionWithRestrictedPermissions(
         RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
         object parentConfig, ConfigXmlReader reader)
 {
     return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
 }
 internal RuntimeConfigurationFactory(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) {
     // If the factory record was defined in a trusted config record, ignore user code on stack
     if (factoryRecord.IsFromTrustedConfigRecord) {
         InitWithFullTrust(configRecord, factoryRecord);
     }
     else {
         // Run configuration section handlers as if user code was on the stack
         InitWithRestrictedPermissions(configRecord, factoryRecord);
     }
 }
Пример #22
0
 // for instantiation of a ConfigurationSection from GetConfig
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord,
                                           SectionRecord sectionRecord)
 {
     SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
     _configRecord = configRecord;
 }
        internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord) {
            _flags[ Flag_Attached ] = true;

            // factory info
            _configKey          = factoryRecord.ConfigKey;
            _group              = factoryRecord.Group;
            _name               = factoryRecord.Name;
            _typeName           = factoryRecord.FactoryTypeName;
            _allowDefinition    = factoryRecord.AllowDefinition;
            _allowExeDefinition = factoryRecord.AllowExeDefinition;
            _flags[ Flag_AllowLocation            ] = factoryRecord.AllowLocation;
            _flags[ Flag_RestartOnExternalChanges ] = factoryRecord.RestartOnExternalChanges;
            _flags[ Flag_RequirePermission        ] = factoryRecord.RequirePermission;

            if (factoryRecord.IsUndeclared) {
                _flags[ Flag_IsUndeclared             ] = true;
                _flags[ Flag_Declared                 ] = false;
                _flags[ Flag_DeclarationRequired      ] = false;
            }
            else {
                _flags[ Flag_IsUndeclared             ] = false;
                _flags[ Flag_Declared                 ] = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null;
                _flags[ Flag_DeclarationRequired      ] = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false);
            }

            // section info
            _flags[ Flag_LocationLocked ]           = sectionRecord.Locked;

            if (sectionRecord.HasFileInput) {
                SectionInput fileInput = sectionRecord.FileInput;

                _flags[ Flag_ProtectionProviderDetermined ] = fileInput.IsProtectionProviderDetermined;
                _protectionProvider                         = fileInput.ProtectionProvider;
                
                SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;

                _configSource                       = sectionXmlInfo.ConfigSource;
                _configSourceStreamName             = sectionXmlInfo.ConfigSourceStreamName;
                _flags[ Flag_AllowOverride ]        = !sectionXmlInfo.LockChildren;
                _flags[ Flag_InheritInChildApps ]   = !sectionXmlInfo.SkipInChildApps;
                _protectionProviderName             = sectionXmlInfo.ProtectionProviderName;
            }
            else {
                _flags[ Flag_ProtectionProviderDetermined ] = false;
                _protectionProvider = null;
            }

            // element context information
            _configurationSection.AssociateContext( configRecord );
        }
Пример #24
0
 internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord)
 {
     this._flags[1]            = true;
     this._configKey           = factoryRecord.ConfigKey;
     this._group               = factoryRecord.Group;
     this._name                = factoryRecord.Name;
     this._typeName            = factoryRecord.FactoryTypeName;
     this._allowDefinition     = factoryRecord.AllowDefinition;
     this._allowExeDefinition  = factoryRecord.AllowExeDefinition;
     this._flags[8]            = factoryRecord.AllowLocation;
     this._flags[0x10]         = factoryRecord.RestartOnExternalChanges;
     this._flags[0x20]         = factoryRecord.RequirePermission;
     this._overrideModeDefault = factoryRecord.OverrideModeDefault;
     if (factoryRecord.IsUndeclared)
     {
         this._flags[0x2000] = true;
         this._flags[2]      = false;
         this._flags[4]      = false;
     }
     else
     {
         this._flags[0x2000] = false;
         this._flags[2]      = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null;
         this._flags[4]      = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false);
     }
     this._flags[0x40]   = sectionRecord.Locked;
     this._flags[0x80]   = sectionRecord.LockChildren;
     this._flags[0x4000] = sectionRecord.LockChildrenWithoutFileInput;
     if (sectionRecord.HasFileInput)
     {
         SectionInput fileInput = sectionRecord.FileInput;
         this._flags[0x800]       = fileInput.IsProtectionProviderDetermined;
         this._protectionProvider = fileInput.ProtectionProvider;
         SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;
         this._configSource           = sectionXmlInfo.ConfigSource;
         this._configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
         this._overrideMode           = sectionXmlInfo.OverrideModeSetting;
         this._flags[0x100]           = !sectionXmlInfo.SkipInChildApps;
         this._protectionProviderName = sectionXmlInfo.ProtectionProviderName;
     }
     else
     {
         this._flags[0x800]       = false;
         this._protectionProvider = null;
     }
     this._configurationSection.AssociateContext(configRecord);
 }
Пример #25
0
 internal RuntimeConfigurationFactory(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     Init(configRecord, factoryRecord);
 }
        //
        // Add a new configuration section group to this config file.
        //
        // Called from ConfigurationSectionGroupCollection.Add().
        // Note this method DOES NOT update the associated ConfigurationSectionGroupCollection.
        //
        internal void AddConfigurationSectionGroup(string group, string name, ConfigurationSectionGroup configSectionGroup) {
            // <location> tags can't have a <configSections> declaration.
            if (IsLocationConfig) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsectiongroup_in_location_config));
            }

            // Validate name argument.
            VerifySectionName(name, null, false);

            // Validate configSectionGroup argument.
            if (configSectionGroup == null) {
                throw ExceptionUtil.ParameterInvalid("name");
            }

            // A section group can only belong to one section group collection.
            if (configSectionGroup.Attached) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsectiongroup_already_added));
            }

            string configKey = BaseConfigurationRecord.CombineConfigKey(group, name);

            // Do not add if the section group already exists, even if it is of a different type.
            FactoryRecord factoryRecord = FindFactoryRecord(configKey, true);
            if (factoryRecord != null) {
                throw new ArgumentException(SR.GetString(SR.Config_add_configurationsectiongroup_already_exists));
            }

            // Add to list of all section groups.
            if (_sectionGroupFactories != null) {
                _sectionGroupFactories.Add(configKey, new FactoryId(configKey, group, name));
            }

            // Get the type name - if it is not specified explicitly, get it from the type of the object.
            string typeName = configSectionGroup.Type;
            if (typeName == null) {
                typeName = Host.GetConfigTypeName(configSectionGroup.GetType());
            }

            // Create a factory record and add it to the collection of factory records.
            factoryRecord = new FactoryRecord(configKey, group, name, typeName, ConfigStreamInfo.StreamName, -1);
            EnsureFactories()[configKey] = factoryRecord;

            // Add it to list of evaluated configuration section groups.
            SectionGroups[configKey] = configSectionGroup;

            // Remove it from RemovedSectionGroups if it was previously removed.
            if (_removedSectionGroups != null) {
                _removedSectionGroups.Remove(configKey);
            }

            // Attach to the configuration record.
            configSectionGroup.AttachToConfigurationRecord(this, factoryRecord);
        }
        private string GetUpdatedSectionDeclarationXml(FactoryRecord factoryRecord, ConfigurationSection configSection, ConfigurationSaveMode saveMode) {
            StringBuilder sb = new StringBuilder();
            sb.Append('<');
            sb.Append(KEYWORD_SECTION);
            sb.Append(' ');
            string type = (configSection.SectionInformation.Type != null) ? configSection.SectionInformation.Type : factoryRecord.FactoryTypeName;
            if (TypeStringTransformerIsSet)
                type = TypeStringTransformer(type);

            AppendAttribute(sb, KEYWORD_SECTION_NAME, configSection.SectionInformation.Name);
            AppendAttribute(sb, KEYWORD_SECTION_TYPE, type);

            if ( !configSection.SectionInformation.AllowLocation ||
                 (saveMode == ConfigurationSaveMode.Full)        ||
                 ((saveMode == ConfigurationSaveMode.Modified) &&
                   configSection.SectionInformation.AllowLocationModified)) {
                AppendAttribute(sb,
                                KEYWORD_SECTION_ALLOWLOCATION,
                                configSection.SectionInformation.AllowLocation ?
                                    KEYWORD_TRUE :
                                    KEYWORD_FALSE);
            }

            if ((configSection.SectionInformation.AllowDefinition != ConfigurationAllowDefinition.Everywhere) ||
                    (saveMode == ConfigurationSaveMode.Full) ||
                    (saveMode == ConfigurationSaveMode.Modified  && configSection.SectionInformation.AllowDefinitionModified)) {

                string v = null;
                switch (configSection.SectionInformation.AllowDefinition) {
                    case ConfigurationAllowDefinition.Everywhere:
                        v = KEYWORD_SECTION_ALLOWDEFINITION_EVERYWHERE;
                        break;
                    case ConfigurationAllowDefinition.MachineOnly:
                        v = KEYWORD_SECTION_ALLOWDEFINITION_MACHINEONLY;
                        break;

                    case ConfigurationAllowDefinition.MachineToWebRoot:
                        v = KEYWORD_SECTION_ALLOWDEFINITION_MACHINETOWEBROOT;
                        break;

                    case ConfigurationAllowDefinition.MachineToApplication:
                        v = KEYWORD_SECTION_ALLOWDEFINITION_MACHINETOAPPLICATION;
                        break;
                }

                AppendAttribute(sb, KEYWORD_SECTION_ALLOWDEFINITION, v);
            }

            if ((configSection.SectionInformation.AllowExeDefinition !=
                    ConfigurationAllowExeDefinition.MachineToApplication ) ||
                    (saveMode == ConfigurationSaveMode.Full) ||
                    (saveMode == ConfigurationSaveMode.Modified  && configSection.SectionInformation.AllowExeDefinitionModified)) {

                AppendAttribute( sb,
                        KEYWORD_SECTION_ALLOWEXEDEFINITION,
                        ExeDefinitionToString(
                        configSection.SectionInformation.AllowExeDefinition )
                        );
            }

            if (    (configSection.SectionInformation.OverrideModeDefaultSetting.IsDefaultForSection == false) ||
                    (saveMode == ConfigurationSaveMode.Full) ||
                    (saveMode == ConfigurationSaveMode.Modified  && configSection.SectionInformation.OverrideModeDefaultModified)) {

                AppendAttribute(    sb,
                                    KEYWORD_SECTION_OVERRIDEMODEDEFAULT,
                                    configSection.SectionInformation.OverrideModeDefaultSetting.OverrideModeXmlValue);
            }

            if (!configSection.SectionInformation.RestartOnExternalChanges) {
                AppendAttribute(sb, KEYWORD_SECTION_RESTARTONEXTERNALCHANGES, KEYWORD_FALSE);
            }
            else if ((saveMode == ConfigurationSaveMode.Full) ||
                    (saveMode == ConfigurationSaveMode.Modified  && configSection.SectionInformation.RestartOnExternalChangesModified)) {
                AppendAttribute(sb, KEYWORD_SECTION_RESTARTONEXTERNALCHANGES, KEYWORD_TRUE);
            }

            if (!configSection.SectionInformation.RequirePermission) {
                AppendAttribute(sb, KEYWORD_SECTION_REQUIREPERMISSION, KEYWORD_FALSE);
            }
            else if ((saveMode == ConfigurationSaveMode.Full) ||
                    (saveMode == ConfigurationSaveMode.Modified  && configSection.SectionInformation.RequirePermissionModified)) {
                AppendAttribute(sb, KEYWORD_SECTION_REQUIREPERMISSION, KEYWORD_TRUE);
            }

            sb.Append("/>");

            return sb.ToString();
        }
        //
        // Add a new configuration section to this config file.
        // This adds both the section declaration and definition to the config file.
        //
        // Called from ConfigurationSectionCollection.Add().
        // Note this method DOES NOT update the associated ConfigurationSectionCollection.
        //
        internal void AddConfigurationSection(string group, string name, ConfigurationSection configSection) {

            // <configSections> is not permitted within a <location> tag.
            if (IsLocationConfig) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsection_in_location_config));
            }

            VerifySectionName(name, null, false);

            if (configSection == null) {
                throw new ArgumentNullException("configSection");
            }

            // Ensure the section is not already part of the configuration hierarchy.
            if (configSection.SectionInformation.Attached) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsection_already_added));
            }

            string configKey = BaseConfigurationRecord.CombineConfigKey(group, name);

            // Ensure the section is not already declared.
            FactoryRecord factoryRecord = FindFactoryRecord(configKey, true);
            if (factoryRecord != null) {
                throw new ArgumentException(SR.GetString(SR.Config_add_configurationsection_already_exists));
            }

            // Add the configSource if needed.
            if (!String.IsNullOrEmpty(configSection.SectionInformation.ConfigSource)) {
                ChangeConfigSource(configSection.SectionInformation, null, null, configSection.SectionInformation.ConfigSource);
            }

            // Add to list of all sections.
            if (_sectionFactories != null) {
                _sectionFactories.Add(configKey, new FactoryId(configKey, group, name));
            }

            // Get the type name.
            string typeName = configSection.SectionInformation.Type;
            if (typeName == null) {
                typeName = Host.GetConfigTypeName(configSection.GetType());
            }

            // Add a factory record for the section.
            factoryRecord = new FactoryRecord(configKey,
                    group,
                    name,
                    typeName,
                    configSection.SectionInformation.AllowLocation,
                    configSection.SectionInformation.AllowDefinition,
                    configSection.SectionInformation.AllowExeDefinition,
                    configSection.SectionInformation.OverrideModeDefaultSetting,
                    configSection.SectionInformation.RestartOnExternalChanges,
                    configSection.SectionInformation.RequirePermission,
                    _flags[IsTrusted],
                    false,  // isUndeclared
                    ConfigStreamInfo.StreamName,
                    -1);

            // Construct a factory for the section
            factoryRecord.Factory = TypeUtil.GetConstructorWithReflectionPermission(
                    configSection.GetType(), typeof(ConfigurationSection), true);

            factoryRecord.IsFactoryTrustedWithoutAptca = TypeUtil.IsTypeFromTrustedAssemblyWithoutAptca(configSection.GetType());

            EnsureFactories()[configKey] = factoryRecord;

            // Add a section record for the section.
            // Since we are adding a new definition, it cannot be locked.
            SectionRecord sectionRecord = EnsureSectionRecordUnsafe(configKey, false);
            sectionRecord.Result = configSection;
            sectionRecord.ResultRuntimeObject = configSection;

            // Undo any previous removals of the section.
            if (_removedSections != null) {
                _removedSections.Remove(configKey);
            }

            // Attach the section to the configuration record.
            configSection.SectionInformation.AttachToConfigurationRecord(this, factoryRecord, sectionRecord);

            //
            // If there is rawXml, set it now. Note this will override any other changes to the section
            // definition made after the call to SetXml.
            //
            string rawXml = configSection.SectionInformation.RawXml;
            if (!String.IsNullOrEmpty(rawXml)) {
                configSection.SectionInformation.RawXml = null;
                configSection.SectionInformation.SetRawXml(rawXml);
            }
        }
        //
        // Ensure the existence of a section group factory, and return it.
        //
        private ConstructorInfo EnsureSectionGroupFactory(FactoryRecord factoryRecord) {
            ConstructorInfo factory = (ConstructorInfo) factoryRecord.Factory;
            if (factory == null) {
                factory = CreateSectionGroupFactory(factoryRecord);
                factoryRecord.Factory = factory;
            }

            return factory;
        }
        //
        // Create the type used to create new instances of a ConfigurationSectionGroup.
        // Our factory is a ConstructorInfo that creates the section group.
        //
        private ConstructorInfo CreateSectionGroupFactory(FactoryRecord factoryRecord) {
            Type type;

            if (String.IsNullOrEmpty(factoryRecord.FactoryTypeName)) {
                type = typeof(ConfigurationSectionGroup);
            }
            else {
                type = TypeUtil.GetTypeWithReflectionPermission(Host, factoryRecord.FactoryTypeName, true);
            }

            ConstructorInfo ctor = TypeUtil.GetConstructorWithReflectionPermission(type, typeof(ConfigurationSectionGroup), true);

            return ctor;
        }
            private object CreateSectionWithRestrictedPermissions(
                    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
                    object parentConfig, ConfigXmlReader reader) {

                // run configuration section handlers as if user code was on the stack
                bool revertPermitOnly = false;
                try {
                    PermissionSet permissionSet = configRecord.GetRestrictedPermissions();
                    if (permissionSet != null) {
                        permissionSet.PermitOnly();
                        revertPermitOnly = true;
                    }

                    return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
                }
                finally {
                    if (revertPermitOnly) {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
Пример #32
0
 internal RuntimeConfigurationFactory(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     // If the factory record was defined in a trusted config record, ignore user code on stack
     if (factoryRecord.IsFromTrustedConfigRecord)
     {
         InitWithFullTrust(configRecord, factoryRecord);
     }
     else
     {
         // Run configuration section handlers as if user code was on the stack
         InitWithRestrictedPermissions(configRecord, factoryRecord);
     }
 }
        //
        // Create the ConfigurationSection.
        //
        override protected object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) {
            // Create an instance of the ConfigurationSection
            ConstructorInfo ctor = (ConstructorInfo) factoryRecord.Factory;
            ConfigurationSection configSection = (ConfigurationSection) TypeUtil.InvokeCtorWithReflectionPermission(ctor);

            // Attach the ConfigurationSection to this record
            configSection.SectionInformation.AttachToConfigurationRecord(this, factoryRecord, sectionRecord);
            configSection.CallInit();

            // Initialize the ConfigurationSection with XML or just its parent.
            ConfigurationSection parentConfigSection = (ConfigurationSection) parentConfig;
            configSection.Reset(parentConfigSection);
            if (reader != null) {
                configSection.DeserializeSection(reader);
            }

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

            return configSection;
        }
Пример #34
0
 private void InitWithFullTrust(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     Init(configRecord, factoryRecord);
 }
 private void InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     Init(configRecord, factoryRecord);
 }
 internal void SetRuntimeConfigurationInformation(BaseConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord)
 {
     this._flags[1] = true;
     this._configKey = factoryRecord.ConfigKey;
     this._group = factoryRecord.Group;
     this._name = factoryRecord.Name;
     this._typeName = factoryRecord.FactoryTypeName;
     this._allowDefinition = factoryRecord.AllowDefinition;
     this._allowExeDefinition = factoryRecord.AllowExeDefinition;
     this._flags[8] = factoryRecord.AllowLocation;
     this._flags[0x10] = factoryRecord.RestartOnExternalChanges;
     this._flags[0x20] = factoryRecord.RequirePermission;
     this._overrideModeDefault = factoryRecord.OverrideModeDefault;
     if (factoryRecord.IsUndeclared)
     {
         this._flags[0x2000] = true;
         this._flags[2] = false;
         this._flags[4] = false;
     }
     else
     {
         this._flags[0x2000] = false;
         this._flags[2] = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, false) != null;
         this._flags[4] = configRecord.IsRootDeclaration(factoryRecord.ConfigKey, false);
     }
     this._flags[0x40] = sectionRecord.Locked;
     this._flags[0x80] = sectionRecord.LockChildren;
     this._flags[0x4000] = sectionRecord.LockChildrenWithoutFileInput;
     if (sectionRecord.HasFileInput)
     {
         SectionInput fileInput = sectionRecord.FileInput;
         this._flags[0x800] = fileInput.IsProtectionProviderDetermined;
         this._protectionProvider = fileInput.ProtectionProvider;
         SectionXmlInfo sectionXmlInfo = fileInput.SectionXmlInfo;
         this._configSource = sectionXmlInfo.ConfigSource;
         this._configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
         this._overrideMode = sectionXmlInfo.OverrideModeSetting;
         this._flags[0x100] = !sectionXmlInfo.SkipInChildApps;
         this._protectionProviderName = sectionXmlInfo.ProtectionProviderName;
     }
     else
     {
         this._flags[0x800] = false;
         this._protectionProvider = null;
     }
     this._configurationSection.AssociateContext(configRecord);
 }
Пример #37
0
            private object CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
            {
                object obj2;
                bool   flag = false;

                try
                {
                    PermissionSet restrictedPermissions = configRecord.GetRestrictedPermissions();
                    if (restrictedPermissions != null)
                    {
                        restrictedPermissions.PermitOnly();
                        flag = true;
                    }
                    obj2 = this.CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
                }
                finally
                {
                    if (flag)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
                return(obj2);
            }
 private bool AreDeclarationAttributesModified(FactoryRecord factoryRecord, ConfigurationSection configSection) {
     return     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
             || factoryRecord.OverrideModeDefault.OverrideMode != configSection.SectionInformation.OverrideModeDefaultSetting.OverrideMode   // Compare the value only
             || configSection.SectionInformation.IsModifiedFlags();
 }
Пример #39
0
 internal RuntimeConfigurationFactory(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     Init(configRecord, factoryRecord);
 }
 // Create the factory that will evaluate configuration 
 override protected object CreateSectionFactory(FactoryRecord factoryRecord) {
     return new RuntimeConfigurationFactory(this, factoryRecord);
 }
Пример #41
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);
 }
        //
        // Create the factory object that is used to create new instances of a ConfigurationSection.
        // Our factory is a ConstructorInfo that creates the section.
        //
        override protected object CreateSectionFactory(FactoryRecord factoryRecord) {

            // Get the type of the factory
            Type type = TypeUtil.GetTypeWithReflectionPermission(Host, factoryRecord.FactoryTypeName, true);

            //
            // If the type is not a ConfigurationSection, use the DefaultSection if the type
            // implements IConfigurationSectionHandler.
            //
            if (!typeof(ConfigurationSection).IsAssignableFrom(type)) {
                TypeUtil.VerifyAssignableType(typeof(IConfigurationSectionHandler), type, true);
                type = typeof(DefaultSection);
            }

            ConstructorInfo ctor = TypeUtil.GetConstructorWithReflectionPermission(type, typeof(ConfigurationSection), true);

            return ctor;
        }
            private void Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) {
                // Get the type of the factory
                Type type = TypeUtil.GetTypeWithReflectionPermission(configRecord.Host, factoryRecord.FactoryTypeName, true);

                // If the type is a ConfigurationSection, that's the type.
                if (typeof(ConfigurationSection).IsAssignableFrom(type)) {
                    _sectionCtor = TypeUtil.GetConstructorWithReflectionPermission(type, typeof(ConfigurationSection), true);
                }
                else {
                    // Note: in v1, IConfigurationSectionHandler is in effect a factory that has a Create method
                    // that creates the real section object.

                    // throws if type does not implement IConfigurationSectionHandler
                    TypeUtil.VerifyAssignableType(typeof(IConfigurationSectionHandler), type, true);

                    // Create an instance of the handler
                    _sectionHandler = (IConfigurationSectionHandler) TypeUtil.CreateInstanceWithReflectionPermission(type);
                }
            }
Пример #44
0
        private ConstructorInfo CreateSectionGroupFactory(FactoryRecord factoryRecord)
        {
            Type type = string.IsNullOrEmpty(factoryRecord.FactoryTypeName)
                ? typeof(ConfigurationSectionGroup)
                : TypeUtil.GetType(Host, factoryRecord.FactoryTypeName, true);

            ConstructorInfo ctor = TypeUtil.GetConstructor(type,
                typeof(ConfigurationSectionGroup), true);

            return ctor;
        }
            private void InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord) {
                // Run configuration section handlers as if user code was on the stack
                bool revertPermitOnly = false;
                try {
                    PermissionSet permissionSet = configRecord.GetRestrictedPermissions();
                    if (permissionSet != null) {
                        permissionSet.PermitOnly();
                        revertPermitOnly = true;
                    }

                    Init(configRecord, factoryRecord);
                }
                finally {
                    if (revertPermitOnly) {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
Пример #46
0
            private void InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
            {
                bool flag = false;

                try
                {
                    PermissionSet restrictedPermissions = configRecord.GetRestrictedPermissions();
                    if (restrictedPermissions != null)
                    {
                        restrictedPermissions.PermitOnly();
                        flag = true;
                    }
                    this.Init(configRecord, factoryRecord);
                }
                finally
                {
                    if (flag)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
            private object CreateSectionWithFullTrust(
                    RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, 
                    object parentConfig, ConfigXmlReader reader) {

                return CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
            }
Пример #48
0
 // Create the factory that will evaluate configuration
 protected override object CreateSectionFactory(FactoryRecord factoryRecord)
 {
     return(new RuntimeConfigurationFactory(this, factoryRecord));
 }
            internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord, 
                    FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader) {

                if (inputIsTrusted) {
                    return CreateSectionWithFullTrust(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
                }
                else {
                    return CreateSectionWithRestrictedPermissions(configRecord, factoryRecord, sectionRecord, parentConfig, reader);
                }
            }
        private string GetUpdatedSectionGroupDeclarationXml(FactoryRecord factoryRecord, ConfigurationSectionGroup configSectionGroup) {
            if (TargetFramework != null && !configSectionGroup.ShouldSerializeSectionGroupInTargetVersion(TargetFramework))
                return null;

            StringBuilder sb = new StringBuilder();
            sb.Append('<');
            sb.Append(KEYWORD_SECTIONGROUP);
            sb.Append(' ');
            AppendAttribute(sb, KEYWORD_SECTIONGROUP_NAME, configSectionGroup.Name);
            string type = (configSectionGroup.Type != null) ? configSectionGroup.Type : factoryRecord.FactoryTypeName;
            if (TypeStringTransformerIsSet)
                type = TypeStringTransformer(type);

            AppendAttribute(sb, KEYWORD_SECTIONGROUP_TYPE, type);

            sb.Append('>');

            return sb.ToString();
        }
Пример #51
0
 internal RuntimeConfigurationFactory(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
 {
     if (factoryRecord.IsFromTrustedConfigRecord)
     {
         this.InitWithFullTrust(configRecord, factoryRecord);
     }
     else
     {
         this.InitWithRestrictedPermissions(configRecord, factoryRecord);
     }
 }
Пример #52
0
        protected override object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
        {
            RuntimeConfigurationFactory factory = (RuntimeConfigurationFactory)factoryRecord.Factory;

            return(factory.CreateSection(inputIsTrusted, this, factoryRecord, sectionRecord, parentConfig, reader));
        }
Пример #53
0
            private void InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
            {
                // Run configuration section handlers as if user code was on the stack
                bool revertPermitOnly = false;

                try {
                    PermissionSet permissionSet = configRecord.GetRestrictedPermissions();
                    if (permissionSet != null)
                    {
                        permissionSet.PermitOnly();
                        revertPermitOnly = true;
                    }

                    Init(configRecord, factoryRecord);
                }
                finally {
                    if (revertPermitOnly)
                    {
                        CodeAccessPermission.RevertPermitOnly();
                    }
                }
            }
Пример #54
0
        private string GetUpdatedSectionGroupDeclarationXml(FactoryRecord factoryRecord,
            ConfigurationSectionGroup configSectionGroup)
        {
            if ((TargetFramework != null) &&
                !configSectionGroup.ShouldSerializeSectionGroupInTargetVersion(TargetFramework))
                return null;

            StringBuilder sb = new StringBuilder();
            sb.Append('<');
            sb.Append(KeywordSectiongroup);
            sb.Append(' ');
            AppendAttribute(sb, KeywordSectiongroupName, configSectionGroup.Name);
            string type = configSectionGroup.Type ?? factoryRecord.FactoryTypeName;
            if (TypeStringTransformerIsSet)
                type = TypeStringTransformer(type);

            AppendAttribute(sb, KeywordSectiongroupType, type);

            sb.Append('>');

            return sb.ToString();
        }
 internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord)
 {
     this.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
     this._configRecord = configRecord;
 }
Пример #56
0
 private object CreateSectionWithFullTrust(
     RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord,
     object parentConfig, ConfigXmlReader reader)
 {
     return(CreateSectionImpl(configRecord, factoryRecord, sectionRecord, parentConfig, reader));
 }