GetParameter() public method

Returns the config parameter for the given component. Throws an exception if there is no such parameter. If you want to know if the parameter exists, call ParameterExists(...).
public GetParameter ( string component, string parameter ) : string
component string The component or section of the config file, used to /// locate the parameter.
parameter string The name of the config parameter.
return string
Exemplo n.º 1
0
 public OdpSdeStDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate)
     : base(config.GetParameter(component, "Server", null),
            config.GetParameter(component, "User", null),
            GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate),
            config.GetParameterAsInt(component, "Connect_Timeout", null))
 {
 }
Exemplo n.º 2
0
 /// <summary>
 /// Get the config for the field and text to be replaced.
 /// </summary>
 /// <param name="config">The config file to use.</param>
 /// <param name="component">The component to use.  This should have three
 /// parameters: ReplaceField, Find, and ReplaceWith.</param>
 public CandidateTextReplacer(Config config, string component)
 {
     _replaceField = typeof (GeocodeCandidate).GetProperty(config.GetParameter(component, "ReplaceField"));
     _matchRegex = config.GetParameter(component, "Find");
     _replaceWith = config.GetParameter(component, "ReplaceWith");
     MatchCollection matches = Regex.Matches(_replaceWith, "{.*?}");
     _sourceFields = new PropertyInfo[matches.Count];
     for (int i = 0; i < _sourceFields.Length; i++)
     {
         string sourceFieldName = matches[i].Value.TrimStart('{').TrimEnd('}');
         _sourceFields[i] = typeof (GeocodeCandidate).GetProperty(sourceFieldName);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new ScoreNormalizer with the given config.  Specify a "Modifiers" parameter in your config
 /// to weight the scores.  The config is a string in the format "LocatorName:Score|LocatorName:Score".
 /// See the tests for an example
 /// </summary>
 /// <param name="config">An Azavea Config object</param>
 /// <param name="component">The component with the configuration for this normalizer</param>
 public ScoreNormalizer(Config config, string component)
 {
     _scoreModifiers = new Dictionary<string, int>();
     string modifierConfig = config.GetParameter(component, "Modifiers");
     if (!string.IsNullOrEmpty(modifierConfig))
     {
         string[] configs = modifierConfig.Split('|');
         foreach (string s in configs)
         {
             string[] values = s.Split(':');
             if (values.Length == 2)
             {
                 int score;
                 if (int.TryParse(values[1], out score))
                 {
                     _scoreModifiers.Add(values[0], score);
                 }
             }
         }
     }
     if (_scoreModifiers.Count == 0)
     {
         throw new LoggingException("No modifier list in this config");
     }
 }
Exemplo n.º 4
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.º 5
0
 /// <summary>
 /// Create a new Processor with the given configuration
 /// </summary>
 /// <param name="config">An Azavea.Open Config object</param>
 /// <param name="sectionName">The section with the country list required by this processor</param>
 public CountrySelectorProcessor(Config config, string sectionName)
 {
     string myCountryList = config.GetParameter(sectionName, "CountryList");
     if (myCountryList != null)
     {
         _myCountries = new List<string>(myCountryList.Split('|'));
     }
     else throw new LoggingException("No country list in this config");
 }
 /// <summary>
 /// Create a new Processor with the given configuration
 /// </summary>
 /// <param name="config">An Azavea.Open Config object</param>
 /// <param name="sectionName">The section with the country list required by this processor</param>
 public MatchTypeSelectorProcessor(Config config, string sectionName)
 {
     string matchList = config.GetParameter(sectionName, "MatchTypes");
     if (matchList != null)
     {
         _allowedMatchTypes = new List<string>(matchList.Split('|'));
     }
     else throw new LoggingException("No MatchType list in this config");
 }
Exemplo n.º 7
0
 /// <summary>
 /// This method is provided for convenience.  If decryptionDelegate is not null,
 /// will use it to decrypt whatever value is in the config parameter.
 /// </summary>
 /// <param name="config">Config file to get the parameter from.</param>
 /// <param name="component">Section within the config file.</param>
 /// <param name="paramName">Name of the paraneter within the section.</param>
 /// <param name="decryptionDelegate">Method to call to decrypt the parameter.  May be null if using plain text.</param>
 /// <returns></returns>
 protected static string GetDecryptedConfigParameter(Config config,
     string component, string paramName, ConnectionInfoDecryptionDelegate decryptionDelegate)
 {
     string retVal = config.GetParameter(component, paramName, null);
     if ((decryptionDelegate != null) && (!String.IsNullOrEmpty(retVal)))
     {
         retVal = decryptionDelegate.Invoke(retVal);
     }
     return retVal;
 }
Exemplo n.º 8
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;
 }
 /// <exclude />
 public RequestProcessorDummyWithConfig(Config config, string component)
 {
     _doReversing = Convert.ToBoolean(config.GetParameter(component, "DoReversing", "false"));
 }
Exemplo n.º 10
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.º 11
0
        /// <summary>
        /// This constructor reads all the appropriate values from our standard config file
        /// in the normal format.
        /// </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 FirebirdDescriptor(Config config, string component,
            ConnectionInfoDecryptionDelegate decryptionDelegate)
        {
            FbConnectionStringBuilder builder = new FbConnectionStringBuilder();
            Server = config.GetParameter(component, "Server", null);
            if (StringHelper.IsNonBlank(Server))
            {
                builder.DataSource = Server;
            }
            else
            {
                builder.ServerType = FbServerType.Embedded;
                // For the embedded server, we want to disable pooling so we don't wind up locking
                // the file indefinitely.
                builder.Pooling = false;
                _usePooling = false;
            }
            builder.Database = Database = config.GetParameterWithSubstitution(component, "Database", true);
            builder.UserID = User = config.GetParameter(component, "User", null);

            // First make it without a password.
            _cleanConnStr = builder.ToString();
            // Now with the password for the real one.
            Password = GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate);
            builder.Password = Password;
            _connectionStr = builder.ToString();
        }
