Пример #1
0
        /// <inheritdoc />
        public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context)
        {
            var valueProviders = _valueProviderFactories.Select(factory => factory.GetValueProvider(context))
                                 .Where(vp => vp != null);

            return(new CompositeValueProvider(valueProviders));
        }
Пример #2
0
 /// <inheritdoc />
 public Task <IValueProvider> GetValueProviderAsync([NotNull] ValueProviderFactoryContext context)
 {
     return(Task.FromResult <IValueProvider>(new ReadableStringCollectionValueProvider(
                                                 BindingSource.Query,
                                                 context.HttpContext.Request.Query,
                                                 CultureInfo.InvariantCulture)));
 }
 /// <inheritdoc />
 public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context)
 {
     return(new ReadableStringCollectionValueProvider(
                BindingSource.Query,
                context.HttpContext.Request.Query,
                CultureInfo.InvariantCulture));
 }
Пример #4
0
        /// <summary>
        /// Creates a new <see cref="CompositeValueProvider"/> from the provided <paramref name="context"/>
        /// and <paramref name="factories"/>.
        /// </summary>
        /// <param name="factories">The set of <see cref="IValueProviderFactory"/> instances.</param>
        /// <param name="context">The <see cref="ValueProviderFactoryContext"/>.</param>
        /// <returns>
        /// A <see cref="CompositeValueProvider"/> containing all <see cref="IValueProvider"/> instances
        /// created.
        /// </returns>
        public static async Task <CompositeValueProvider> CreateAsync(
            IEnumerable <IValueProviderFactory> factories,
            ValueProviderFactoryContext context)
        {
            if (factories == null)
            {
                throw new ArgumentNullException(nameof(factories));
            }

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

            var composite = new CompositeValueProvider();

            foreach (var valueProvidersFactory in factories)
            {
                var valueProvider = await valueProvidersFactory.GetValueProviderAsync(context);

                if (valueProvider != null)
                {
                    composite.Add(valueProvider);
                }
            }

            return(composite);
        }
        public Task<ActionBindingContext> GetActionBindingContextAsync(ActionContext actionContext)
        {
            if (_bindingContext != null)
            {
                if (actionContext == _bindingContext.Item1)
                {
                    return Task.FromResult(_bindingContext.Item2);
                }
            }

            var factoryContext = new ValueProviderFactoryContext(
                                    actionContext.HttpContext,
                                    actionContext.RouteData.Values);

            var valueProvider = _compositeValueProviderFactory.GetValueProvider(factoryContext);

            var context = new ActionBindingContext(
                actionContext,
                _modelMetadataProvider,
                _compositeModelBinder,
                valueProvider,
                _inputFormatterProvider,
                _validatorProviders);

            _bindingContext = new Tuple<ActionContext, ActionBindingContext>(actionContext, context);

            return Task.FromResult(context);
        }
        public IValueProvider GetValueProvider(ValueProviderFactoryContext context)
        {
            if (context.HttpContext.Request.Path.Value.Contains("TestValueProvider"))
            {
                return new CustomValueProvider();
            }

            return null;
        }
        public Task<IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context.HttpContext.Request.Path.Value.Contains("TestValueProvider"))
            {
                return Task.FromResult<IValueProvider>(new CustomValueProvider());
            }

            return Task.FromResult<IValueProvider>(null);
        }
        public Task<IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return Task.FromResult<IValueProvider>(new DictionaryBasedValueProvider(
                BindingSource.Path,
                context.RouteValues));
        }
Пример #9
0
        public Task <IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(Task.FromResult <IValueProvider>(new DictionaryBasedValueProvider(
                                                        BindingSource.Path,
                                                        context.RouteValues)));
        }
        /// <inheritdoc />
        public Task<IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return Task.FromResult<IValueProvider>(new ReadableStringCollectionValueProvider(
                BindingSource.Query,
                context.HttpContext.Request.Query,
                CultureInfo.InvariantCulture));
        }
Пример #11
0
        public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context)
        {
            var request = context.HttpContext.Request;

            if (IsSupportedContentType(request))
            {
                var culture = GetCultureInfo(request);
                return(new ReadableStringCollectionValueProvider(() => request.GetFormAsync(), culture));
            }

            return(null);
        }
Пример #12
0
        /// <inheritdoc />
        public Task <IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(Task.FromResult <IValueProvider>(new ReadableStringCollectionValueProvider(
                                                        BindingSource.Query,
                                                        context.HttpContext.Request.Query,
                                                        CultureInfo.InvariantCulture)));
        }
        public async Task <IValueProvider> GetValueProviderAsync([NotNull] ValueProviderFactoryContext context)
        {
            var request = context.HttpContext.Request;

            if (request.HasFormContentType)
            {
                return(new JQueryFormValueProvider(
                           BindingSource.Form,
                           await GetValueCollectionAsync(request),
                           CultureInfo.CurrentCulture));
            }

            return(null);
        }
Пример #14
0
        public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context)
        {
            var request = context.HttpContext.Request;

            if (request.HasFormContentType)
            {
                var culture = GetCultureInfo(request);

                return(new ReadableStringCollectionValueProvider <IFormDataValueProviderMetadata>(
                           async() => await request.ReadFormAsync(),
                           culture));
            }

            return(null);
        }
        public Task<IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            
            var request = context.HttpContext.Request;
            if (request.HasFormContentType)
            {
                return CreateValueProviderAsync(request);
            }

            return TaskCache<IValueProvider>.DefaultCompletedTask;
        }
Пример #16
0
        public Task <IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var request = context.HttpContext.Request;

            if (request.HasFormContentType)
            {
                return(CreateValueProviderAsync(request));
            }

            return(TaskCache <IValueProvider> .DefaultCompletedTask);
        }
