コード例 #1
0
 public TransactionProcessor(IInputFormatter inputFormatter)
 {
     _inputFormatter = inputFormatter;
 }
コード例 #2
0
 private static BodyModelBinder GetBodyBinder(IInputFormatter inputFormatter)
 {
     return(GetBodyBinder(new DefaultHttpContext(), inputFormatter));
 }
コード例 #3
0
 public RequestReader(HttpContext httpContext, IInputFormatter inputFormatter)
 {
     _httpContext    = httpContext;
     _inputFormatter = inputFormatter;
 }
コード例 #4
0
        /// <summary>
        ///		Asynchronously read the body content as the specified type.
        /// </summary>
        /// <typeparam name="TBody">
        ///		The CLR data-type that the body content will be deserialised into.
        /// </typeparam>
        /// <param name="content">
        ///		The <see cref="HttpContent"/> to read.
        /// </param>
        /// <param name="formatter">
        ///		The content formatter used to deserialise the body content.
        /// </param>
        /// <param name="formatterContext">
        ///		Contextual information about the content body being deserialised.
        /// </param>
        /// <returns>
        ///		The deserialised body content.
        /// </returns>
        public static async Task <TBody> ReadAsAsync <TBody>(this HttpContent content, IInputFormatter formatter, InputFormatterContext formatterContext)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            if (formatterContext == null)
            {
                throw new ArgumentNullException(nameof(formatterContext));
            }

            using (Stream responseStream = await content.ReadAsStreamAsync().ConfigureAwait(false))
            {
                object responseBody = await formatter.ReadAsync(formatterContext, responseStream).ConfigureAwait(false);

                return((TBody)responseBody);
            }
        }
コード例 #5
0
 private static BodyModelBinder GetBodyBinder(IInputFormatter inputFormatter)
 {
     return GetBodyBinder(new DefaultHttpContext(), inputFormatter);
 }
コード例 #6
0
        private static BodyModelBinder GetBodyBinder(HttpContext httpContext, IInputFormatter inputFormatter)
        {
            var actionContext = CreateActionContext(httpContext);
            var inputFormatterSelector = new Mock<IInputFormatterSelector>();
            inputFormatterSelector
                .Setup(o => o.SelectFormatter(
                    It.IsAny<IReadOnlyList<IInputFormatter>>(),
                    It.IsAny<InputFormatterContext>()))
                .Returns(inputFormatter);

            var bodyValidationPredicatesProvider = new Mock<IValidationExcludeFiltersProvider>();
            bodyValidationPredicatesProvider.SetupGet(o => o.ExcludeFilters)
                                             .Returns(new List<IExcludeTypeValidationFilter>());

            var bindingContext = new ActionBindingContext()
            {
                InputFormatters = new List<IInputFormatter>(),
            };

            var bindingContextAccessor = new MockScopedInstance<ActionBindingContext>()
            {
                Value = bindingContext,
            };

            var binder = new BodyModelBinder(
                actionContext,
                bindingContextAccessor,
                inputFormatterSelector.Object,
                bodyValidationPredicatesProvider.Object);

            return binder;
        }
コード例 #7
0
        private static ModelBindingContext GetBindingContext(
            Type modelType,
            IInputFormatter inputFormatter = null,
            HttpContext httpContext = null,
            IModelMetadataProvider metadataProvider = null)
        {
            if (httpContext == null)
            {
                httpContext = new DefaultHttpContext();
            }

            if (metadataProvider == null)
            {
                metadataProvider = new EmptyModelMetadataProvider();
            }

            var operationBindingContext = new OperationBindingContext
            {
                ModelBinder = GetBodyBinder(httpContext, inputFormatter),
                MetadataProvider = metadataProvider,
                HttpContext = httpContext,
            };

            var bindingContext = new ModelBindingContext
            {
                ModelMetadata = metadataProvider.GetMetadataForType(modelType),
                ModelName = "someName",
                ValueProvider = Mock.Of<IValueProvider>(),
                ModelState = new ModelStateDictionary(),
                OperationBindingContext = operationBindingContext,
                BindingSource = BindingSource.Body,
            };

            return bindingContext;
        }
コード例 #8
0
        public static MongoSource <T> CreateFromCollection <T>(string collectionName, IInputFormatter <T> formatter)
            where T : class
        {
            var source = new MongoSource <T>(collectionName);

            source.SetFormatter(formatter);
            return(source);
        }
コード例 #9
0
ファイル: LoggingBinderBase.cs プロジェクト: 5l1v3r1/Maze-1
 protected void LogInputFormatterRejected(IInputFormatter formatter, InputFormatterContext formatterContext)
 {
 }
コード例 #10
0
ファイル: BodyModelBinder.cs プロジェクト: pa-at/aspnetcore
 private static partial void InputFormatterRejected(ILogger logger, IInputFormatter inputFormatter, string?contentType);
コード例 #11
0
 public void AddInputFormatter(IInputFormatter formatter)
 {
     _mvcCoreBuilder.AddMvcOptions(o => o.InputFormatters.Add(formatter));
 }