示例#1
0
 public DefaultMethodInvoker(RequestContext requestContext, MethodInvokerEntry entry)
     : base(requestContext, entry.Interceptors)
 {
     _entry  = entry;
     _client = entry.Client;
     _codec  = entry.Codec;
     _keyValueFormatterFactory = entry.KeyValueFormatterFactory;
     _templateParser           = entry.TemplateParser;
 }
示例#2
0
 public MethodInvokerCache(
     IGoClient goClient = null,
     IKeyValueFormatterFactory keyValueFormatterFactory = null,
     ITemplateParser templateParser = null,
     IServiceProvider services      = null)
 {
     _goClient = goClient ?? DefaultGoClient;
     _keyValueFormatterFactory = keyValueFormatterFactory ?? DefaultKeyValueFormatterFactory;
     _templateParser           = templateParser ?? DefaultTemplateParser;
     _services = services;
 }
        public static async Task <IDictionary <string, string> > FormatAsync(this IKeyValueFormatterFactory keyValueFormatterFactory, IKeyValueFormatter formatter, object model, Type type = null, string name = null)
        {
            var context = new KeyValueFormatterContext(keyValueFormatterFactory)
            {
                BinderModelName = name ?? string.Empty,
                Model           = model,
                ModelType       = type ?? model.GetType()
            };
            await formatter.FormatAsync(context);

            return(context.Result);
        }
示例#4
0
        private async Task <IDictionary <ParameterTarget, IDictionary <string, StringValues> > > FormatAsync(IReadOnlyList <ParameterDescriptor> parameterDescriptors, IKeyValueFormatterFactory keyValueFormatterFactory, IReadOnlyList <object> arguments)
        {
            if (keyValueFormatterFactory == null || parameterDescriptors == null || !parameterDescriptors.Any() || arguments == null || !arguments.Any())
            {
                return(null);
            }

            IDictionary <ParameterTarget, IDictionary <string, StringValues> > formatResult =
                new Dictionary <ParameterTarget, IDictionary <string, StringValues> >
            {
                {
                    ParameterTarget.Query,
                    new Dictionary <string, StringValues>(StringComparer.OrdinalIgnoreCase)
                },
                { ParameterTarget.Path, new Dictionary <string, StringValues>() },
                {
                    ParameterTarget.Header,
                    new Dictionary <string, StringValues>(StringComparer.OrdinalIgnoreCase)
                }
            };

            for (var i = 0; i < parameterDescriptors.Count; i++)
            {
                var parameterDescriptor = parameterDescriptors[i];

                if (!formatResult.TryGetValue(parameterDescriptor.FormattingInfo.Target, out var itemResult))
                {
                    continue;
                }

                IKeyValueFormatter formatter = null;
                if (parameterDescriptor.FormattingInfo.FormatterType != null)
                {
                    formatter = (IKeyValueFormatter)ActivatorUtilities.GetServiceOrCreateInstance(RequestContext.GoContext.RequestServices, parameterDescriptor.FormattingInfo.FormatterType);
                }

                if (formatter == null)
                {
                    formatter = keyValueFormatterFactory.CreateFormatter(parameterDescriptor.ParameterType);
                }

                var parameter = parameterDescriptors[i];
                var value     = arguments[i];
                var item      = await keyValueFormatterFactory.FormatAsync(formatter, value, parameter.ParameterType, parameterDescriptor.FormattingInfo.FormatterName);

                foreach (var t in item)
                {
                    itemResult[t.Key] = t.Value;
                }
            }

            return(formatResult);
        }
示例#5
0
 public KeyValueFormatterContext(IKeyValueFormatterFactory formatterFactory)
 {
     FormatterFactory = formatterFactory;
 }