Exemplo n.º 1
0
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context)
        {
            var             request = context.ActionContext.HttpContext.Request;
            IFormCollection form;

            try
            {
                form = await request.ReadFormAsync();
            }
            catch (InvalidDataException ex)
            {
                // ReadFormAsync can throw InvalidDataException if the form content is malformed.
                // Wrap it in a ValueProviderException that the CompositeValueProvider special cases.
                throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
            }
            catch (IOException ex)
            {
                // ReadFormAsync can throw IOException if the client disconnects.
                // Wrap it in a ValueProviderException that the CompositeValueProvider special cases.
                throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
            }

            var valueProvider = new FormValueProvider(
                BindingSource.Form,
                form,
                CultureInfo.CurrentCulture);

            context.ValueProviders.Add(valueProvider);
        }
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context, HttpRequest request)
        {
            IFormCollection form;

            try
            {
                form = await request.ReadFormAsync();
            }
            catch (InvalidDataException ex)
            {
                // ReadFormAsync can throw InvalidDataException if the form content is malformed.
                // Wrap it in a ValueProviderException that the CompositeValueProvider special cases.
                throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
            }
            catch (IOException ex)
            {
                // ReadFormAsync can throw IOException if the client disconnects.
                // Wrap it in a ValueProviderException that the CompositeValueProvider special cases.
                throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
            }

            if (form.Files.Count > 0)
            {
                var valueProvider = new FormFileValueProvider(form.Files);
                context.ValueProviders.Add(valueProvider);
            }
        }
Exemplo n.º 3
0
 public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
 {
     if (context.ActionContext.HttpContext.Request.HasFormContentType)
     {
         context.ValueProviders.Add(new TrimmedFormValueProvider(context.ActionContext.HttpContext.Request.Form));
     }
     return(Task.CompletedTask);
 }
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context)
        {
            var request = context.ActionContext.HttpContext.Request;
            var valueProvider = new JQueryFormValueProvider(
                BindingSource.Form,
                await GetValueCollectionAsync(request),
                CultureInfo.CurrentCulture);

            context.ValueProviders.Add(valueProvider);
        }
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context, HttpRequest request)
        {
            var formCollection = await request.ReadFormAsync();

            if (formCollection.Files.Count > 0)
            {
                var valueProvider = new FormFileValueProvider(formCollection.Files);
                context.ValueProviders.Add(valueProvider);
            }
        }
Exemplo n.º 6
0
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context)
        {
            var request       = context.ActionContext.HttpContext.Request;
            var valueProvider = new JQueryFormValueProvider(
                BindingSource.Form,
                await GetValueCollectionAsync(request),
                CultureInfo.CurrentCulture);

            context.ValueProviders.Add(valueProvider);
        }
        private static ValueProviderFactoryContext CreateThrowingContext(Exception exception)
        {
            var context = new Mock <HttpContext>();

            context.Setup(c => c.Request.ContentType).Returns("application/x-www-form-urlencoded");
            context.Setup(c => c.Request.HasFormContentType).Returns(true);
            context.Setup(c => c.Request.ReadFormAsync(It.IsAny <CancellationToken>())).ThrowsAsync(exception);
            var actionContext        = new ActionContext(context.Object, new RouteData(), new ActionDescriptor());
            var valueProviderContext = new ValueProviderFactoryContext(actionContext);

            return(valueProviderContext);
        }
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context)
        {
            var request = context.ActionContext.HttpContext.Request;

            var formCollection = await request.ReadFormAsync();

            var valueProvider = new JQueryFormValueProvider(
                BindingSource.Form,
                JQueryKeyValuePairNormalizer.GetValues(formCollection, formCollection.Count),
                CultureInfo.CurrentCulture);

            context.ValueProviders.Add(valueProvider);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Asynchronously creates a <see cref="CompositeValueProvider"/> using the provided
        /// <paramref name="actionContext"/>.
        /// </summary>
        /// <param name="actionContext">The <see cref="ActionContext"/> associated with the current request.</param>
        /// <param name="factories">The <see cref="IValueProviderFactory"/> to be applied to the context.</param>
        /// <returns>
        /// A <see cref="Task{TResult}"/> which, when completed, asynchronously returns a
        /// <see cref="CompositeValueProvider"/>.
        /// </returns>
        public static async Task <CompositeValueProvider> CreateAsync(
            ActionContext actionContext,
            IList <IValueProviderFactory> factories)
        {
            var valueProviderFactoryContext = new ValueProviderFactoryContext(actionContext);

            for (var i = 0; i < factories.Count; i++)
            {
                var factory = factories[i];
                await factory.CreateValueProviderAsync(valueProviderFactoryContext);
            }

            return(new CompositeValueProvider(valueProviderFactoryContext.ValueProviders));
        }
        /// <inheritdoc />
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var valueProvider = new RouteValueProvider(
                BindingSource.Path,
                context.ActionContext.RouteData.Values);

            context.ValueProviders.Add(valueProvider);

            return(Task.CompletedTask);
        }
        /// <inheritdoc />
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var request = context.ActionContext.HttpContext.Request;
            if (request.HasFormContentType)
            {
                // Allocating a Task only when the body is form data.
                return AddValueProviderAsync(context);
            }

            return TaskCache.CompletedTask;
        }
