internal static ConfigurationErrorsException WrapAsConfigException(string outerMessage, Exception e, IConfigErrorInfo errorInfo) { return(errorInfo != null ? WrapAsConfigException(outerMessage, e, errorInfo.Filename, errorInfo.LineNumber) : WrapAsConfigException(outerMessage, e, null, 0)); }
internal static ConfigurationErrorsException WrapAsConfigException(string outerMessage, Exception e, IConfigErrorInfo errorInfo) { return errorInfo != null ? WrapAsConfigException(outerMessage, e, errorInfo.Filename, errorInfo.LineNumber) : WrapAsConfigException(outerMessage, e, null, 0); }
private static string GetUnsafeConfigErrorInfoFilename(IConfigErrorInfo errorInfo) { if (errorInfo != null) { return(errorInfo.Filename); } return(null); }
static internal ConfigurationErrorsException WrapAsConfigException(string outerMessage, Exception e, IConfigErrorInfo errorInfo) { if (errorInfo != null) { return WrapAsConfigException(outerMessage, e, errorInfo.Filename, errorInfo.LineNumber); } else { return WrapAsConfigException(outerMessage, e, null, 0); } }
private static int GetConfigErrorInfoLineNumber(IConfigErrorInfo errorInfo) { if (errorInfo != null) { return(errorInfo.LineNumber); } return(0); }
/// <inheritdoc /> protected override void DeserializeSection(XmlReader reader) { // Grab file path IConfigErrorInfo errorInfo = reader as IConfigErrorInfo; FilePath = errorInfo != null ? errorInfo.Filename : CurrentConfiguration?.FilePath; base.DeserializeSection(reader); }
public virtual void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition)) { throw new ConfigurationErrorsException("The section can't be defined in this file (the allowed definition context is '" + allowDefinition + "').", errorInfo.Filename, errorInfo.LineNumber); } }
private int GetLineNumber(XmlReader reader) { IConfigErrorInfo err = reader as IConfigErrorInfo; if (err != null) { return((int)err.LineNumber); } return(0); }
public static int GetXmlNodeLineNumber(XmlNode node) { IConfigErrorInfo info = node as IConfigErrorInfo; if (info != null) { return(info.LineNumber); } return(0); }
public static int GetXmlNodeLineNumber(XmlNode node) { IConfigErrorInfo configNode = node as IConfigErrorInfo; if (configNode != null) { return(configNode.LineNumber); } return(0); }
private static string GetUnsafeXmlNodeFilename(XmlNode node) { IConfigErrorInfo info = node as IConfigErrorInfo; if (info != null) { return(info.Filename); } return(string.Empty); }
private int GetLineNumber(XmlReader reader) { IConfigErrorInfo info = reader as IConfigErrorInfo; if (info != null) { return(info.LineNumber); } return(0); }
private string GetFilename(XmlReader reader) { IConfigErrorInfo info = reader as IConfigErrorInfo; if (info != null) { return(info.Filename); } return(""); }
private string GetFilename(XmlReader reader) { IConfigErrorInfo err = reader as IConfigErrorInfo; if (err != null) { return((string)err.Filename); } return(""); }
private static string GetUnsafeXmlNodeFilename(XmlNode node) { IConfigErrorInfo configNode = node as IConfigErrorInfo; if (configNode != null) { return(configNode.Filename); } return(string.Empty); }
public object Create(object parent, object configContext, XmlNode section) { object result = parent; XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file"); if (fileAttribute == null && fileAttribute.Value.Length == 0) { return(new NameValueSectionHandler().Create(result, null, section)); } IConfigErrorInfo configXmlNode = fileAttribute as IConfigErrorInfo; if (configXmlNode == null) { return(null); } string directory = Path.GetDirectoryName(configXmlNode.Filename); string absoluteFilePath = Path.GetFullPath(directory + fileAttribute.Value); if (!File.Exists(absoluteFilePath)) { throw new ConfigurationErrorsException(string.Format("external config file: {0} does not exists", absoluteFilePath)); } var configXmlDocument = new ConfigXmlDocument(); try { configXmlDocument.Load(absoluteFilePath); } catch (XmlException e) { throw new ConfigurationErrorsException(e.Message, e, absoluteFilePath, e.LineNumber); } if (section.Name != configXmlDocument.DocumentElement.Name) { throw new ConfigurationErrorsException(string.Format("Section name '{0}' in app.config does not match section name '{1}' in file '{2}'", section.Name, configXmlDocument.DocumentElement.Name, absoluteFilePath)); } var nodeToDecrypt = configXmlDocument.DocumentElement["EncryptedData"]; if (nodeToDecrypt == null) { throw new ConfigurationErrorsException(string.Format("External encrypted file {0} does not contain EncryptedData element", absoluteFilePath)); } var protectionProvider = new DpapiProtectedConfigurationProvider(); var decryptedConfigSection = protectionProvider.Decrypt(nodeToDecrypt); result = new NameValueSectionHandler().Create(result, null, decryptedConfigSection); return(result); }
public object Create(object parent, object configContext, XmlNode section) { object result = parent; // parse XML XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file"); result = NameValueSectionHandler.CreateStatic(result, section); if (fileAttribute != null && fileAttribute.Value.Length != 0) { string filename = null; filename = fileAttribute.Value; IConfigErrorInfo configXmlNode = fileAttribute as IConfigErrorInfo; if (configXmlNode == null) { return(null); } string configFile = configXmlNode.Filename; string directory = Path.GetDirectoryName(configFile); string sourceFileFullPath = Path.Combine(directory, filename); if (File.Exists(sourceFileFullPath)) { ConfigXmlDocument doc = new ConfigXmlDocument(); try { doc.Load(sourceFileFullPath); } catch (XmlException e) { throw new ConfigurationErrorsException(e.Message, e, sourceFileFullPath, e.LineNumber); } if (section.Name != doc.DocumentElement.Name) { throw new ConfigurationErrorsException( SR.Format(SR.Config_name_value_file_section_file_invalid_root, section.Name), doc.DocumentElement); } result = NameValueSectionHandler.CreateStatic(result, doc.DocumentElement); } } return(result); }
private void LoadFromConfigXmlReader(ConfigXmlReader reader) { IConfigErrorInfo err = (IConfigErrorInfo)reader; _filename = err.Filename; _lineOffset = err.LineNumber + 1; try { _reader = reader; base.Load(_reader); } finally { if (_reader != null) { _reader.Close(); _reader = null; } } }
private void LoadFromConfigXmlReader(ConfigXmlReader reader) { IConfigErrorInfo info = reader; this._filename = info.Filename; this._lineOffset = info.LineNumber + 1; try { this._reader = reader; base.Load(this._reader); } finally { if (this._reader != null) { this._reader.Close(); this._reader = null; } } }
public object Create(object parent, object configContext, XmlNode section) { object obj2 = parent; XmlNode node = section.Attributes.RemoveNamedItem("file"); obj2 = NameValueSectionHandler.CreateStatic(obj2, section); if ((node == null) || (node.Value.Length == 0)) { return(obj2); } string str = null; str = node.Value; IConfigErrorInfo info = node as IConfigErrorInfo; if (info == null) { return(null); } string path = Path.Combine(Path.GetDirectoryName(info.Filename), str); if (!File.Exists(path)) { return(obj2); } ConfigXmlDocument document = new ConfigXmlDocument(); try { document.Load(path); } catch (XmlException exception) { throw new ConfigurationErrorsException(exception.Message, exception, path, exception.LineNumber); } if (section.Name != document.DocumentElement.Name) { throw new ConfigurationErrorsException(System.SR.GetString("Config_name_value_file_section_file_invalid_root", new object[] { section.Name }), document.DocumentElement); } return(NameValueSectionHandler.CreateStatic(obj2, document.DocumentElement)); }
public virtual void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { host.VerifyDefinitionAllowed(configPath, allowDefinition, allowExeDefinition, errorInfo); }
private int GetLineNumber(XmlReader reader) { IConfigErrorInfo err = reader as IConfigErrorInfo; return(err?.LineNumber ?? 0); }
public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition)) { switch (allowExeDefinition) { case ConfigurationAllowExeDefinition.MachineOnly: throw new ConfigurationErrorsException( SR.GetString(SR.Config_allow_exedefinition_error_machine), errorInfo); case ConfigurationAllowExeDefinition.MachineToApplication: throw new ConfigurationErrorsException( SR.GetString(SR.Config_allow_exedefinition_error_application), errorInfo); case ConfigurationAllowExeDefinition.MachineToRoamingUser: throw new ConfigurationErrorsException( SR.GetString(SR.Config_allow_exedefinition_error_roaminguser), errorInfo); default: // If we have extended ConfigurationAllowExeDefinition // make sure to update this switch accordingly throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed"); } } }
public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { if (!this.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition)) { ConfigurationAllowExeDefinition definition = allowExeDefinition; if (definition != ConfigurationAllowExeDefinition.MachineOnly) { if (definition == ConfigurationAllowExeDefinition.MachineToApplication) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_application"), errorInfo); } if (definition == ConfigurationAllowExeDefinition.MachineToRoamingUser) { throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_roaminguser"), errorInfo); } throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed"); } throw new ConfigurationErrorsException(System.Configuration.SR.GetString("Config_allow_exedefinition_error_machine"), errorInfo); } }
// Get file and linenumber from an IConfigErrorInfo private static int GetConfigErrorInfoLineNumber(IConfigErrorInfo errorInfo) { return(errorInfo?.LineNumber ?? 0); }
internal ConfigurationErrorsException(string message, Exception inner, IConfigErrorInfo errorInfo) : this(message, inner, GetConfigErrorInfoFilename(errorInfo), GetConfigErrorInfoLineNumber(errorInfo)) { }
static internal string NormalizeConfigSource(string configSource, IConfigErrorInfo errorInfo) { if (String.IsNullOrEmpty(configSource)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_invalid_format), errorInfo); } string trimmedConfigSource = configSource.Trim(); if (trimmedConfigSource.Length != configSource.Length) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_invalid_format), errorInfo); } if (configSource.IndexOf('/') != -1) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_invalid_chars), errorInfo); } if (String.IsNullOrEmpty(configSource) || System.IO.Path.IsPathRooted(configSource)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_source_invalid_format), errorInfo); } return configSource; }
protected void ValidateUniqueChildConfigSource( string configKey, string configSourceStreamName, string configSourceArg, IConfigErrorInfo errorInfo) { // // Detect if a parent config file is using the same config source stream. // BaseConfigurationRecord current; if (IsLocationConfig) { current = _parent._parent; } else { current = _parent; } while (!current.IsRootConfig) { lock (current) { if (current.ConfigStreamInfo.HasStreamInfos) { StreamInfo streamInfo = (StreamInfo) current.ConfigStreamInfo.StreamInfos[configSourceStreamName]; if (streamInfo != null) { throw new ConfigurationErrorsException( SR.GetString(SR.Config_source_parent_conflict, configSourceArg), errorInfo); } } } current = current.Parent; } }
private static string GetConfigErrorInfoFilename(IConfigErrorInfo errorInfo) { return errorInfo?.Filename; }
// Get file and linenumber from an IConfigErrorInfo private static int GetConfigErrorInfoLineNumber(IConfigErrorInfo errorInfo) { return errorInfo?.LineNumber ?? 0; }
public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { if (!this.IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition)) { ConfigurationAllowDefinition definition = allowDefinition; if (definition != ConfigurationAllowDefinition.MachineOnly) { if (definition == ConfigurationAllowDefinition.MachineToWebRoot) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Config_allow_definition_error_webroot"), errorInfo.Filename, errorInfo.LineNumber); } if (definition == ConfigurationAllowDefinition.MachineToApplication) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Config_allow_definition_error_application"), errorInfo.Filename, errorInfo.LineNumber); } throw System.Web.Util.ExceptionUtil.UnexpectedError("WebConfigurationHost::VerifyDefinitionAllowed"); } throw new ConfigurationErrorsException(System.Web.SR.GetString("Config_allow_definition_error_machine"), errorInfo.Filename, errorInfo.LineNumber); } }
static internal string ValidateProtectionProviderAttribute(string protectionProvider, IConfigErrorInfo errorInfo) { if (String.IsNullOrEmpty(protectionProvider)) { throw new ConfigurationErrorsException(SR.GetString(SR.Protection_provider_invalid_format), errorInfo); } return protectionProvider; }
private static int GetConfigErrorInfoLineNumber(IConfigErrorInfo errorInfo) { if (errorInfo != null) { return errorInfo.LineNumber; } return 0; }
// Return null if the subPath represents the current directory, for example: // path="" // path=" " // path="." // path="./" internal static string NormalizeLocationSubPath(string subPath, IConfigErrorInfo errorInfo) { // if subPath is null or empty, it is the current dir if (String.IsNullOrEmpty(subPath)) return null; // if subPath=".", it is the current dir if (subPath == ".") return null; // do not allow whitespace in front of subPath, as the OS // handles beginning and trailing whitespace inconsistently string trimmedSubPath = subPath.TrimStart(); if (trimmedSubPath.Length != subPath.Length) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_location_path_invalid_first_character), errorInfo); } // do not allow problematic starting characters if (invalidFirstSubPathCharacters.IndexOf(subPath[0]) != -1) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_location_path_invalid_first_character), errorInfo); } // do not allow whitespace at end of subPath, as the OS // handles beginning and trailing whitespace inconsistently trimmedSubPath = subPath.TrimEnd(); if (trimmedSubPath.Length != subPath.Length) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_location_path_invalid_last_character), errorInfo); } // the file system ignores trailing '.', '\', or '/', so do not allow it in a location subpath specification if (invalidLastSubPathCharacters.IndexOf(subPath[subPath.Length-1]) != -1) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_location_path_invalid_last_character), errorInfo); } // combination of URI reserved characters and OS invalid filename characters, minus / (allowed reserved character) if (subPath.IndexOfAny(s_invalidSubPathCharactersArray) != -1) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_location_path_invalid_character), errorInfo); } return subPath; }
internal ConfigurationErrorsException(string message, IConfigErrorInfo errorInfo) : this(message, null, GetUnsafeConfigErrorInfoFilename(errorInfo), GetConfigErrorInfoLineNumber(errorInfo)) { }
// Check if the section name contains reserved words from the config system, // and is a valid name for an XML Element. static protected void VerifySectionName(string name, IConfigErrorInfo errorInfo, bool allowImplicit) { if (String.IsNullOrEmpty(name)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_invalid), errorInfo); } // must be a valid name in xml, so that it can be used as an element // n.b. - it also excludes forward slash '/' try { XmlConvert.VerifyName(name); } // Do not let the exception propagate as an XML exception, // for we want errors in the section name to be treated as local errors, // not global ones. catch (Exception e) { throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_tag_name_invalid), e, errorInfo); } catch { throw ExceptionUtil.WrapAsConfigException(SR.GetString(SR.Config_tag_name_invalid), null, errorInfo); } if (IsImplicitSection(name)) { if (allowImplicit) { // avoid test below for strings starting with "config" return; } else { throw new ConfigurationErrorsException(SR.GetString(SR.Cannot_declare_or_remove_implicit_section, name), errorInfo); } } if (StringUtil.StartsWith(name, "config")) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_cannot_begin_with_config), errorInfo); } if (name == KEYWORD_LOCATION) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_cannot_be_location), errorInfo); } }
public virtual void VerifyDefinitionAllowed(string configPath, System.Configuration.ConfigurationAllowDefinition allowDefinition, System.Configuration.ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) {}
// VerifyDefinitionAllowed // // Verify that the Definition is allowed at this // place. // // For example, if this config record is an application then // make sure the section say's it can be defined in an // application // private void VerifyDefinitionAllowed(FactoryRecord factoryRecord, string configPath, IConfigErrorInfo errorInfo) { Host.VerifyDefinitionAllowed(configPath, factoryRecord.AllowDefinition, factoryRecord.AllowExeDefinition, errorInfo); }
private static string GetConfigErrorInfoFilename(IConfigErrorInfo errorInfo) { return(errorInfo?.Filename); }
// VerifySectionUnlocked // // Verify the section we have defined is unlocked // protected void VerifySectionUnlocked(string configKey, IConfigErrorInfo configErrorInfo) { if (IsSectionLocked(configKey)) { throw new ConfigurationErrorsException(SR.GetString(SR.Config_section_locked), configErrorInfo); } }
void IInternalConfigHost.VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { throw new NotImplementedException(); }
// Normalize a locationSubpath argument string IInternalConfigConfigurationFactory.NormalizeLocationSubPath(string subPath, IConfigErrorInfo errorInfo) { return BaseConfigurationRecord.NormalizeLocationSubPath(subPath, errorInfo); }
public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition)) { switch (allowExeDefinition) { case ConfigurationAllowExeDefinition.MachineOnly: throw new ConfigurationErrorsException( SR.Config_allow_exedefinition_error_machine, errorInfo); case ConfigurationAllowExeDefinition.MachineToApplication: throw new ConfigurationErrorsException( SR.Config_allow_exedefinition_error_application, errorInfo); case ConfigurationAllowExeDefinition.MachineToRoamingUser: throw new ConfigurationErrorsException( SR.Config_allow_exedefinition_error_roaminguser, errorInfo); default: // If we have extended ConfigurationAllowExeDefinition // make sure to update this switch accordingly throw ExceptionUtil.UnexpectedError("ClientConfigurationHost::VerifyDefinitionAllowed"); } } }
void IInternalConfigHost.VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { }
private string GetFilename(XmlReader reader) { IConfigErrorInfo err = reader as IConfigErrorInfo; return(err != null ? err.Filename : ""); }
public override void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { if (!IsDefinitionAllowed(configPath, allowDefinition, allowExeDefinition)) { switch (allowDefinition) { case ConfigurationAllowDefinition.MachineOnly: throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_machine), errorInfo.Filename, errorInfo.LineNumber); case ConfigurationAllowDefinition.MachineToWebRoot: throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_webroot), errorInfo.Filename, errorInfo.LineNumber); case ConfigurationAllowDefinition.MachineToApplication: throw new ConfigurationErrorsException(SR.GetString(SR.Config_allow_definition_error_application), errorInfo.Filename, errorInfo.LineNumber); default: // If we have extended ConfigurationAllowDefinition // make sure to update this switch accordingly throw ExceptionUtil.UnexpectedError("WebConfigurationHost::VerifyDefinitionAllowed"); } } }
string IInternalConfigConfigurationFactory.NormalizeLocationSubPath(string subPath, IConfigErrorInfo errorInfo) { return BaseConfigurationRecord.NormalizeLocationSubPath(subPath, errorInfo); }
public string NormalizeLocationSubPath(string subPath, IConfigErrorInfo errorInfo) { return(subPath); }
private static string GetUnsafeConfigErrorInfoFilename(IConfigErrorInfo errorInfo) { if (errorInfo != null) { return errorInfo.Filename; } return null; }
public virtual void VerifyDefinitionAllowed(string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { Host.VerifyDefinitionAllowed(configPath, allowDefinition, allowExeDefinition, errorInfo); }
public virtual void VerifyDefinitionAllowed (string configPath, ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition, IConfigErrorInfo errorInfo) { if (!IsDefinitionAllowed (configPath, allowDefinition, allowExeDefinition)) throw new ConfigurationErrorsException ("The section can't be defined in this file (the allowed definition context is '" + allowDefinition + "').", errorInfo.Filename, errorInfo.LineNumber); }
// // private void ValidateUniqueConfigSource( string configKey, string configSourceStreamName, string configSourceArg, IConfigErrorInfo errorInfo) { // // Detect if another section in this file is using the same configSource // with has a different section name. // lock (this) { if (ConfigStreamInfo.HasStreamInfos) { StreamInfo streamInfo = (StreamInfo) ConfigStreamInfo.StreamInfos[configSourceStreamName]; if (streamInfo != null && streamInfo.SectionName != configKey) { throw new ConfigurationErrorsException( SR.GetString(SR.Config_source_cannot_be_shared, configSourceArg), errorInfo); } } } ValidateUniqueChildConfigSource(configKey, configSourceStreamName, configSourceArg, errorInfo); }
public string NormalizeLocationSubPath (string subPath, IConfigErrorInfo errorInfo) { return subPath; }