// RefreshFactoryRecord
//
// Refresh the Factory Record for a particular section.
//
private void RefreshFactoryRecord(string configKey) {
Hashtable factoryList = null;
FactoryRecord factoryRecord = null;
ConfigurationSchemaErrors errors;
errors = new ConfigurationSchemaErrors();
// Get Updated Factory List from File
int lineNumber = 0;
try {
using (Impersonate()) {
using (Stream stream = Host.OpenStreamForRead(ConfigStreamInfo.StreamName)) {
if (stream != null) {
ConfigStreamInfo.HasStream = true;
using (XmlUtil xmlUtil = new XmlUtil(stream, ConfigStreamInfo.StreamName, true, errors)) {
try {
factoryList = ScanFactories(xmlUtil);
ThrowIfParseErrors(xmlUtil.SchemaErrors);
}
catch {
lineNumber = xmlUtil.LineNumber;
throw;
}
}
}
}
}
// Add implicit sections to the factory list
if (factoryList == null) {
// But if factoryList isn't found in this config, we still try to
// add implicit sections to an empty factoryList.
factoryList = new Hashtable();
}
AddImplicitSections(factoryList);
if (factoryList != null) {
factoryRecord = (FactoryRecord) factoryList[configKey];
}
}
//
// Guarantee that exceptions contain the name of the stream and an approximate line number if available.
//
// And don't allow frames up the stack to run exception filters while impersonated.
catch (Exception e) {
errors.AddError(
ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), e, ConfigStreamInfo.StreamName, lineNumber),
ExceptionAction.Global);
}
catch {
errors.AddError(
ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_error_loading_XML_file), null, ConfigStreamInfo.StreamName, lineNumber),
ExceptionAction.Global);
}
// Set/Add/Remove Record
// Note that the _factoryRecords hashtable is protected by the hierarchy lock.
if (factoryRecord != null || HasFactoryRecords) {
EnsureFactories()[configKey] = factoryRecord;
}
// Throw accumulated errors
ThrowIfParseErrors(errors);
}