static internal IInternalConfigRecord Create( InternalConfigRoot configRoot, IInternalConfigRecord parent, string configPath) { RuntimeConfigurationRecord configRecord = new RuntimeConfigurationRecord(); configRecord.Init(configRoot, (BaseConfigurationRecord) parent, configPath, null); return configRecord; }
internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams) { _typeConfigHost = typeConfigHost; _hostInitConfigurationParams = hostInitConfigurationParams; _configRoot = new InternalConfigRoot(this); IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstanceWithReflectionPermission(typeConfigHost); // Wrap the host with the UpdateConfigHost to support SaveAs. IInternalConfigHost updateConfigHost = new UpdateConfigHost(configHost); ((IInternalConfigRoot)_configRoot).Init(updateConfigHost, true); // // Set the configuration paths for this Configuration. // We do this in a separate step so that the WebConfigurationHost // can use this object's _configRoot to get the <sites> section, // which is used in it's MapPath implementation. // string configPath, locationConfigPath; configHost.InitForConfiguration(ref locationSubPath, out configPath, out locationConfigPath, _configRoot, hostInitConfigurationParams); if (!String.IsNullOrEmpty(locationSubPath) && !updateConfigHost.SupportsLocation) { throw ExceptionUtil.UnexpectedError("Configuration::ctor"); } if (String.IsNullOrEmpty(locationSubPath) != String.IsNullOrEmpty(locationConfigPath)) { throw ExceptionUtil.UnexpectedError("Configuration::ctor"); } // Get the configuration record for this config file. _configRecord = (MgmtConfigurationRecord)_configRoot.GetConfigRecord(configPath); // // Create another MgmtConfigurationRecord for the location that is a child of the above record. // Note that this does not match the resolution hiearchy that is used at runtime. // if (!String.IsNullOrEmpty(locationSubPath)) { _configRecord = MgmtConfigurationRecord.Create( _configRoot, _configRecord, locationConfigPath, locationSubPath); } // // Throw if the config record we created contains global errors. // _configRecord.ThrowIfInitErrors(); }
internal Configuration(string locationSubPath, Type typeConfigHost, params object[] hostInitConfigurationParams) { _typeConfigHost = typeConfigHost; _hostInitConfigurationParams = hostInitConfigurationParams; IInternalConfigHost configHost = (IInternalConfigHost)TypeUtil.CreateInstance(typeConfigHost); // Wrap the host with the UpdateConfigHost to support SaveAs. UpdateConfigHost updateConfigHost = new UpdateConfigHost(configHost); // Now wrap in ImplicitMachineConfigHost so we can stub in a simple machine.config if needed. IInternalConfigHost implicitMachineConfigHost = new ImplicitMachineConfigHost(updateConfigHost); InternalConfigRoot configRoot = new InternalConfigRoot(this, updateConfigHost); ((IInternalConfigRoot)configRoot).Init(implicitMachineConfigHost, isDesignTime: true); // Set the configuration paths for this Configuration. // // We do this in a separate step so that the WebConfigurationHost // can use this object's _configRoot to get the <sites> section, // which is used in it's MapPath implementation. string configPath, locationConfigPath; implicitMachineConfigHost.InitForConfiguration( ref locationSubPath, out configPath, out locationConfigPath, configRoot, hostInitConfigurationParams); if (!string.IsNullOrEmpty(locationSubPath) && !implicitMachineConfigHost.SupportsLocation) throw ExceptionUtil.UnexpectedError("Configuration::ctor"); if (string.IsNullOrEmpty(locationSubPath) != string.IsNullOrEmpty(locationConfigPath)) throw ExceptionUtil.UnexpectedError("Configuration::ctor"); // Get the configuration record for this config file. _configRecord = (MgmtConfigurationRecord)configRoot.GetConfigRecord(configPath); // Create another MgmtConfigurationRecord for the location that is a child of the above record. // Note that this does not match the resolution hiearchy that is used at runtime. if (!string.IsNullOrEmpty(locationSubPath)) { _configRecord = MgmtConfigurationRecord.Create( configRoot, _configRecord, locationConfigPath, locationSubPath); } // Throw if the config record we created contains global errors. _configRecord.ThrowIfInitErrors(); }
internal void Init( IInternalConfigRoot configRoot, BaseConfigurationRecord parent, string configPath, string locationSubPath) { _initErrors = new ConfigurationSchemaErrors(); // // try/catch here is only for unexpected exceptions due to errors in // our own code, as we always want the configuration record to be // usable // try { _configRoot = (InternalConfigRoot) configRoot; _parent = parent; _configPath = configPath; _locationSubPath = locationSubPath; _configName = ConfigPathUtility.GetName(configPath); if (IsLocationConfig) { _configStreamInfo = _parent.ConfigStreamInfo; } else { _configStreamInfo = new ConfigRecordStreamInfo(); } // no more initialization in case of root config if (IsRootConfig) return; // determine what features we support _flags[SupportsChangeNotifications] = ClassFlags[ClassSupportsChangeNotifications] && Host.SupportsChangeNotifications; _flags[SupportsRefresh] = ClassFlags[ClassSupportsRefresh] && Host.SupportsRefresh; _flags[SupportsKeepInputs] = ClassFlags[ClassSupportsKeepInputs] || _flags[SupportsRefresh]; _flags[SupportsPath] = Host.SupportsPath; _flags[SupportsLocation] = Host.SupportsLocation; // get static state based on the configPath if (_flags[SupportsLocation]) { _flags[IsAboveApplication] = Host.IsAboveApplication(_configPath); } _flags[IsTrusted] = Host.IsTrustedConfigPath(_configPath); ArrayList locationSubPathInputs = null; if (_flags[SupportsLocation]) { // // Treat location inputs from parent record // as though they were bonafide sections in this record. // if (IsLocationConfig && _parent._locationSections != null) { // Resolve paths and check for errors in location sections. _parent.ResolveLocationSections(); int i = 0; while (i < _parent._locationSections.Count) { LocationSectionRecord locationSectionRecord = (LocationSectionRecord) _parent._locationSections[i]; if (!StringUtil.EqualsIgnoreCase(locationSectionRecord.SectionXmlInfo.SubPath, _locationSubPath)) { i++; } else { // remove the locationSectionRecord from the list _parent._locationSections.RemoveAt(i); if (locationSubPathInputs == null) { locationSubPathInputs = new ArrayList(); } locationSubPathInputs.Add(locationSectionRecord); } } } // // Add location inputs that apply to this path, all the way up the parent hierarchy. // if (Host.IsLocationApplicable(_configPath)) { BaseConfigurationRecord current = _parent; while (!current.IsRootConfig) { if (current._locationSections != null) { current.ResolveLocationSections(); foreach (LocationSectionRecord locationSectionRecord in current._locationSections) { // We use the location tag input if: // - The path matches, and // - It's not skipped due to inheritInChildApplications setting. if (StringUtil.EqualsIgnoreCase(locationSectionRecord.SectionXmlInfo.TargetConfigPath, this._configPath) && !ShouldSkipDueToInheritInChildApplications(locationSectionRecord.SectionXmlInfo.SkipInChildApps)) { // add the location input for this section SectionRecord sectionRecord = EnsureSectionRecord(locationSectionRecord.ConfigKey, true); SectionInput sectionInput = new SectionInput( locationSectionRecord.SectionXmlInfo, locationSectionRecord.ErrorsList); sectionRecord.AddLocationInput(sectionInput); // copy the initialization errors to the record if (locationSectionRecord.HasErrors) { this._initErrors.AddSavedLocalErrors(locationSectionRecord.Errors); } } } } current = current._parent; } } } if (!IsLocationConfig) { // // If config file exists, open it and parse it once so we can // find what to evaluate later. // InitConfigFromFile(); } else { // Add location sections for this record as bonafide sections. if (locationSubPathInputs != null) { foreach (LocationSectionRecord locationSectionRecord in locationSubPathInputs) { // add the file input SectionRecord sectionRecord = EnsureSectionRecord(locationSectionRecord.ConfigKey, true); SectionInput sectionInput = new SectionInput(locationSectionRecord.SectionXmlInfo, locationSectionRecord.ErrorsList); sectionRecord.AddFileInput(sectionInput); // copy the initialization errors to the record if (locationSectionRecord.HasErrors) { this._initErrors.AddSavedLocalErrors(locationSectionRecord.Errors); } } } } } // // Capture all exceptions and include them in initialization errors. // catch (Exception e) { string streamname = (ConfigStreamInfo != null) ? ConfigStreamInfo.StreamName : null; _initErrors.AddError( ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), e, streamname, 0), ExceptionAction.Global); } catch { string streamname = (ConfigStreamInfo != null) ? ConfigStreamInfo.StreamName : null; _initErrors.AddError( ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), null, streamname, 0), ExceptionAction.Global); } }