Exemplo n.º 12
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.");
 }
Exemplo n.º 13
0
 /// <summary>
 /// This constructor reads all the appropriate 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 OleDbDescriptor(Config config, string component,
     ConnectionInfoDecryptionDelegate decryptionDelegate)
     : this(GetTypeFromConfig(config, component),
            config.GetParameter(component, "Provider", null),
            config.GetParameter(component, "Server", null),
            config.GetParameterWithSubstitution(component, "Database", true, null),
            config.GetParameter(component, "User", null),
            GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate),
            config.GetParameterAsInt(component, "Connect_Timeout", null))
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// This constructor reads all the appropriate 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 SQLServerDescriptor(Config config, string component,
     ConnectionInfoDecryptionDelegate decryptionDelegate)
     : this(config.GetParameter(component, "Server", null),
            config.GetParameter(component, "Database", null),
            config.GetParameter(component, "User", null),
            GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate))
 {
 }
Exemplo n.º 15
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 MemoryDescriptor(Config config, string component,
     ConnectionInfoDecryptionDelegate decryptionDelegate)
     : this(config.GetParameter(component, "UID"))
 {
 }
        /// <summary>
        /// This constructor reads all the appropriate values from our standard config file
        /// in the normal format.
        /// </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 PostgreSqlDescriptor(Config config, string component,
            ConnectionInfoDecryptionDelegate decryptionDelegate)
        {
            _server = config.GetParameter(component, "Server");
            _port = config.GetParameter(component, "Port", _port);
            _databaseName = config.GetParameter(component, "Database");
            _user = config.GetParameter(component, "User", null);
            _password = GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate);
            _encoding = config.GetParameter(component, "Encoding", _encoding);

            _connectionStr = MakeConnectionString(_server, _port, _databaseName, _user, _password, _encoding);
            _cleanConnStr = MakeConnectionString(_server, _port, _databaseName, _user, null, _encoding);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Constructor for the Google geocoder source.
 /// </summary>
 /// <param name="config">The config to use to construct the Google geocoder.</param>
 /// <param name="component">The component in the config in which to look for 
 /// the configuration parameters.</param>
 public GoogleGeocoder(Config config, string component)
     : base(config, component)
 {
     _authKey = config.GetParameter(component, "GoogleApiKey");
 }
Exemplo n.º 18
0
 /// <summary>
 /// Creates the geocoder. If the username and password are not set, then the publicly
 /// available interface will be used. This should only be used in *non-commercial* products.
 /// </summary>
 /// <param name="config">The config file we are using.</param>
 /// <param name="sectionName">The config section we are using to look for RequestProcessors and ResponseProcessors.</param>
 public GeocoderUSGeocoder(Config config, string sectionName)
     : base(config, sectionName)
 {
     _username = config.GetParameter(sectionName, "UserName");
     _password = config.GetParameter(sectionName, "Password");
 }