Beispiel #1
0
        private static void InitializeFormatterConfig(IConfiguration config, RpcConfig instance)
        {
            var formatterNode = config.GetSection("formatter");

            if (formatterNode?.GetChildren()?.Any() == true)
            {
                var removeDefaultNode = formatterNode["removeDefault"];
                instance.Formatter = new FormatterConfig
                {
                    RemoveDefault = removeDefaultNode?.ToLower() == "true",
                    Formatters    = new List <FormatterItemConfig>(),
                };

                var formattersNode = formatterNode.GetSection("formatters");
                var clients        = formattersNode.GetChildren();
                foreach (var item in clients)
                {
                    var name = item["name"];
                    var type = item["type"];

                    //if (string.IsNullOrEmpty(name))
                    //	throw new RpcConfigException("name of RpcLite configuration client 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));
                    }

                    var serviceConfigItem = new FormatterItemConfig
                    {
                        Name = name,
                        Type = type,
                    };
                    instance.Formatter.Formatters.Add(serviceConfigItem);
                }
            }
        }
        private static void InitializeFormatterConfig(IConfiguration config, RpcConfig instance)
        {
            var formatterNode = config.GetSection("formatter");

            if (formatterNode?.GetChildren()?.Any() == true)
            {
                var removeDefaultNode = formatterNode["removeDefault"];
                instance.Formatter = new FormatterConfig
                {
                    RemoveDefault = removeDefaultNode?.ToLower() == "true",
                    Formatters = new List<FormatterItemConfig>(),
                };

                var formattersNode = formatterNode.GetSection("formatters");
                var clients = formattersNode.GetChildren();
                foreach (var item in clients)
                {
                    var name = item["name"];
                    var type = item["type"];

                    //if (string.IsNullOrEmpty(name))
                    //	throw new RpcConfigException("name of RpcLite configuration client 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));

                    var serviceConfigItem = new FormatterItemConfig
                    {
                        Name = name,
                        Type = type,
                    };
                    instance.Formatter.Formatters.Add(serviceConfigItem);
                }
            }
        }