public void FacetFieldParameter005() { // Arrange var expected = JObject.Parse(@" { ""facet"": { ""Id"": { ""terms"": { ""field"": ""_id_"", ""mincount"": 1, ""domain"":{ ""excludeTags"": [ ""tag1"", ""tag2"" ] } } } } }"); string actual; var jObject = new JObject(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetFieldParameter <TestDocument>(expressionBuilder); parameter.Configure(q => q.Id, excludes: new[] { "tag1", "tag2" }); // Act parameter.Execute(jObject); actual = jObject.ToString(); // Assert Assert.Equal(expected.ToString(), actual); }
public void FieldsParameter001() { // Arrange var expected = JObject.Parse(@" { ""fields"": [ ""_id_"", ""_score_"" ] }"); string actual; var jObject = new JObject(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter1 = new FieldsParameter <TestDocument>(expressionBuilder); var parameter2 = new FieldsParameter <TestDocument>(expressionBuilder); parameter1.Configure(q => q.Id); parameter2.Configure(q => q.Score); // Act parameter1.Execute(jObject); parameter2.Execute(jObject); actual = jObject.ToString(); // Assert Assert.Equal(expected.ToString(), actual); }
private static StandardResult <string> EvaulateExpression(SimpleTableRow row, string expressionText) { if (expressionText == null) { return(StandardResult <string> .ReturnResult(null)); } var fieldSource = new FieldDataSource() { Row = row }; var expression = ExpressionCache.Compile(expressionText); var result = expression.Evaluate(new Context() { FieldSource = fieldSource }); if (result.IsError) { return(StandardResult <string> .ReturnError(result.String)); } if (!result.IsString) { return(StandardResult <string> .ReturnError("message processing error - expression evaulation did not result in a string")); } return(StandardResult <string> .ReturnResult(result.String)); }
public void FacetFieldParameter002() { // Arrange var expected = JObject.Parse(@" { ""facet"": { ""Id"": { ""terms"": { ""field"": ""_id_"", ""mincount"": 1, ""sort"": { ""count"": ""desc"" } } } } }"); string actual; var jObject = new JObject(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetFieldParameter <TestDocument>(expressionBuilder); parameter.Configure(q => q.Id, FacetSortType.CountDesc); // Act parameter.Execute(jObject); actual = jObject.ToString(); // Assert Assert.Equal(expected.ToString(), actual); }
/// <summary> /// Initializes a new instance of the <see cref="SortCollectionManager"/> class. /// </summary> /// <param name="sourceCollection">The collection of <see cref="SortDescriptor"/>s to manage</param> /// <param name="descriptionCollection">The collection of <see cref="SortDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param> /// <param name="expressionCache">The cache with entries for the <see cref="SortDescriptor"/>s</param> /// <param name="validationAction">The callback for validating items that are added or changed</param> public SortCollectionManager(SortDescriptorCollection sourceCollection, SortDescriptionCollection descriptionCollection, ExpressionCache expressionCache, Action<SortDescriptor> validationAction) { if (sourceCollection == null) { throw new ArgumentNullException("sourceCollection"); } if (descriptionCollection == null) { throw new ArgumentNullException("descriptionCollection"); } if (expressionCache == null) { throw new ArgumentNullException("expressionCache"); } if (validationAction == null) { throw new ArgumentNullException("validationAction"); } this._sourceCollection = sourceCollection; this._descriptionCollection = descriptionCollection; this.ExpressionCache = expressionCache; this.ValidationAction = (item) => validationAction((SortDescriptor)item); this.AsINotifyPropertyChangedFunc = (item) => ((SortDescriptor)item).Notifier; ((INotifyCollectionChanged)descriptionCollection).CollectionChanged += this.HandleDescriptionCollectionChanged; this.AddCollection(sourceCollection); }
/// <summary> /// Initializes a new instance of the <see cref="GroupCollectionManager"/> class. /// </summary> /// <param name="sourceCollection">The collection of <see cref="GroupDescriptor"/>s to manage</param> /// <param name="descriptionCollection">The collection of <see cref="GroupDescription"/>s to synchronize with the <paramref name="sourceCollection"/></param> /// <param name="expressionCache">The cache with entries for the <see cref="GroupDescriptor"/>s</param> /// <param name="validationAction">The callback for validating items that are added or changed</param> public GroupCollectionManager(GroupDescriptorCollection sourceCollection, ObservableCollection<GroupDescription> descriptionCollection, ExpressionCache expressionCache, Action<GroupDescriptor> validationAction) { if (sourceCollection == null) { throw new ArgumentNullException("sourceCollection"); } if (descriptionCollection == null) { throw new ArgumentNullException("descriptionCollection"); } if (expressionCache == null) { throw new ArgumentNullException("expressionCache"); } if (validationAction == null) { throw new ArgumentNullException("validationAction"); } this._sourceCollection = sourceCollection; this._descriptionCollection = descriptionCollection; this.ExpressionCache = expressionCache; this._groupValidationAction = validationAction; this.ValidationAction = this.Validate; this.AsINotifyPropertyChangedFunc = this.AsINotifyPropertyChanged; this.AddCollection(sourceCollection); this.AddCollection(descriptionCollection); }
public void FacetQueryParameter005() { // Arrange var expected = JObject.Parse(@" { ""facet"": { ""X"": { ""query"": { ""q"": ""{!ex=tag1,tag2}avg('Y')"", ""mincount"": 1 } } } }"); string actual; var jObject = new JObject(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetQueryParameter <TestDocument>(expressionBuilder); parameter.Configure("X", new Any <TestDocument>("avg('Y')"), excludes: new[] { "tag1", "tag2" }); // Act parameter.Execute(jObject); actual = jObject.ToString(); // Assert Assert.Equal(expected.ToString(), actual); }
public void FacetQueryParameter002() { // Arrange var expected = JObject.Parse(@" { ""facet"": { ""X"": { ""query"": { ""q"": ""avg('Y')"", ""mincount"": 1, ""sort"": { ""count"": ""desc"" } } } } }"); string actual; var jObject = new JObject(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetQueryParameter <TestDocument>(expressionBuilder); parameter.Configure("X", new Any <TestDocument>("avg('Y')"), FacetSortType.CountDesc); // Act parameter.Execute(jObject); actual = jObject.ToString(); // Assert Assert.Equal(expected.ToString(), actual); }
public static StandardResult <SimpleTable> Execute(SimpleTable sourceTable, SimpleTable expandTable) { if (sourceTable == null) { return(StandardResult <SimpleTable> .ReturnError("ExpandTable() error: source table null")); } if (expandTable == null) { return(StandardResult <SimpleTable> .ReturnError("ExpandTable() error: aggregate table null")); } var newTable = sourceTable.Copy(); // create columns foreach (var map in expandTable) { var source = map["source"]; var destination = map["destination"]; newTable.AddColumnName(destination); var expression = ExpressionCache.Compile(source); if (expression == null) { return(StandardResult <SimpleTable> .ReturnError("AggregateTable() error: evaluator returns null", "Source: " + source)); } } var fieldSource = new FieldDataSource(); foreach (var newRow in newTable) { fieldSource.Row = newRow; foreach (var map in expandTable) { var source = map["source"]; var destination = map["destination"]; var expression = ExpressionCache.Compile(source); var result = expression.Evaluate(new Context() { FieldSource = fieldSource }); if (result.IsError) { return(StandardResult <SimpleTable> .ReturnError("ExpandTable() error: occurred during evaluating: " + expression.Parser.Tokenizer.Expression, result.String)); } newRow[destination] = ToString(result); } } return(StandardResult <SimpleTable> .ReturnResult(newTable)); }
public void FacetQueryParameter006() { // Arrange var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetQueryParameter <TestDocument>(expressionBuilder); // Act / Assert Assert.Throws <ArgumentNullException>(() => parameter.Configure("x", null)); }
public void SpatialFilterParameter004() { // Arrange var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new SpatialFilterParameter <TestDocument>(expressionBuilder); // Act / Assert Assert.Throws <ArgumentNullException>(() => parameter.Configure(null, SolrSpatialFunctionType.Bbox, new GeoCoordinate(), 10)); }
public void FacetRangeParameter016() { // Arrange / Act / Assert var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetRangeParameter <TestDocument>(expressionBuilder); // Act / Assert Assert.Throws <ArgumentNullException>(() => parameter.Configure("x", q => q.Id, "", "", null)); }
public void FieldListParameter007() { // Arrange var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FieldListParameter <TestDocument>(expressionBuilder); // Act / Assert Assert.Throws <ArgumentException>(() => parameter.Configure(new Expression <Func <TestDocument, object> >[] { })); }
public void FieldsParameter004() { // Arrange var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FieldsParameter <TestDocument>(expressionBuilder); // Act / Assert Assert.Throws <ArgumentNullException>(() => parameter.Configure(null)); }
protected StandardResult <Value> InternalExecute(string command) { if (string.IsNullOrWhiteSpace(command)) { return(ReturnResult <Value>(new Value(string.Empty))); } if (command.StartsWith("#")) { return(ReturnResult <Value>(new Value(string.Empty))); } var variable = string.Empty; var expressionText = string.Empty; int posEqual = command.IndexOf('='); if (posEqual > 0) { expressionText = command.Substring(posEqual + 1); variable = command.Substring(0, posEqual - 1); } else { variable = string.Empty; expressionText = command; } var expression = ExpressionCache.Compile(expressionText); if (!expression.IsValid) { return(ReturnError <Value>("ValidateTable() error: occurred during evaluating: " + expression.Parser.Tokenizer.Expression)); } var result = expression.Evaluate(new Context() { MethodSource = this, VariableSource = this }); if (result.IsError) { return(ReturnError <Value>(result.String)); } if (!string.IsNullOrWhiteSpace(variable)) { Variables.Remove(variable); Variables.Add(variable, result); } return(ReturnResult <Value>(result)); }
public void FacetFieldParameter003() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetFieldParameter <TestDocument>(expressionBuilder); parameter.Configure(q => q.Id, FacetSortType.CountDesc); // Act / Assert Assert.Throws <UnsupportedSortTypeException>(() => parameter.Execute(container)); }
public void FacetRangeParamete011() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetRangeParameter <TestDocument>(expressionBuilder); parameter.Configure("X", q => q.Id, "1", "10", "20", true, true, FacetSortType.IndexDesc); // Act / Assert Assert.Throws <UnsupportedSortTypeException>(() => parameter.Execute(container)); }
public void ExpressionBuilder001() { // Arrange string name; var expressionCache = new ExpressionCache <Document>(); var expressionBuilder = (IExpressionBuilder <Document>) new ExpressionBuilder <Document>(expressionCache); // Act name = expressionBuilder.GetFieldNameFromExpression(q => q.PropertyString); // Assert Assert.Equal("PropertyString", name); }
public void ExpressionBuilder016() { // Arrange string name; var expressionCache = new ExpressionCache <Document>(); var expressionBuilder = (IExpressionBuilder <Document>) new ExpressionBuilder <Document>(expressionCache); // Act name = expressionBuilder.GetFieldNameFromExpression(q => q.PropertyDateTimeOffsetWithAttr); // Assert Assert.Equal("PropDateTimeOffset", name); }
public void FacetQueryParameter004() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FacetQueryParameter <TestDocument>(expressionBuilder); parameter.Configure("X", new QueryAll <TestDocument>(), FacetSortType.IndexDesc); // Act / Assert Assert.Throws <UnsupportedSortTypeException>(() => parameter.Execute(container)); }
private static Expression <Func <TSource, TDest> > BuildExpression <TDest>(Dictionary <int, int> parameterIndexs, int index = 0) { var cachedExp = GetCachedExpression <TDest>(); if (cachedExp != null) { return(cachedExp); } lock (ExpressionCache) { cachedExp = GetCachedExpression <TDest>(); if (cachedExp != null) { return(cachedExp); } var config = GetCachedConfig(typeof(TSource), typeof(TDest)); var hasConfig = config != null; var sourceProperties = typeof(TSource).GetProperties(); var destinationProperties = typeof(TDest).GetProperties().Where(dest => dest.CanWrite); if (hasConfig) { destinationProperties = destinationProperties.Where(dest => !config.IgnoreMembers.Contains(dest.Name)); } var parameterExpression = Expression.Parameter(typeof(TSource), string.Concat("src", typeof(TSource).Name, index)); var bindings = destinationProperties .Select(destinationProperty => HasCustomExpression(config, destinationProperty) ? BuildCustomBinding(config, parameterExpression, destinationProperty) : BuildBinding(parameterExpression, destinationProperty, sourceProperties, config, parameterIndexs, index) ) .Where(binding => binding != null); var expression = Expression.Lambda <Func <TSource, TDest> >( Expression.MemberInit(Expression.New(typeof(TDest)), bindings), parameterExpression); var key = GetCacheKey <TDest>(); ExpressionCache.Add(key, expression); return(expression); } }
public void FacetRangeResult002() { // Arrange var jObject = JObject.Parse(@" { ""facets"": { ""count"": 100, ""facetRange"": { ""buckets"": [ { ""val"": ""2014-06-22T20:33:00.741Z"", ""count"": 10 }, { ""val"": ""2014-06-28T20:33:00.741Z"", ""count"": 20 } ], ""before"": { ""count"": 30 }, ""after"": { ""count"": 40 } } } }"); var expressionCache = new ExpressionCache <TestDocumentWithAnyPropertyTypes>(); var expressionBuilder = (IExpressionBuilder <TestDocumentWithAnyPropertyTypes>) new ExpressionBuilder <TestDocumentWithAnyPropertyTypes>(expressionCache); var parameters = new List <ISearchParameter> { new FacetRangeParameter <TestDocumentWithAnyPropertyTypes>(expressionBuilder).Configure("facetRange", q => q.PropDateTime, "+10DAYS", "NOW/DATE-1", "NOW/DAY+1") }; var result = (IConvertJsonObject) new FacetRangeResult <TestDocumentWithAnyPropertyTypes>(expressionBuilder); // Act result.Execute(parameters, jObject); // Assert var data = ((IFacetRangeResult <TestDocumentWithAnyPropertyTypes>)result).Data.ToList(); Assert.Equal(1, data.Count); Assert.Equal("facetRange", data[0].Name); Assert.Equal(4, data[0].Data.Count()); Assert.IsType(typeof(FacetRange <DateTime>), data[0].Data.First().Key); }
public void BoostParameter002() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new BoostParameter <TestDocument>(expressionBuilder); parameter.Configure(new Any <TestDocument>("id"), BoostFunctionType.Boost); // Act parameter.Execute(container); // Assert Assert.Equal(1, container.Count); Assert.Equal("boost=id", container[0]); }
public void Range004() { // Arrange var expected = "_id_:[1 TO *]"; string actual; var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new Range <TestDocument, int>(q => q.Id, 1, null); parameter.ExpressionBuilder = expressionBuilder; // Act actual = parameter.Execute(); // Assert Assert.Equal(expected, actual); }
public void QueryParameter001() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new QueryParameter <TestDocument>(expressionBuilder); parameter.Configure(new Single <TestDocument>(q => q.Id, "ITEM01")); // Act parameter.Execute(container); // Assert Assert.Equal(1, container.Count); Assert.Equal("q=_id_:ITEM01", container[0]); }
public void SpatialFilterParameter006() { // Arrange bool isValid; string errorMessage; var expressionCache = new ExpressionCache <TestDocumentWithAttribute>(); var expressionBuilder = (IExpressionBuilder <TestDocumentWithAttribute>) new ExpressionBuilder <TestDocumentWithAttribute>(expressionCache); var parameter = new SpatialFilterParameter <TestDocumentWithAttribute>(expressionBuilder); parameter.Configure(q => q.Indexed, SolrSpatialFunctionType.Geofilt, new GeoCoordinate(), 0); // Act parameter.Validate(out isValid, out errorMessage); // Assert Assert.True(isValid); }
public void SpatialFilterParameter003() { // Arrange bool actual; string dummy; var expressionCache = new ExpressionCache <TestDocumentWithAttribute>(); var expressionBuilder = (IExpressionBuilder <TestDocumentWithAttribute>) new ExpressionBuilder <TestDocumentWithAttribute>(expressionCache); var parameter = new SpatialFilterParameter <TestDocumentWithAttribute>(expressionBuilder); parameter.Configure(q => q.NotIndexed, SolrSpatialFunctionType.Geofilt, new GeoCoordinate(), 0); // Act parameter.Validate(out actual, out dummy); // Assert Assert.False(actual); }
private void CalDecisionValue() { SysActivity activity = this.AI.Activity; if ((activity.Expressions == null) || (activity.Expressions.Count == 0)) { throw new ApplicationException("活动没有表达式"); } if (!activity.ExpressionId.HasValue) { throw new ApplicationException("未指定活动的表达式"); } SysExpression expr = activity.Expressions.FirstOrDefault <SysExpression>(e => e.ExpressionId == activity.ExpressionId.Value); if (expr == null) { throw new ApplicationException("指定的表达式不在活动的表达式中"); } Queue <SysExpression> calOrder = ExpressionHelper.GetCalOrder(activity.Expressions.ToList <SysExpression>()); if (calOrder.Count <SysExpression>(p => (p.ExpressionId == expr.ExpressionId)) <= 0) { throw new ApplicationException("无法计算表达式的值"); } EntityCache cache = new EntityCache(base.Manager); ExpressionCache cache2 = new ExpressionCache(); while (calOrder.Count > 0) { SysExpression expression = calOrder.Dequeue(); object obj2 = ExpressionHelper.GetHelper(expression).GetValue(expression, cache, cache2, base.PI, this.AI); if (expression.ExpressionId == expr.ExpressionId) { if (obj2 == null) { throw new ApplicationException("决策活动的值返回null"); } if (obj2.GetType() != typeof(bool)) { throw new ApplicationException("决策活动的值不是布尔类型"); } this.AI.ExpressionValue = new int?(Convert.ToInt32(obj2)); return; } } }
public void SpatialFilterParameter002() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new SpatialFilterParameter <TestDocument>(expressionBuilder); parameter.Configure(q => q.Spatial, SolrSpatialFunctionType.Bbox, new GeoCoordinate(-1.1M, -2.2M), 5.5M); // Act parameter.Execute(container); // Assert Assert.Equal(1, container.Count); Assert.Equal("fq={!bbox sfield=_spatial_ pt=-1.1,-2.2 d=5.5}", container[0]); }
public void FilterQueryParameter003() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new FilterQueryParameter <TestDocument>(expressionBuilder); parameter.Configure(new Single <TestDocument>(q => q.Id, "X"), "tag1"); // Act parameter.Execute(container); // Assert Assert.Equal(1, container.Count); Assert.Equal("fq={!tag=tag1}_id_:X", container[0]); }
public void SpatialFilterParameter008() { // Arrange var container = new List <string>(); var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); var parameter = new SpatialFilterParameter <TestDocument>(expressionBuilder); parameter.Configure(q => q.Spatial, SolrSpatialFunctionType.Geofilt, new GeoCoordinate(52.9127M, 4.7818799M), 1M); // Act parameter.Execute(container); // Assert Assert.Equal(1, container.Count); Assert.Equal("fq={!geofilt sfield=_spatial_ pt=52.9127,4.7818799 d=1}", container[0]); }
public void Setup() { var expressionCache = new ExpressionCache <TestDocument>(); var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache); this._parameters = new List <ISearchParameter> { new FacetRangeParameter <TestDocument>(expressionBuilder).Configure("facetRange", q => q.Age, "10", "10", "100") }; this._facetRangeResult = new FacetRangeResult <TestDocument>(expressionBuilder); // Data using http://www.json-generator.com/ var assembly = typeof(FacetRangeResultBenchmarks).GetTypeInfo().Assembly; var str = EmbeddedResourceHelper.GetByName(assembly, $"SolrExpress.Benchmarks.Solr4.Search.Result.FacetRangeResultBenchmarks{this.ElementsCount}.json"); this._jsonObject = JObject.Parse(str); }
/// <summary> /// Initializes a new instance of the <see cref="FilterCollectionManager"/> class. /// </summary> /// <param name="sourceCollection">The collection of <see cref="FilterDescriptor"/>s to manage</param> /// <param name="expressionCache">The cache with entries for the <see cref="FilterDescriptor"/>s</param> /// <param name="validationAction">The callback for validating items that are added or changed</param> public FilterCollectionManager(FilterDescriptorCollection sourceCollection, ExpressionCache expressionCache, Action<FilterDescriptor> validationAction) { if (sourceCollection == null) { throw new ArgumentNullException("sourceCollection"); } if (expressionCache == null) { throw new ArgumentNullException("expressionCache"); } if (validationAction == null) { throw new ArgumentNullException("validationAction"); } this.ExpressionCache = expressionCache; this._sourceCollection = sourceCollection; this.ValidationAction = (item) => validationAction((FilterDescriptor)item); this.AsINotifyPropertyChangedFunc = (item) => ((FilterDescriptor)item).Notifier; this.AddCollection(this._sourceCollection); }
/// <summary> /// Produces the Linq expression representing the entire filter descriptors collection. /// </summary> /// <param name="filterDescriptors">Collection of filters</param> /// <param name="filterOperator">The operator used to combine filters</param> /// <param name="expressionCache">Cache for storing built expressions</param> /// <returns>Produced linq expression, which can be <c>null</c> if there are no filter descriptors.</returns> public static Expression BuildFiltersExpression( FilterDescriptorCollection filterDescriptors, FilterDescriptorLogicalOperator filterOperator, ExpressionCache expressionCache) { Debug.Assert(filterDescriptors != null, "Unexpected null filterDescriptors"); Expression filtersExpression = null; foreach (FilterDescriptor filterDescriptor in filterDescriptors) { // Ignored filters will not have a cache entry if (expressionCache.ContainsKey(filterDescriptor)) { Expression filterExpression = expressionCache[filterDescriptor]; if (filtersExpression == null) { filtersExpression = filterExpression; } else if (filterOperator == FilterDescriptorLogicalOperator.And) { filtersExpression = Expression.AndAlso(filtersExpression, filterExpression); } else { filtersExpression = Expression.OrElse(filtersExpression, filterExpression); } } } return filtersExpression; }
public void CollectionManagerCollatesGroupDescriptorEvents() { GroupDescriptorCollection collection = new GroupDescriptorCollection(); ObservableCollection<GroupDescription> descriptionCollection = new ObservableCollection<GroupDescription>(); ExpressionCache cache = new ExpressionCache(); GroupDescriptor descriptor = null; this.CollectionManagerCollatesTemplate( (validationAction) => { return new GroupCollectionManager(collection, descriptionCollection, cache, gd => validationAction()); }, () => { collection.Add(new GroupDescriptor()); }, () => { collection[0].PropertyPath = "First"; }, () => { collection.Add(new GroupDescriptor()); }, () => { collection[1].PropertyPath = "Second"; }, () => { collection[1] = new GroupDescriptor(); }, () => { descriptor = collection[0]; collection.Remove(descriptor); }, () => { descriptor.PropertyPath = "Removed"; }); }
public void CollectionManagerCollatesSortDescriptorEvents() { SortDescriptorCollection collection = new SortDescriptorCollection(); SortDescriptionCollection descriptionCollection = new SortDescriptionCollection(); ExpressionCache cache = new ExpressionCache(); SortDescriptor descriptor = null; this.CollectionManagerCollatesTemplate( (validationAction) => { return new SortCollectionManager(collection, descriptionCollection, cache, sd => validationAction()); }, () => { collection.Add(new SortDescriptor()); }, () => { collection[0].PropertyPath = "First"; }, () => { collection.Add(new SortDescriptor()); }, () => { collection[1].PropertyPath = "Second"; }, () => { collection[1] = new SortDescriptor(); }, () => { descriptor = collection[0]; collection.Remove(descriptor); }, () => { descriptor.PropertyPath = "Removed"; }); }
public PropertyValidationReport(ExpressionCache expressionCache) { if (expressionCache == null) throw new System.ArgumentNullException("expressionCache"); _expressionCache = expressionCache; }
/// <summary> /// Composes an <see cref="EntityQuery" /> for sorting and grouping purposes. /// </summary> /// <param name="source">The queryable source.</param> /// <param name="groupDescriptors">The group descriptors.</param> /// <param name="sortDescriptors">The sort descriptors.</param> /// <param name="expressionCache">Cache for storing built expressions</param> /// <returns>The composed <see cref="EntityQuery" />.</returns> public static EntityQuery OrderBy( EntityQuery source, GroupDescriptorCollection groupDescriptors, SortDescriptorCollection sortDescriptors, ExpressionCache expressionCache) { Debug.Assert(source != null, "Unexpected null source"); Debug.Assert(sortDescriptors != null, "Unexpected null sortDescriptors"); Debug.Assert(groupDescriptors != null, "Unexpected null groupDescriptors"); bool hasOrderBy = false; // check the GroupDescriptors first foreach (GroupDescriptor groupDescriptor in groupDescriptors) { if (groupDescriptor != null && groupDescriptor.PropertyPath != null) { Debug.Assert(expressionCache.ContainsKey(groupDescriptor), "There should be a cached group expression"); // check to see if we sort by the same parameter in desc order bool sortAsc = true; foreach (SortDescriptor sortDescriptor in sortDescriptors) { if (sortDescriptor != null) { string sortDescriptorPropertyPath = sortDescriptor.PropertyPath; string groupDescriptorPropertyPath = groupDescriptor.PropertyPath; if (sortDescriptorPropertyPath != null && sortDescriptorPropertyPath.Equals(groupDescriptorPropertyPath)) { if (sortDescriptor.Direction == ListSortDirection.Descending) { sortAsc = false; } break; } } } string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy"); if (!sortAsc) { orderMethodName += "Descending"; } source = OrderBy(source, orderMethodName, expressionCache[groupDescriptor]); hasOrderBy = true; } } // then check the SortDescriptors foreach (SortDescriptor sortDescriptor in sortDescriptors) { if (sortDescriptor != null) { Debug.Assert(expressionCache.ContainsKey(sortDescriptor), "There should be a cached sort expression"); string orderMethodName = (!hasOrderBy ? "OrderBy" : "ThenBy"); if (sortDescriptor.Direction == ListSortDirection.Descending) { orderMethodName += "Descending"; } source = OrderBy(source, orderMethodName, expressionCache[sortDescriptor]); hasOrderBy = true; } } return source; }
public PropertyValidationReport() { _expressionCache = RulesEngine.DefaultExpressionCache; }