ParameterExists() public method

Method to check if a parameter exists, prior to calling GetParameter (which throws exceptions if you request an invalid parameter).
public ParameterExists ( string component, string parameter ) : bool
component string The component or section of the config file, used to /// locate the parameter.
parameter string The name of the config parameter.
return bool
Exemplo n.º 1
0
 /// <summary>
 /// Get the config for characters to be removed if the defaults aren't good enough.
 /// </summary>
 /// <param name="config">The config file to use.</param>
 /// <param name="component">The component to use.  Only one parameter is
 /// available and it's optional: CharactersToRemove</param>
 public SpecialCharacterRemover(Config config, string component)
 {
     if (config.ParameterExists(component, "CharactersToRemove"))
     {
         _charactersToRemove = config.GetParameter(component, "CharactersToRemove");
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// This is a factory method, that will load the appropriate type of connection
 /// descriptor using the given config.
 /// 
 /// It first searches for config item(s) called "ConnectionConfigSection" and/or
 /// "ConnectionConfig".  (ConnectionConfig should be an "app name" for a config, not a file name).
 /// If present, it will use those to load from another section in this or another
 /// config file.  This allows more dynamic install-time configuration of DB connections.
 /// You may daisy-chain the configuration if you wish.
 /// 
 /// Once in the connection configuration section, it will first search for the "DescriptorClass"
 /// config item, and use that class if specified.  If not, defaults to an OleDbDescriptor
 /// (which means it should be backwards compatible for all our existing config files).
 /// </summary>
 /// <param name="cfg">Config to load the descriptor info from.</param>
 /// <param name="section">What section of that config has the DB connection info in it.</param>
 /// <param name="decryptionDelegate">Method to call to decrypt information, if the actual
 ///                                  connection descriptor type supports decryption.  May be null.</param>
 /// <returns>A fully populated ConnectionDescriptor.</returns>
 public static IConnectionDescriptor LoadFromConfig(Config cfg, string section,
     ConnectionInfoDecryptionDelegate decryptionDelegate)
 {
     if (!cfg.ComponentExists(section))
     {
         throw new BadDaoConfigurationException("Config section " + section +
                                                " does not exist in " + cfg.Application);
     }
     IConnectionDescriptor retVal;
     // First see if we're redirected to another config and/or section.
     if (cfg.ParameterExists(section, "ConnectionConfig") ||
         cfg.ParameterExists(section, "ConnectionConfigSection"))
     {
         string otherName = cfg.GetParameter(section, "ConnectionConfig", cfg.Application);
         string otherSection = cfg.GetParameter(section, "ConnectionConfigSection", section);
         if (_log.IsDebugEnabled)
         {
             _log.Debug("Loading " + section + " connection info from "
                        + otherName + "[" + otherSection + "]");
         }
         // Recurse with different config values.
         retVal = LoadFromConfig(Config.GetConfig(otherName), otherSection, decryptionDelegate);
     }
     else
     {
         // Not overridden, read from this config section.
         // For backwards compatibility, default to using an OleDb descriptor.
         string typeName = cfg.GetParameter(section, "DescriptorClass",
             "Azavea.Open.DAO.OleDb.OleDbDescriptor,Azavea.Open.DAO.OleDb");
         Type[] paramTypes = new Type[] {typeof (Config), typeof (string),
             typeof(ConnectionInfoDecryptionDelegate)};
         Type descType = Type.GetType(typeName);
         if (descType == null)
         {
             throw new BadDaoConfigurationException("DescriptorClass '" + typeName +
                                                    "' was specified, but we were unable to get type info.  Are you missing a DLL?");
         }
         ConstructorInfo constr = descType.GetConstructor(paramTypes);
         if (constr == null)
         {
             throw new BadDaoConfigurationException("DescriptorClass '" + typeName +
                                                    "' was specified, but we were unable to get constructor info.");
         }
         retVal = (IConnectionDescriptor)constr.Invoke(new object[] { cfg, section, decryptionDelegate });
     }
     return retVal;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Populates the descriptor's values from a config file.
 /// </summary>
 /// <param name="config">Config to get params from.</param>
 /// <param name="component">Section of the config XML to look in for db params.</param>
 /// <param name="decryptionDelegate">Delegate to call to decrypt password fields.
 ///                                  May be null if passwords are in plain text.</param>
 public CsvDescriptor(Config config, string component,
     ConnectionInfoDecryptionDelegate decryptionDelegate)
     : this(CsvConnectionType.Unknown,
            config.GetParameterWithSubstitution(component, "Path", true),
            null, null,
            config.ParameterExists(component, "OutputQuoteLevel")
                ? (CsvQuoteLevel) Enum.Parse(typeof (CsvQuoteLevel),config.GetParameter(component, "OutputQuoteLevel"))
                : CsvQuoteLevel.QuoteStrings)
 {
 }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the type based on a couple optional parameters in the DB config file.
 /// </summary>
 /// <param name="config">Config to get params from.</param>
 /// <param name="component">Section of the config XML to look in for db params.</param>
 /// <returns>The type as specified in the config file, or throws an exception if
 ///          there is no type correctly specified.</returns>
 private static DatabaseType GetTypeFromConfig(Config config, string component)
 {
     if (config.ParameterExists(component, "Type"))
     {
         return (DatabaseType)Enum.Parse(typeof(DatabaseType), config.GetParameter(component, "Type").Trim().ToUpper());
     }
     if (config.ParameterExists(component, "Provider"))
     {
         return GuessTypeFromProvider(config.GetParameter(component, "Provider").Trim());
     }
     throw new BadDaoConfigurationException(
         "Database connection config for '" + component + "' is missing both type and provider.");
 }