示例#1
0
        public object Create(object parent, object configContext, XmlNode section)
        {
            Hashtable engines = new Hashtable();

            foreach (XmlNode engineNode in section.SelectNodes("engines/engine"))
            {
                EngineConfig engine = EngineConfig.FromXml(engineNode);
                if (engines.Contains(engine.Name))
                {
                    string msg = string.Format(CultureInfo.InvariantCulture,
                                               "A engine with name '{0}' already exists.",
                                               engine.Name);
#if NET_2_0
                    throw new ConfigurationErrorsException(msg, engineNode);
#else
                    throw new ConfigurationException(msg, engineNode);
#endif
                }
                engines.Add(engine.Name, engine);
            }

            Hashtable connections = new Hashtable();

            foreach (XmlNode connNode in section.SelectNodes("connections/connection"))
            {
                ConnectionConfig conn = ConnectionConfig.FromXml(connNode, engines);
                if (connections.Contains(conn.Name))
                {
                    string msg = string.Format(CultureInfo.InvariantCulture,
                                               "A connection with name '{0}' already exists.",
                                               conn.Name);
#if NET_2_0
                    throw new ConfigurationErrorsException(msg, connNode);
#else
                    throw new ConfigurationException(msg, connNode);
#endif
                }
                connections.Add(conn.Name, conn);
            }

            ConnectionConfig [] c = new ConnectionConfig [connections.Count];
            connections.Values.CopyTo(c, 0);
            return(c);
        }