Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name">name of Service<para>if Registry will be use, Service Name must be set</para></param>
        /// <param name="group"></param>
        /// <param name="address"></param>
        /// <returns></returns>
        public RpcConfigBuilder UseClient <TClient>(string name, string group, string address)
        {
            var item = new ClientConfigItem(name, typeof(TClient), address)
            {
                Group   = group,
                Address = address
            };

            return(UseClients(item));
        }
Пример #2
0
        // ReSharper disable once FunctionComplexityOverflow
        private static void InitializeClientConfig(IConfiguration config, RpcConfig instance)
        {
            var clientsNode = config.GetSection("clients");

            if (clientsNode != null)
            {
                var environment = clientsNode["environment"];
                //instance.ClientEnvironment = !string.IsNullOrWhiteSpace(environment) ? environment : instance.Environment;
                if (instance.Client == null)
                {
                    instance.Client = new ClientConfig();
                }

                var clients = clientsNode.GetChildren();
                foreach (var item in clients)
                {
                    var name    = item["name"];                  // GetAttribute("name", item);
                    var address = item["address"];               //GetAttribute("path", item);
                    var type    = item["type"];                  //GetAttribute("type", item);
                    var env     = item["environment"];           //GetAttribute("type", item);
                    //var nameSpace = item["namespace"]; // GetAttribute("namespace", item);

                    if (string.IsNullOrEmpty(name))
                    {
                        throw new RpcConfigException("name of RpcLite configuration client node can't be null or empty");
                    }
                    //if (string.IsNullOrEmpty(path))
                    //	throw new ConfigurationErrorsException("path of RpcLite configuration node can't be null or empty");
                    if (string.IsNullOrEmpty(type))
                    {
                        throw new RpcConfigException(string.Format("type of RpcLite configuration client node '{0}' can't be null or empty", name));
                    }
                    //if (string.IsNullOrEmpty(nameSpace))
                    //	throw new RpcConfigException(string.Format("namespace of RpcLite configuration client node '{0}' can't be null or empty", name));

                    var serviceConfigItem = new ClientConfigItem
                    {
                        Name = name,
                        Type = type,
                        //TypeName = typeName,
                        //AssemblyName = assemblyName,
                        Address = address,
                        //Namespace = nameSpace,
                        Group = string.IsNullOrWhiteSpace(env) ? environment : env,
                    };
                    instance.Client.Clients.Add(serviceConfigItem);
                }
            }
        }
Пример #3
0
        // ReSharper disable once FunctionComplexityOverflow
        private static void InitializeClientConfig(IConfiguration config, RpcConfig instance)
        {
            var clientsNode = config.GetSection("clients");
            if (clientsNode != null)
            {
                var environment = clientsNode["environment"];
                //instance.ClientEnvironment = !string.IsNullOrWhiteSpace(environment) ? environment : instance.Environment;
                if (instance.Client == null) instance.Client = new ClientConfig();

                var clients = clientsNode.GetChildren();
                foreach (var item in clients)
                {
                    var name = item["name"]; // GetAttribute("name", item);
                    var address = item["address"]; //GetAttribute("path", item);
                    var type = item["type"]; //GetAttribute("type", item);
                    var env = item["environment"]; //GetAttribute("type", item);
                    //var nameSpace = item["namespace"]; // GetAttribute("namespace", item);

                    if (string.IsNullOrEmpty(name))
                        throw new RpcConfigException("name of RpcLite configuration client node can't be null or empty");
                    //if (string.IsNullOrEmpty(path))
                    //	throw new ConfigurationErrorsException("path of RpcLite configuration node can't be null or empty");
                    if (string.IsNullOrEmpty(type))
                        throw new RpcConfigException(string.Format("type of RpcLite configuration client node '{0}' can't be null or empty", name));
                    //if (string.IsNullOrEmpty(nameSpace))
                    //	throw new RpcConfigException(string.Format("namespace of RpcLite configuration client node '{0}' can't be null or empty", name));

                    var serviceConfigItem = new ClientConfigItem
                    {
                        Name = name,
                        Type = type,
                        //TypeName = typeName,
                        //AssemblyName = assemblyName,
                        Address = address,
                        //Namespace = nameSpace,
                        Group = string.IsNullOrWhiteSpace(env) ? environment : env,
                    };
                    instance.Client.Clients.Add(serviceConfigItem);
                }
            }
        }
