Пример #1
0
        public static ServiceConfig GetConfig(string serviceName)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(CONST.CONFIG_PATH);
            XmlNode serviceNode = xmlDoc.SelectSingleNode("//Service[@name='" + serviceName + "']");

            if (serviceNode == null)
            {
                throw new Exception("Not find xml node with " + serviceName + " service.");
            }
            ServiceConfig config = new ServiceConfig();

            config.ServiceName = serviceNode.Attributes["name"].Value;
            config.ServiceID   = int.Parse(serviceNode.Attributes["id"].Value);
            var attMaxThreadCount = serviceNode.Attributes["maxThreadCount"];

            if (attMaxThreadCount != null)
            {
                config.MaxThreadCount = int.Parse(attMaxThreadCount.Value);
            }
            else
            {
                config.MaxThreadCount = CONST.DEFAULT_MAX_THREAD_COUNT;
            }
            XmlNode xnSocketPool = serviceNode.SelectSingleNode("Commmunication/SocketPool");

            config.SocketPool = new SocketPoolProfile(xnSocketPool);
            XmlNode xnProtocol = serviceNode.SelectSingleNode("Commmunication/Protocol");

            config.Protocol = new ProtocolProfile(xnProtocol);
            XmlNodeList          xnServers = serviceNode.SelectNodes("Loadbalance/Server/add");
            List <ServerProfile> servers   = new List <ServerProfile>();

            foreach (XmlNode xnServer in xnServers)
            {
                servers.Add(new ServerProfile(xnServer));
            }
            config.Servers     = servers;
            config.ServiceName = serviceName;
            return(config);
        }
Пример #2
0
 public static ServiceConfig GetConfig(string serviceName)
 {
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load(CONST.CONFIG_PATH);
     XmlNode serviceNode = xmlDoc.SelectSingleNode("//Service[@name='" + serviceName + "']");
     if (serviceNode == null)
         throw new Exception("Not find xml node with " + serviceName + " service.");
     ServiceConfig config = new ServiceConfig();
     config.ServiceName = serviceNode.Attributes["name"].Value;
     config.ServiceID = int.Parse(serviceNode.Attributes["id"].Value);
     var attMaxThreadCount = serviceNode.Attributes["maxThreadCount"];
     if (attMaxThreadCount != null)
     {
         config.MaxThreadCount = int.Parse(attMaxThreadCount.Value);
     }
     else
     {
         config.MaxThreadCount = CONST.DEFAULT_MAX_THREAD_COUNT;
     }
     XmlNode xnSocketPool = serviceNode.SelectSingleNode("Commmunication/SocketPool");
     config.SocketPool = new SocketPoolProfile(xnSocketPool);
     XmlNode xnProtocol = serviceNode.SelectSingleNode("Commmunication/Protocol");
     config.Protocol = new ProtocolProfile(xnProtocol);
     XmlNodeList xnServers = serviceNode.SelectNodes("Loadbalance/Server/add");
     List<ServerProfile> servers = new List<ServerProfile>();
     foreach (XmlNode xnServer in xnServers)
     {
         servers.Add(new ServerProfile(xnServer));
     }
     config.Servers = servers;
     config.ServiceName = serviceName;
     return config;
 }