예제 #1
0
        /// <summary>
        /// parse connectionstring as ConsulRemoteServiceConfig
        /// </summary>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static ConsulRemoteServiceConfig Parse(string connectionString)
        {
            try
            {
                var keyValueDict = new Dictionary <string, object>();
                foreach (var kv in connectionString.Split(';'))
                {
                    var keyValue = kv.Split('=');
                    keyValueDict[keyValue[0]] = keyValue[1];
                }

                var config = new ConsulRemoteServiceConfig();
                foreach (var p in config.GetType().GetProperties())
                {
                    if (p.CanRead && p.CanWrite)
                    {
                        if (keyValueDict.ContainsKey(p.Name))
                        {
                            p.SetValue(config, Convert.ChangeType(keyValueDict[p.Name], p.PropertyType));
                        }
                    }
                }

                return(config);
            }
            catch (Exception e)
            {
                throw new ArgumentException("解析connectionstring错误", e);
            }
        }
예제 #2
0
        public GRPCChannelPoolManager(ConsulRemoteServiceConfig config, ClientAgentOption option)
        {
            this.clientConfig = config;
            this.ClientAgentOption = option;

            InitGrpcChannel();
        }