Пример #1
0
        /// <summary>
        /// the method load the agent using reflection and return an instance of agent
        /// to the caller
        /// </summary>
        /// <param name="agentName">name of the agent referenced in the configuration file</param>
        /// <returns>an agent object</returns>
        private IConfigurationAgent GetAgent(string agentName)
        {
            XmlNode             agentNode = configurationData.SelectSingleNode("//Agent[@name ='" + agentName + "']");
            Type                type      = Type.GetType(agentNode.Attributes["type"].Value);
            IConfigurationAgent agent     = (IConfigurationAgent)Activator.CreateInstance(type);

            //Initialize method setup the agent object with the parameter information specified
            //in the file that is needed for the agent to do its job
            agent.Initialize(agentNode);
            return(agent);
        }
Пример #2
0
        /// <summary>
        /// 方法使用反射加载代理,并返回一个代理实例
        /// 给调用者
        /// </summary>
        /// <param name="agentName">代理的名称</param>
        /// <returns>返回的代理对象</returns>
        private IConfigurationAgent GetAgent(string agentName)
        {
            //获得该名称的节点
            XmlNode agentNode = configurationData.SelectSingleNode("//Agent[@name ='" + agentName + "']");
            //获得该节点的类型
            Type type = Type.GetType(agentNode.Attributes["type"].Value);
            //创建该类型的代理实例
            IConfigurationAgent agent = (IConfigurationAgent)Activator.CreateInstance(type, null);

            //初始化方法设置的代理对象与指定的参数信息
            //在文件中所需要的代理来完成其工作
            agent.Initialize(agentNode);
            //返回代理对象
            return(agent);
        }