Azavea.Open.Common.Config.ComponentExists C# (CSharp) Method

ComponentExists() public method

Method to check if a config section exists for a component, prior to calling GetConfigXml or GetParametersAsHashTable (which throw exceptions if you request an invalid component name).
public ComponentExists ( string component ) : bool
component string The component or section of the config file, used to /// locate the parameter.
return bool
        public bool ComponentExists(string component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component", "Component cannot be null.");
            }
            try
            {
                if (_paramsByComponent.ContainsKey(component))
                {
                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                ReThrowException("Unable to check if component exists.",
                    new object[] { ConfigFile, component }, ex);
                // that throws, but the compiler wants a return statement.
                return false;
            }
        }

Usage Example

Ejemplo n.º 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);
                        }
                    }
                }
            }
        }
All Usage Examples Of Azavea.Open.Common.Config::ComponentExists