Example #1
0
 public bool Fill(string configName, string key, string data, ClientEndpointInfo info)
 {
     if (string.IsNullOrWhiteSpace(data))
     {
         return(false);
     }
     info.ContractType = Type.GetType(data, false);
     if ((info.ContractType == null) || !info.ContractType.IsInterface)
     {
         return(false);
     }
     try
     {
         info.ClientType = TypeFinder.GetTypes(info.ContractType.Assembly, info.ContractType).FirstOrDefault <Type>();
     }
     catch (Exception exception)
     {
         string log = exception.Message;
         // 写日志............
     }
     if (info.ClientType == null)
     {
         throw new InvalidOperationException(string.Format("您配置接口类型{0}不是Thrift生成的接口类型,请修改{1}节点", data, configName));
     }
     return(true);
 }
Example #2
0
        public ClientEndpointInfo[] Load(IConfigsType dictData)
        {
            var dictionary = new Dictionary <string, ClientEndpointInfo>();

            foreach (string str in dictData.GetKeys())
            {
                Match match = Regex.Match(str, @"^Cicada.Rpc.Client.Endpoints.(\w+).([\w.]+)$", RegexOptions.IgnoreCase);
                if (match.Success && (match.Groups.Count == 3))
                {
                    ClientEndpointInfo info;
                    if (dictionary.ContainsKey(match.Groups[1].Value))
                    {
                        info = dictionary[match.Groups[1].Value];
                    }
                    else
                    {
                        info = new ClientEndpointInfo();
                        dictionary.Add(match.Groups[1].Value, info);
                    }
                    string key = match.Groups[2].Value.ToLower();
                    if (!FillDataStrategies.ContainsKey(key))
                    {
                        throw new InvalidOperationException(string.Format("未知的配置,请检查节点{0}是否配置正确", str));
                    }
                    if (!FillDataStrategies[key].Fill(str, key, dictData.Get(str), info))
                    {
                        throw new InvalidOperationException(string.Format("错误的配置,请检查节点{0}是否配置正确", str));
                    }
                }
            }
            return(dictionary.Values.ToArray <ClientEndpointInfo>());
        }
 public bool Fill(string configName, string key, string data, ClientEndpointInfo info)
 {
     if (!string.IsNullOrWhiteSpace(data))
     {
         info.ServiceRespository = data.Trim();
     }
     return(true);
 }
Example #4
0
 public bool Fill(string configName, string key, string data, ClientEndpointInfo info)
 {
     //string name = string.IsNullOrWhiteSpace(data) ? "direct" : data.Trim();
     //name = name.ToLower();
     //IServiceFinder finder = CicadaFacade.Container.Resolve<IServiceFinder>(name);
     //if (finder == null)
     //{
     //    throw new InvalidOperationException(string.Format("您配置Rpc服务发现类型{0}是无效的,请修改{1}节点", data, configName));
     //}
     //info.ServiceFinderType = name;
     //info.ServiceFinder = finder;
     return(true);
 }
        public bool Fill(string configName, string key, string data, ClientEndpointInfo info)
        {
            int num;

            if (string.IsNullOrWhiteSpace(data))
            {
                info.ClientMaxCollections = 100;
                return(true);
            }
            if (!int.TryParse(data.Trim(), out num))
            {
                throw new InvalidOperationException(string.Format("配置的值{0}不是有效的客户端连接最大连接数,请检查{1}配置项", data, configName));
            }
            info.ClientMaxCollections = num;
            return(true);
        }
 public bool Fill(string configName, string key, string data, ClientEndpointInfo info)
 {
     if (!string.IsNullOrWhiteSpace(data))
     {
         int      num;
         char[]   separator = new char[] { ':' };
         string[] strArray  = data.Trim().Split(separator);
         if (strArray.Length != 2)
         {
             return(false);
         }
         info.Server = strArray[0].Trim();
         if (!int.TryParse(strArray[1].Trim(), out num))
         {
             throw new InvalidOperationException(string.Format("配置的值{0}不是有效的端口号,请检查{1}配置项", data, configName));
         }
         info.Port = num;
     }
     return(true);
 }