GetParametersAsList() public method

Gets you a list of all the parameters for the component as key-value-pairs. This preserves the order of parameters from the config file.
public GetParametersAsList ( string component ) : string>>.IList
component string The component or section of the config file, used to /// locate the parameter.
return string>>.IList
示例#1
0
        /// <summary>
        /// This handles running through the configuration and getting the request
        /// and response processors.
        /// </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>
        private void GetProcessors(Config config, string sectionName)
        {
            if (config.ComponentExists(sectionName))
            {
                IList<KeyValuePair<string, string>> kvps = config.GetParametersAsList(sectionName);
                foreach (KeyValuePair<string, string> kvp in kvps)
                {
                    string typeName = kvp.Value;
                    Type processorType = Type.GetType(typeName);
                    if (processorType != null && typeof(IProcessor).IsAssignableFrom(processorType))
                    {
                        ConstructorInfo ci = processorType.GetConstructor(new [] {typeof (Config), typeof (string)});
                        IProcessor p;
                        if (ci != null)
                        {
                            p = (IProcessor) ci.Invoke(new object[] {config, kvp.Key});
                        }
                        else
                        {
                            ci = processorType.GetConstructor(new Type[] {});
                            if (ci == null)
                            {
                                throw new ConfigurationErrorsException("Processor '" + typeName +
                                                                       "' was specified, but we were unable to get constructor info.");
                            }
                            p = (IProcessor) ci.Invoke(new object[] {});
                        }

                        // At this point we have a processor object.  Add it to the dictionary.
                        if (p as IRequestProcessor != null)
                        {
                            _processors[typeof (IRequestProcessor)].Add(p);
                        }
                        if (p as IResponseProcessor != null)
                        {
                            _processors[typeof (IResponseProcessor)].Add(p);
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Constructs the geocoder, reading the list of sources from the specified
        /// section of the given config.
        /// </summary>
        /// <param name="config">Config object with the geocoder configuration.</param>
        /// <param name="sectionName">Section of the config that the geocoding sources are in.</param>
        public Geocoder(Config config, string sectionName)
            : base(config, sectionName)
        {
            IList<KeyValuePair<string, string>> sourceLines = config.GetParametersAsList(sectionName);
            foreach (KeyValuePair<string,string> sourceLine in sourceLines)
            {
                try
                {
                    // Key is the config section name for that geocoder source,
                    string sourceConfigSection = sourceLine.Key;
                    // value is the class name.
                    string typeName = sourceLine.Value;
                    Type geocoderSourceType = Type.GetType(typeName);
                    if (geocoderSourceType == null)
                    {
                        throw new ConfigurationErrorsException("GeocoderSourceClass '" + typeName +
                                                               "' was specified, but we were unable to get type info.  Are you missing a DLL?");
                    }

                    Type[] constructorParamTypes = new[] {typeof (Config), typeof (string)};
                    ConstructorInfo constr = geocoderSourceType.GetConstructor(constructorParamTypes);
                    if (constr == null)
                    {
                        throw new ConfigurationErrorsException("GeocoderSourceClass '" + typeName +
                                                               "' was specified, but we were unable to get constructor info.");
                    }

                    GeocoderSource source = (GeocoderSource) constr.Invoke(new object[] {config, sourceConfigSection});
                    _geocoderSources.Add(source);
                }
                catch (Exception e)
                {
                    throw new LoggingException("Unable to load geocoder source '" +
                        sourceLine.Key + "', '" + sourceLine.Value + "'.", e);
                }
            }
            if (_geocoderSources.Count == 0)
            {
                throw new LoggingException("No geocoding sources specified in section " + sectionName +
                    ", unable to construct geocoder.");
            }
        }