Пример #1
0
        public static ESBConfig ReadConfig()
        {
            if (_esbConfig != null)
            {
                return(_esbConfig);
            }
            if (!File.Exists(configfile))
            {
                string configfile2 = AppDomain.CurrentDomain.BaseDirectory + "ESBConfig.xml";
                if (!File.Exists(configfile2))
                {
                    throw new Exception(string.Format("未找到ESBConfig配置文件,路径:{0} 和路径 {1}", configfile, configfile2));
                }
                else
                {
                    configfile = configfile2;
                }
            }


            _esbConfig = SerializerHelper.DeSerializerFile <ESBConfig>(configfile, true);
            if (_esbConfig.ESBServer.IndexOf('.') == -1 &&
                _esbConfig.ESBServer.IndexOf(':') == -1)
            {
                var ipaddress = System.Net.Dns.GetHostAddresses(_esbConfig.ESBServer);
                if (ipaddress == null)
                {
                    throw new Exception("配置服务地址无效。");
                }

                _esbConfig.ESBServer = ipaddress.FirstOrDefault(p => p.AddressFamily != AddressFamily.InterNetworkV6).ToString();
            }

            return(_esbConfig);
        }