public IValueProvider Handle(IValueProvider provider, Parameter parameter, ParameterValue parameterValue)
 {
     if (parameter.Translator == SerializeStringToValueTranslatorProvider.ProviderKey)
     {
         return new EagerLoadValueProviderDecorator(provider,_settings);
     }
     return provider;
 }
 private IEnumerable<Tuple<IValueProvider, IFilterCondition[]>> BuildValueProviders(Parameter parameter, IByContextSettings settings)
 {
     foreach (var parameterValue in parameter.Values)
     {
         IEnumerable<IFilterCondition> filterConditions = this.TranslateFilterConditions(parameterValue.FilterConditions, settings);
         yield return new Tuple<IValueProvider, IFilterCondition[]>(settings.ValueProviderBuilder.Build(parameter, parameterValue),filterConditions.ToArray());
     }
 }
        public IParameterValueProvider Convert(Parameter parameter, IByContextSettings settings)
        {
            var parameterType = Type.GetType(parameter.TypeName, true);

            var required = this.GetRequired(parameter);

            bool isParameterSupportedCollection = settings.ResultBuilderProvider.IsTypeIsSupportedCollection(parameterType);
            var engine = this.BuildQueryEngine(parameter, settings, isParameterSupportedCollection);

            var resultBuilder = settings.ResultBuilderProvider.Get(parameterType);

            IParameterValueProvider parameterValueProvider = new QueryEngineParameterValueProvider
                (engine, resultBuilder, required, parameter.Name, settings.LogggerProvider);

            return parameterValueProvider;
        }
        private void BuildParameterProvider(IByContextSettings settings, SectionProvider provider, Parameter parameter, PropertyInfo parameterPropertyInfo)
        {
            if (string.IsNullOrEmpty(parameter.TypeName))
            {
                parameter.TypeName = parameterPropertyInfo.PropertyType.AssemblyQualifiedName;
            }
            else if (!parameterPropertyInfo.PropertyType.IsAssignableFrom(Type.GetType(parameter.TypeName, true)))
            {
                throw new InvalidParameterConfiguration(string.Format("Specified type {0} for parameter {1} is not assignable to the property of type {2}", parameter.TypeName, parameter.Name,parameterPropertyInfo.PropertyType.FullName));
            }

            /*var valueProvider = new ParameterToParameterValueProviderConverter().Convert(parameter, settings);*/
            var valueProvider = new ParameterToQueryEngineParameterValueProviderConverter().Convert(parameter, settings);

            provider.ParameterValuesProviders.Add(parameterPropertyInfo.Name, valueProvider);
        }
Exemplo n.º 5
0
        /*[Test]*/
        public void FilterBestMatchWithLotsOfPotentialValues()
        {
            var numParam = new Parameter().FromExpression<SimpleSection, int>(x => x.IntProp);
            foreach (var valueIndex in Enumerable.Range(0, 100))
            {
                var parameterValue = new ParameterValue { Value = valueIndex.ToString() };
                foreach (var refIndex in Enumerable.Range(0, 100))
                {
                    foreach (var subjectIndex in Enumerable.Range(0, 100))
                    {
                        parameterValue.WithTextMatchReference(subjectIndex.ToString(), refIndex.ToString());
                    }
                }
                numParam.AddValue(parameterValue);
            }

            numParam.Values.Add(new ParameterValue { Value = "1" }.WithTextMatchReference("A", "33333").WithTextMatchReference("B", "33333"));

            Section section = new Section().FromType<SimpleSection>()
                                           .AddParameter(numParam);

            IByContext svc = Configure.With(cfg =>
                           cfg.RuntimeContext((context) =>
                           {
                               context.Add("A", "33333");
                               context.Add("B", "33333");
                               foreach (var subjectIndex in Enumerable.Range(0, 100))
                               {
                                   context.Add(subjectIndex.ToString(), "33333" + subjectIndex.ToString());
                               }
                           })
                           .AddSection(section)
                       );

            Trace.Write("start filtering...");
            var stopwatch = Stopwatch.StartNew();
            var simpleSection = svc.GetSection<SimpleSection>();
            stopwatch.Stop();
            Trace.WriteLine("elapsed: " + stopwatch.Elapsed);
            Trace.WriteLine("Milliseconds: " + stopwatch.ElapsedMilliseconds);

            Assert.IsTrue(true);
        }
        public void ConvertSection()
        {
            Section section = new Section
                {
                    TypeName = typeof (SimpleSection).AssemblyQualifiedName,
                    ModelBinderFactory = null,
                };
            var strPropParam = new Parameter
                {
                    Name = "StrProp",
                    Values = new List<ParameterValue>
                        {
                            new ParameterValue{Value = "aa"}
                        },
                };

            var intPropParam = new Parameter
                {
                    Name = "IntProp",
                    Values = new List<ParameterValue>
                        {
                            new ParameterValue
                                {
                                    Value = "11"
                                }
                        },
                };

            section.Parameters.Add(strPropParam.Name, strPropParam);
            section.Parameters.Add(intPropParam.Name, intPropParam);

            var sectionProvider = new SectionToProviderConverter().Convert(section, new ByContextSettings());

            var sectionInstance = sectionProvider.Get(new Dictionary<string, string>());

            Assert.IsInstanceOf<SimpleSection>(sectionInstance);
            Assert.AreEqual(11, ((SimpleSection)sectionInstance).IntProp);
            Assert.AreEqual("aa", ((SimpleSection)sectionInstance).StrProp);
        }
 private bool GetRequired(Parameter parameter)
 {
     var required = this._helper.GetConfigurationProperty(parameter, x => x.Required, () => true, bool.Parse);
     return required;
 }
 private IQueryEngine BuildQueryEngine(Parameter parameter, IByContextSettings settings, bool isParameterSupportedCollection)
 {
     var queriableItems = this.BuildValueProviders(parameter, settings).Select(x => QueriableItem.Create(x.Item1, x.Item2));
     return settings.QueryEngineBuilder.Get(queriableItems, isParameterSupportedCollection);
 }