Пример #4
0
        // ReSharper disable once FunctionComplexityOverflow
        private static void InitializeClientConfig(IConfiguration config, RpcConfig instance)
        {
            var clientNode = config.GetSection("client");

            if (clientNode?.GetChildren()?.Any() != true)
            {
                return;
            }

            instance.Client = new ClientConfig();

            var invokerNode = clientNode.GetSection("invoker");

            if (invokerNode?.GetChildren()?.Any() == true)
            {
                var name = invokerNode["name"];
                var type = invokerNode["type"];

                instance.Client.Invoker = new InvokerConfig
                {
                    Name = name,
                    Type = type,
                };
            }

            var clientsNode = clientNode.GetSection("clients");

            if (clientsNode?.GetChildren()?.Any() == true)
            {
                var group = clientsNode["group"];
                //instance.ClientEnvironment = !string.IsNullOrWhiteSpace(environment) ? environment : instance.Environment;

                var clients = clientsNode.GetChildren();
                foreach (var item in clients)
                {
                    var name    = item["name"];
                    var address = item["address"];
                    var type    = item["type"];
                    var env     = item["group"];
                    //var nameSpace = item["namespace"];

                    if (string.IsNullOrEmpty(name))
                    {
                        throw new RpcConfigException("name of RpcLite configuration client node can't be null or empty");
                    }
                    //if (string.IsNullOrEmpty(path))
                    //	throw new ConfigurationErrorsException("path of RpcLite configuration node can't be null or empty");
                    if (string.IsNullOrEmpty(type))
                    {
                        throw new RpcConfigException(string.Format("type of RpcLite configuration client node '{0}' can't be null or empty", name));
                    }
                    //if (string.IsNullOrEmpty(nameSpace))
                    //	throw new RpcConfigException(string.Format("namespace of RpcLite configuration client node '{0}' can't be null or empty", name));


                    var dic = new Dictionary <string, string>();
                    foreach (var configItem in item.GetChildren())
                    {
                        dic[configItem.Key] = configItem.Value;
                    }

                    var serviceConfigItem = new ClientConfigItem
                    {
                        Name = name,
                        Type = type,
                        //TypeName = typeName,
                        //AssemblyName = assemblyName,
                        Address = address,
                        //Namespace = nameSpace,
                        Group = string.IsNullOrWhiteSpace(env) ? group : env,
                        Items = dic
                    };
                    instance.Client.Clients.Add(serviceConfigItem);
                }
            }

            InitializeChannelConfig(clientNode, instance);
        }
Пример #5
0
        // ReSharper disable once FunctionComplexityOverflow
        private static void InitializeClientConfig(IConfiguration config, RpcConfig instance)
        {
            var clientNode = config.GetSection("client");
            if (clientNode?.GetChildren()?.Any() != true)
                return;

            instance.Client = new ClientConfig();

            var invokerNode = clientNode.GetSection("invoker");
            if (invokerNode?.GetChildren()?.Any() == true)
            {
                var name = invokerNode["name"];
                var type = invokerNode["type"];

                instance.Client.Invoker = new InvokerConfig
                {
                    Name = name,
                    Type = type,
                };
            }

            var clientsNode = clientNode.GetSection("clients");
            if (clientsNode?.GetChildren()?.Any() == true)
            {
                var group = clientsNode["group"];
                //instance.ClientEnvironment = !string.IsNullOrWhiteSpace(environment) ? environment : instance.Environment;

                var clients = clientsNode.GetChildren();
                foreach (var item in clients)
                {
                    var name = item["name"];
                    var address = item["address"];
                    var type = item["type"];
                    var env = item["group"];
                    //var nameSpace = item["namespace"];

                    if (string.IsNullOrEmpty(name))
                        throw new RpcConfigException("name of RpcLite configuration client node can't be null or empty");
                    //if (string.IsNullOrEmpty(path))
                    //	throw new ConfigurationErrorsException("path of RpcLite configuration node can't be null or empty");
                    if (string.IsNullOrEmpty(type))
                        throw new RpcConfigException(string.Format("type of RpcLite configuration client node '{0}' can't be null or empty", name));
                    //if (string.IsNullOrEmpty(nameSpace))
                    //	throw new RpcConfigException(string.Format("namespace of RpcLite configuration client node '{0}' can't be null or empty", name));

                    var dic = new Dictionary<string, string>();
                    foreach (var configItem in item.GetChildren())
                    {
                        dic[configItem.Key] = configItem.Value;
                    }

                    var serviceConfigItem = new ClientConfigItem
                    {
                        Name = name,
                        Type = type,
                        //TypeName = typeName,
                        //AssemblyName = assemblyName,
                        Address = address,
                        //Namespace = nameSpace,
                        Group = string.IsNullOrWhiteSpace(env) ? group : env,
                        Items = dic
                    };
                    instance.Client.Clients.Add(serviceConfigItem);
                }
            }

            InitializeChannelConfig(clientNode, instance);
        }