/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="path"></param> /// <param name="address"></param> /// <returns></returns> public RpcConfigBuilder UseService <TService>(string name, string path, string address) { var item = new ServiceConfigItem(name, typeof(TService), path) { Address = address }; return(UseServices(item)); }
private static void InitializeServiceConfig(IConfiguration config, RpcConfig instance) { try { var serviceNode = config.GetSection("service"); if (serviceNode == null) { return; } if (instance.Service == null) { instance.Service = new ServiceConfig(); } var servicesNode = serviceNode.GetSection("services"); if (servicesNode != null) { var serviceItems = new List <ServiceConfigItem>(); var serviceItemNodes = servicesNode.GetChildren(); foreach (var item in serviceItemNodes) { var name = item["name"]; var path = item["path"]; var type = item["type"]; var address = item["address"]; var env = item["environment"]; //GetAttribute("type", item); if (string.IsNullOrEmpty(name)) { throw new RpcConfigException("name of RpcLite service configuration node can't be null or empty"); } if (string.IsNullOrEmpty(path)) { throw new RpcConfigException("path of RpcLite service configuration node " + name + " can't be null or empty"); } if (string.IsNullOrEmpty(type)) { throw new RpcConfigException("type of RpcLite service configuration node " + name + " can't be null or empty"); } //string typeName; //string assemblyName; //var splitorIndex = type.IndexOf(",", StringComparison.Ordinal); //if (splitorIndex > -1) //{ // typeName = type.Substring(0, splitorIndex); // assemblyName = type.Substring(splitorIndex + 1); //} //else //{ // typeName = type; // assemblyName = null; //} //if (string.IsNullOrWhiteSpace(assemblyName)) // throw new RpcConfigException("assembly can't be null or empty, in RpcLite service configuration node " + name); var serviceConfigItem = new ServiceConfigItem { Name = name, Type = type, //TypeName = typeName, //AssemblyName = assemblyName, Path = path, Address = address, Group = env, }; serviceItems.Add(serviceConfigItem); } instance.Service.Services.AddRange(serviceItems); } var mapperNode = serviceNode.GetSection("mapper"); if (mapperNode != null) { instance.Service.Mapper = InitializeServiceMapperConfig(mapperNode); } var pathsNode = serviceNode.GetSection("paths"); if (pathsNode != null) { var paths = new List <string>(); var pathNodes = pathsNode.GetChildren(); foreach (var path in pathNodes) { if (!string.IsNullOrWhiteSpace(path.Value)) { paths.Add(path.Value); } else if (!string.IsNullOrWhiteSpace(path["value"])) { paths.Add(path["value"]); } } instance.Service.Paths = paths.ToArray(); } } catch (Exception ex) { throw new ConfigException("Service Configuration Error", ex); } }
//private static void InitializeResolverConfig(IConfiguration config, RpcConfig instance) //{ // try // { // var resolverNode = config.GetSection("addressResolver"); // if (resolverNode != null && resolverNode.GetChildren().Any()) // { // //foreach (XmlNode item in resolverNode.ChildNodes) // { // //if (resolverNode.Name != "add" || resolverNode.Attributes == null) // // continue; // var name = resolverNode["name"]; //GetAttribute("name", resolverNode); // var type = resolverNode["type"]; //GetAttribute("type", resolverNode); // if (string.IsNullOrEmpty(name)) // throw new RpcConfigException("name of RpcLite configuration addressResolver node can't be null or empty"); // if (string.IsNullOrEmpty(type)) // throw new RpcConfigException("type of RpcLite configuration addressResolver node " + name + " can't be null or empty"); // string typeName; // string assemblyName; // var splitorIndex = type.IndexOf(",", StringComparison.Ordinal); // if (splitorIndex > -1) // { // typeName = type.Substring(0, splitorIndex); // assemblyName = type.Substring(splitorIndex + 1); // } // else // { // typeName = type; // assemblyName = null; // } // var resolver = new ResolverConfigItem // { // Name = name, // Type = type, // TypeName = typeName, // AssemblyName = assemblyName, // }; // instance.Resover = resolver; // } // } // } // catch (Exception ex) // { // throw new ConfigException("Client Configuration Error", ex); // } //} private static void InitializeServiceConfig(IConfiguration config, RpcConfig instance) { try { var servicesNode = config.GetSection("services"); if (servicesNode != null) { instance.Service = instance.Service ?? new ServiceConfig(); var serviceItemNodes = servicesNode.GetChildren(); foreach (var item in serviceItemNodes) { var name = item["name"]; var path = item["path"]; var type = item["type"]; var address = item["address"]; var env = item["environment"]; //GetAttribute("type", item); if (string.IsNullOrEmpty(name)) throw new RpcConfigException("name of RpcLite service configuration node can't be null or empty"); if (string.IsNullOrEmpty(path)) throw new RpcConfigException("path of RpcLite service configuration node " + name + " can't be null or empty"); if (string.IsNullOrEmpty(type)) throw new RpcConfigException("type of RpcLite service configuration node " + name + " can't be null or empty"); //string typeName; //string assemblyName; //var splitorIndex = type.IndexOf(",", StringComparison.Ordinal); //if (splitorIndex > -1) //{ // typeName = type.Substring(0, splitorIndex); // assemblyName = type.Substring(splitorIndex + 1); //} //else //{ // typeName = type; // assemblyName = null; //} //if (string.IsNullOrWhiteSpace(assemblyName)) // throw new RpcConfigException("assembly can't be null or empty, in RpcLite service configuration node " + name); var serviceConfigItem = new ServiceConfigItem { Name = name, Type = type, //TypeName = typeName, //AssemblyName = assemblyName, Path = path, Address = address, Group = env, }; instance.Service.Services.Add(serviceConfigItem); } } } catch (Exception ex) { throw new ConfigException("Service Configuration Error", ex); } }
private static void InitializeServiceConfig(IConfiguration config, RpcConfig instance) { try { var serviceNode = config.GetSection("service"); if (serviceNode == null) return; if (instance.Service == null) instance.Service = new ServiceConfig(); var servicesNode = serviceNode.GetSection("services"); if (servicesNode != null) { var serviceItems = new List<ServiceConfigItem>(); var serviceItemNodes = servicesNode.GetChildren(); foreach (var item in serviceItemNodes) { var name = item["name"]; var path = item["path"]; var type = item["type"]; var address = item["address"]; var env = item["environment"]; //GetAttribute("type", item); if (string.IsNullOrEmpty(name)) throw new RpcConfigException("name of RpcLite service configuration node can't be null or empty"); if (string.IsNullOrEmpty(path)) throw new RpcConfigException("path of RpcLite service configuration node " + name + " can't be null or empty"); if (string.IsNullOrEmpty(type)) throw new RpcConfigException("type of RpcLite service configuration node " + name + " can't be null or empty"); //string typeName; //string assemblyName; //var splitorIndex = type.IndexOf(",", StringComparison.Ordinal); //if (splitorIndex > -1) //{ // typeName = type.Substring(0, splitorIndex); // assemblyName = type.Substring(splitorIndex + 1); //} //else //{ // typeName = type; // assemblyName = null; //} //if (string.IsNullOrWhiteSpace(assemblyName)) // throw new RpcConfigException("assembly can't be null or empty, in RpcLite service configuration node " + name); var serviceConfigItem = new ServiceConfigItem { Name = name, Type = type, //TypeName = typeName, //AssemblyName = assemblyName, Path = path, Address = address, Group = env, }; serviceItems.Add(serviceConfigItem); } instance.Service.Services.AddRange(serviceItems); } var mapperNode = serviceNode.GetSection("mapper"); if (mapperNode != null) { instance.Service.Mapper = InitializeServiceMapperConfig(mapperNode); } var pathsNode = serviceNode.GetSection("paths"); if (pathsNode != null) { var paths = new List<string>(); var pathNodes = pathsNode.GetChildren(); foreach (var path in pathNodes) { if (!string.IsNullOrWhiteSpace(path.Value)) paths.Add(path.Value); else if (!string.IsNullOrWhiteSpace(path["value"])) paths.Add(path["value"]); } instance.Service.Paths = paths.ToArray(); } } catch (Exception ex) { throw new ConfigException("Service Configuration Error", ex); } }