Пример #17
0
        public async Task <IValueProvider> GetValueProviderAsync([NotNull] ValueProviderFactoryContext context)
        {
            var request = context.HttpContext.Request;

            if (request.HasFormContentType)
            {
                var culture = GetCultureInfo(request);

                return(new ReadableStringCollectionValueProvider(
                           BindingSource.Form,
                           await request.ReadFormAsync(),
                           culture));
            }

            return(null);
        }
Пример #18
0
        /// <summary>
        /// Creates a new <see cref="CompositeValueProvider"/> from the provided <paramref name="context"/>
        /// and <paramref name="factories"/>.
        /// </summary>
        /// <param name="factories">The set of <see cref="IValueProviderFactory"/> instances.</param>
        /// <param name="context">The <see cref="ValueProviderFactoryContext"/>.</param>
        /// <returns>
        /// A <see cref="CompositeValueProvider"/> containing all <see cref="IValueProvider"/> instances
        /// created.
        /// </returns>
        public static CompositeValueProvider Create(
            [NotNull] IEnumerable <IValueProviderFactory> factories,
            [NotNull] ValueProviderFactoryContext context)
        {
            var composite = new CompositeValueProvider();

            foreach (var valueProvidersFactory in factories)
            {
                var valueProvider = valueProvidersFactory.GetValueProvider(context);
                if (valueProvider != null)
                {
                    composite.Add(valueProvider);
                }
            }

            return(composite);
        }
Пример #19
0
        public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context)
        {
            // Process the query collection once-per request.
            var            storage = context.HttpContext.Items;
            object         value;
            IValueProvider provider;

            if (!storage.TryGetValue(_cacheKey, out value))
            {
                var queryCollection = context.HttpContext.Request.Query;
                provider           = new ReadableStringCollectionValueProvider(queryCollection, CultureInfo.InvariantCulture);
                storage[_cacheKey] = provider;
            }
            else
            {
                provider = (ReadableStringCollectionValueProvider)value;
            }
            return(provider);
        }
        public async Task GetValueProvider_ReturnsSnakeCaseQueryValueProviderInstanceWithInvariantCulture()
        {
            // Arrange
            var request = new Mock<HttpRequest>();

            request.SetupGet(f => f.Query).Returns(Mock.Of<IReadableStringCollection>());

            var context = new Mock<HttpContext>();

            context.SetupGet(c => c.Items).Returns(new Dictionary<object, object>());
            context.SetupGet(c => c.Request).Returns(request.Object);

            var factoryContext = new ValueProviderFactoryContext(
                context.Object,
                new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase));

            // Act
            var result = await _factory.GetValueProviderAsync(factoryContext);

            // Assert
            var valueProvider = Assert.IsType<SnakeCaseQueryValueProvider>(result);
            Assert.Equal(CultureInfo.InvariantCulture, valueProvider.Culture);
        }
Пример #21
0
        public Task<IValueProvider> GetValueProviderAsync(ValueProviderFactoryContext context)
        {
            var collection = new Dictionary<string, object>();
            var lightcoreContext = context.HttpContext.LightcoreContext();
            var item = lightcoreContext?.Item;

            if (item != null)
            {
                var controller = context.RouteValues["controller"] as string;

                if (controller != null && !controller.Equals("Lightcore"))
                {
                    var rendering = item.PresentationDetails.Renderings
                                        .FirstOrDefault(r => r.Controller.Equals(controller, StringComparison.OrdinalIgnoreCase));

                    if (rendering != null)
                    {
                        foreach (var parameter in rendering.Parameters)
                        {
                            collection.Add(parameter.Key, parameter.Value);
                        }

                        collection.Add("datasource", rendering.Datasource);
                        collection.Add("language", item.Language.Name);
                        collection.Add("itemId", item.Id);
                        collection.Add("templateId", item.TemplateId);

                        collection.Add("renderingContext.Datasource", rendering.Datasource);
                        collection.Add("renderingContext.ItemLanguageName", item.Language.Name);
                        collection.Add("renderingContext.ItemId", item.Id);
                        collection.Add("renderingContext.ItemTemplateId", item.TemplateId);
                    }
                }
            }

            return Task.FromResult<IValueProvider>(new DictionaryBasedValueProvider(BindingSource.ModelBinding, collection));
        }
Пример #22
0
 public Task <IValueProvider> GetValueProviderAsync([NotNull] ValueProviderFactoryContext context)
 {
     return(Task.FromResult <IValueProvider>(new DictionaryBasedValueProvider(
                                                 BindingSource.Path,
                                                 context.RouteValues)));
 }
Пример #23
0
        private static ActionBindingContext GetActionBindingContext(MvcOptions options, ActionContext actionContext)
        {
            var valueProviderFactoryContext = new ValueProviderFactoryContext(
                actionContext.HttpContext,
                actionContext.RouteData.Values);

            var valueProvider = CompositeValueProvider.CreateAsync(
                options.ValueProviderFactories,
                valueProviderFactoryContext).Result;

            return new ActionBindingContext()
            {
                InputFormatters = options.InputFormatters,
                OutputFormatters = options.OutputFormatters, // Not required for model binding.
                ValidatorProvider = new TestModelValidatorProvider(options.ModelValidatorProviders),
                ModelBinder = new CompositeModelBinder(options.ModelBinders),
                ValueProvider = valueProvider
            };
        }
 public IValueProvider GetValueProvider(ValueProviderFactoryContext context)
 {
     throw new NotImplementedException();
 }
 public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context)
 {
     return(new DictionaryBasedValueProvider(BindingSource.Path, context.RouteValues));
 }