Exemplo n.º 12
0
        /// <inheritdoc />
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var valueProvider = new QueryStringValueProvider(
                BindingSource.Query,
                context.ActionContext.HttpContext.Request.Query,
                CultureInfo.InvariantCulture);

            context.ValueProviders.Add(valueProvider);

            return(TaskCache.CompletedTask);
        }
        /// <inheritdoc />
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var request = context.ActionContext.HttpContext.Request;

            if (request.HasFormContentType)
            {
                // Allocating a Task only when the body is form data.
                return(AddValueProviderAsync(context));
            }

            return(Task.CompletedTask);
        }
        /// <summary>
        /// Asynchronously creates a <see cref="CompositeValueProvider"/> using the provided
        /// <paramref name="controllerContext"/>.
        /// </summary>
        /// <param name="controllerContext">The <see cref="ControllerContext"/> associated with the current request.</param>
        /// <returns>
        /// A <see cref="Task{TResult}"/> which, when completed, asynchronously returns a
        /// <see cref="CompositeValueProvider"/>.
        /// </returns>
        public static async Task <CompositeValueProvider> CreateAsync(ControllerContext controllerContext)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException(nameof(controllerContext));
            }

            var factories = controllerContext.ValueProviderFactories;
            var valueProviderFactoryContext = new ValueProviderFactoryContext(controllerContext);

            for (var i = 0; i < factories.Count; i++)
            {
                var factory = factories[i];
                await factory.CreateValueProviderAsync(valueProviderFactoryContext);
            }

            return(new CompositeValueProvider(valueProviderFactoryContext.ValueProviders));
        }
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context, HttpRequest request)
        {
            IFormCollection form;

            try
            {
                form = await request.ReadFormAsync();
            }
            catch (InvalidDataException ex)
            {
                throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
            }

            if (form.Files.Count > 0)
            {
                var valueProvider = new FormFileValueProvider(form.Files);
                context.ValueProviders.Add(valueProvider);
            }
        }
        public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var query = context.ActionContext.HttpContext.Request.Query;

            if (query != null && query.Count > 0)
            {
                var valueProvider = new JQueryQueryStringValueProvider(
                    BindingSource.Query,
                    JQueryKeyValuePairNormalizer.GetValues(query, query.Count),
                    CultureInfo.InvariantCulture);

                context.ValueProviders.Add(valueProvider);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 17
0
        private static async Task AddValueProviderAsync(ValueProviderFactoryContext context)
        {
            var             request = context.ActionContext.HttpContext.Request;
            IFormCollection form;

            try
            {
                form = await request.ReadFormAsync();
            }
            catch (InvalidDataException ex)
            {
                throw new ValueProviderException(Resources.FormatFailedToReadRequestForm(ex.Message), ex);
            }

            var valueProvider = new FormValueProvider(
                BindingSource.Form,
                form,
                CultureInfo.CurrentCulture);

            context.ValueProviders.Add(valueProvider);
        }
 public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
 {
     context.ValueProviders.Add(_valueProvider);
     return(Task.CompletedTask);
 }
Exemplo n.º 19
0
 public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
 {
     context.ValueProviders.Add(_valueProvider);
     return TaskCache.CompletedTask;
 }
Exemplo n.º 20
0
 public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
 {
     throw new NotImplementedException();
 }
 public Task CreateValueProviderAsync(ValueProviderFactoryContext context)
 {
     context.ValueProviders.Add(new TrimmedQueryStringValueProvider(context.ActionContext.HttpContext.Request.Query));
     return(Task.CompletedTask);
 }