private void dataGrid_FilterChanging(object sender, GridFilterEventArgs e) { if (!DateFilterColumnsName.Contains(e.Column.MappingName)) { return; } if (e.FilterPredicates == null) { return; } //Due to performance reasons in SfDataGrid FilterPredicates are created based on Checked and UnChecked items count (Which count is less) //so need to change the FilterPredicates after changing DisplayText of FilterElement. if (checkedItems.Count() > unCheckedItems.Count()) { e.FilterPredicates.Clear(); var init = true; foreach (var filterelement in checkedItems) { var c = new FilterPredicate(); c.FilterValue = filterelement.ActualValue; c.FilterBehavior = FilterBehavior.StringTyped; c.FilterType = Syncfusion.Data.FilterType.Contains; c.PredicateType = init ? PredicateType.And : PredicateType.Or; init = false; e.FilterPredicates.Add(c); } } }
/// <summary> /// Assigns a proxy predicate to a multi-attributed expression. /// </summary> private static IProxyPredicate GetMultiAttributePredicate(ComparisonPredicate expression, ICollection <IIndex> indices, IQueryStore queryStore) { var candidatesList = new OrderedList <int, IIndex>(); foreach (var index in indices) { List <string> indexAttributes = new List <string>(); indexAttributes.Add(index.Attributes.Name); if (ContainsRange(indexAttributes, expression.AttributeNames)) { candidatesList.Add(index.KeyCount, index); } } if (candidatesList.Count > 0) { var predicate = new FilterPredicate(expression, candidatesList.FirstValues[0]); predicate.AddChildPredicate(new AllPredicate(candidatesList.FirstValues[0])); return(new ProxyPredicate(predicate, expression)); } return(new ProxyPredicate(new StorePredicate(expression, queryStore), expression)); }
/// <summary> /// Gets the list of FilterPredicates for the corresponding column. /// </summary> /// <param name="filterValue">Value that want to be filter in corresponding column.</param> /// <returns> /// Returns the list of FilterPredicates that have been generated for the particular column. /// </returns> protected List<FilterPredicate> GetFilterPredicates(object filterValue) { var column = this.FilterRowCell.DataColumn.GridColumn; if (column == null) return null; var filterPredicates = new List<FilterPredicate>(); if (column.FilterRowCondition == FilterRowCondition.NotNull || column.FilterRowCondition == FilterRowCondition.Null) filterValue = null; else if (column.FilterRowCondition == FilterRowCondition.Empty || column.FilterRowCondition == FilterRowCondition.NotEmpty) filterValue = string.Empty; else if ((filterValue == null || filterValue.ToString() == string.Empty)) return filterPredicates; var filterMode = isSupportDisplayTextFiltering(column) || (column.GetType() != typeof(GridTextColumn) && column.GetFilterBehavior() == FilterBehavior.StringTyped) ? ColumnFilter.DisplayText : ColumnFilter.Value; var filterPredicate = new FilterPredicate() { FilterBehavior = column.GetFilterBehavior(), FilterType = FilterRowHelpers.GetFilterType(column.FilterRowCondition), FilterValue = filterValue, IsCaseSensitive = column.IsCaseSensitiveFilterRow, PredicateType = PredicateType.And , FilterMode = filterMode }; filterPredicates.Add(filterPredicate); return filterPredicates; }
public override string PushDown() { if (!IsPredicateSet) { return(String.Empty); } IsPushedDown = true; string result = ""; switch (ColumnName) { case FilterColumnName.ApplicationName: result = "sqlserver.client_app_name"; break; case FilterColumnName.HostName: result = "sqlserver.client_hostname"; break; case FilterColumnName.LoginName: result = "sqlserver.server_principal_name"; break; case FilterColumnName.DatabaseName: result = "sqlserver.database_name"; break; } result += " " + FilterPredicate.ComparisonOperatorAsString(ComparisonOperator) + " N'" + EscapeFilter(PredicateValue) + "'"; return(result); }
void CommitFilterOpCombo() { var dataGridViewComboBoxEditingControl = dataGridViewFilter.EditingControl as DataGridViewComboBoxEditingControl; if (dataGridViewComboBoxEditingControl == null || dataGridViewFilter.CurrentRow == null) { return; } var rowIndex = dataGridViewFilter.CurrentRow.Index; var filterOperation = FilterOperationFromDisplayName(dataGridViewComboBoxEditingControl.Text); if (filterOperation == null) { return; } if (filterOperation == ViewInfo.Filters[rowIndex].FilterSpec.Operation) { return; } var newFilters = ViewSpec.Filters.ToArray(); var columnDescriptor = ViewInfo.Filters[rowIndex].ColumnDescriptor; newFilters[rowIndex] = newFilters[rowIndex].SetPredicate( FilterPredicate.CreateFilterPredicate(columnDescriptor.DataSchema, columnDescriptor.PropertyType, filterOperation, dataGridViewFilter.CurrentRow.Cells[colFilterOperand.Index].Value as string)); ViewSpec = ViewSpec.SetFilters(newFilters); }
private string GetOperandError <T>(string operand) { var dataSchema = new DataSchema(); var rootColumn = ColumnDescriptor.RootColumn(dataSchema, typeof(DataRowWithProperty <T>)); var column = rootColumn.ResolveChild("Property"); var stringWriter = new StringWriter(); using (var xmlTextWriter = new XmlTextWriter(stringWriter)) { xmlTextWriter.WriteStartElement("filter"); xmlTextWriter.WriteAttributeString("opname", FilterOperations.OP_EQUALS.OpName); xmlTextWriter.WriteAttributeString("operand", operand); xmlTextWriter.WriteEndElement(); } var xmlReader = new XmlTextReader(new StringReader(stringWriter.ToString())); while (!xmlReader.IsStartElement()) { xmlReader.Read(); } FilterPredicate filterPredicate = FilterPredicate.ReadXml(xmlReader); FilterInfo filterInfo = new FilterInfo(new FilterSpec(column.PropertyPath, filterPredicate), column, rootColumn); return(filterInfo.Error); }
public void TestFilterSpecRoundTrips() { var propertyPath = PropertyPath.Root.Property("property"); var invariantDataSchema = new DataSchema(); foreach (var cultureInfo in ListTestCultureInfos()) { var dataSchema = new DataSchema(new DataSchemaLocalizer(cultureInfo)); foreach (var testOperand in ListTestOperands()) { var columnType = testOperand.GetType(); var filterPredicate = FilterPredicate.CreateFilterPredicate(dataSchema, columnType, FilterOperations.OP_EQUALS, ValueToString(testOperand, cultureInfo)); var invariantFilterPredicate = FilterPredicate.CreateFilterPredicate(invariantDataSchema, columnType, FilterOperations.OP_EQUALS, ValueToString(testOperand, CultureInfo.InvariantCulture)); Assert.AreEqual(invariantFilterPredicate, filterPredicate); var filterSpec = new FilterSpec(propertyPath, filterPredicate); var predicateOperandValue = filterSpec.Predicate.GetOperandValue(dataSchema, columnType); var expectedOperandValue = predicateOperandValue is double ?Convert.ChangeType(testOperand, typeof(double)) : testOperand; Assert.AreEqual(expectedOperandValue, predicateOperandValue); Assert.AreEqual(ValueToString(testOperand, cultureInfo), filterSpec.Predicate.GetOperandDisplayText(dataSchema, columnType)); var filterSpecRoundTrip = RoundTripToXml(filterSpec); Assert.AreEqual(expectedOperandValue, filterSpecRoundTrip.Predicate.GetOperandValue(dataSchema, columnType)); Assert.AreEqual(ValueToString(testOperand, cultureInfo), filterSpecRoundTrip.Predicate.GetOperandDisplayText(dataSchema, columnType)); } } }
public void TestViewLayoutRowTransforms() { var dataSchema = new DataSchema(); var viewLayout = new ViewLayout("TestName").ChangeRowTransforms( new IRowTransform[] { new PivotSpec() .ChangeRowHeaders(new[] { new PivotSpec.Column(new ColumnId("RowHeaderOne")).ChangeCaption("MyCaption") }) .ChangeColumnHeaders(new[] { new PivotSpec.Column(new ColumnId("ColumnOne")), }) .ChangeValues(new[] { (PivotSpec.AggregateColumn) new PivotSpec.AggregateColumn(new ColumnId("ValueOne"), AggregateOperation.Cv).ChangeCaption("Aggregate column caption"), }), new RowFilter("filterText", true, new[] { new RowFilter.ColumnFilter(new ColumnId("column1"), FilterPredicate.CreateFilterPredicate(dataSchema, typeof(string), FilterOperations.OP_CONTAINS, "contains1")) }).SetColumnSorts(new[] { new RowFilter.ColumnSort(new ColumnId("columnSort1"), ListSortDirection.Ascending), new RowFilter.ColumnSort(new ColumnId("columnSort2"), ListSortDirection.Descending) }) } ).ChangeColumnFormats(new [] { Tuple.Create(new ColumnId("ColumnId1"), ColumnFormat.EMPTY.ChangeFormat("R").ChangeWidth(20)) }); var viewLayoutList = new ViewLayoutList("Test").ChangeLayouts(new [] { viewLayout }) .ChangeDefaultLayoutName("TestName"); var roundTrip = RoundTripToXml(viewLayoutList); Assert.AreEqual(viewLayoutList, roundTrip); }
private RowFilter.ColumnFilter CreateColumnFilter(ColumnId columnId, IFilterOperation filterOp, double operand) { var op = FilterPredicate.CreateFilterPredicate(_bindingListSource.ViewInfo.DataSchema, typeof(double), filterOp, operand.ToString(CultureInfo.CurrentCulture)); return(new RowFilter.ColumnFilter(columnId, op)); }
private static FilterPredicate TranslateFilterPredicate(Expression expression) { if (expression is BinaryExpression binaryExpression) { var filterPredicate = new FilterPredicate(); var groups = TranslateFilterGroup(binaryExpression); groups.ForEach(g => filterPredicate.Groups.Add(g)); return(filterPredicate); } throw new NotSupportedException($"Cannot translate FilterPredicate \"{expression}\" because {expression.NodeType} node is not supported."); }
public override string ToString() { var oDataQueryParts = new List <string>(10) { FormatPredicate.ToString() }; if (CountPredicate != null) { oDataQueryParts.Add(CountPredicate.ToString()); } if (ExpandPredicate != null) { oDataQueryParts.Add(ExpandPredicate.ToString()); } if (FilterPredicate != null) { oDataQueryParts.Add(FilterPredicate.ToString()); } if (OrderByPredicate != null) { oDataQueryParts.Add(OrderByPredicate.ToString()); } if (SelectPredicate != null) { oDataQueryParts.Add(SelectPredicate.ToString()); } if (SkipPredicate != null) { oDataQueryParts.Add(SkipPredicate.ToString()); } if (SkipTokenPredicate != null) { oDataQueryParts.Add(SkipTokenPredicate.ToString()); } if (TopPredicate != null) { oDataQueryParts.Add(TopPredicate.ToString()); } if (InlineCountPredicate != null) { oDataQueryParts.Add(InlineCountPredicate.ToString()); } return($"?{String.Join("&", oDataQueryParts)}"); }
private FilterPredicate SafeCreateFilterPredicate(DataSchema dataSchema, Type columnType, IFilterOperation filterOperation, string operand) { try { return(FilterPredicate.CreateFilterPredicate(dataSchema, columnType, filterOperation, operand)); } catch { return(FilterPredicate.CreateFilterPredicate(dataSchema, typeof(string), filterOperation, operand)); } }
public FilterPredicate GetPredicateExpression(IQueryable <TEntity> query, AdvancedFilterModel filter, ParameterExpression accessExpression) { var resultPredicate = GetSingleFilterPredicateExpression(filter, accessExpression); var filterPredicate = new FilterPredicate() { Predicate = resultPredicate, OperatorType = filter.FilterLinkCondition }; return(filterPredicate); }
private List <TObjectType> GetObjects(string sqlQuery, CSParameterCollection parameters, Dictionary <string, string> aliasMap, IEnumerable <PrefetchField> prefetchFields) { using (CSTransaction csTransaction = new CSTransaction(Schema)) { List <TObjectType> objectList = new List <TObjectType>(); using (ICSDbReader reader = DB.CreateReader(sqlQuery, parameters)) { while (reader.Read()) { TObjectType csObject = CSObject <TObjectType> .New(); csObject.Fire_ObjectReading(); csObject.FromDataReader(reader, aliasMap); foreach (PrefetchField prefetchField in prefetchFields) { csObject.ReadRelationToOne(prefetchField.SchemaField, reader, prefetchField.AliasMap); } if (FilterPredicate != null) { bool shouldAdd = true; foreach (Predicate <TObjectType> predicate in FilterPredicate.GetInvocationList()) { if (!predicate(csObject)) { shouldAdd = false; break; } } if (!shouldAdd) { continue; } } csObject.ObjectDeleted += OnObjectDeleted; objectList.Add(csObject); csObject.Fire_ObjectRead(); } } csTransaction.Commit(); return(objectList); } }
private RowFilter.ColumnFilter MakeColumnFilter(ComboBox comboOperation, TextBox text) { FilterItem filterItem = comboOperation.SelectedItem as FilterItem; if (null == filterItem || FilterOperations.OP_HAS_ANY_VALUE == filterItem.FilterOperation) { return(null); } var filterPredicate = FilterPredicate.CreateFilterPredicate(DataSchema, PropertyDescriptor.PropertyType, filterItem.FilterOperation, text.Text); return(new RowFilter.ColumnFilter(ColumnId.GetColumnId(PropertyDescriptor), filterPredicate)); }
public override string PushDown() { if (!IsPredicateSet) { return(String.Empty); } IsPushedDown = true; string result = ColumnName.ToString(); result += " " + FilterPredicate.ComparisonOperatorAsString(ComparisonOperator) + " N'" + EscapeFilter(PredicateValue) + "'"; return(result); }
public void SingleTest(FilterPredicate pred, string predStr) { var titleProp = "title"; var titleVal = "test title"; var builder = new AgilityContentFilterBuilder() .AddFilter(titleProp, titleVal, pred); var filterStr = builder.Build(); var expected = WebUtility.UrlEncode($"{titleProp}[{predStr}]{titleVal}"); Assert.Equal(expected, filterStr); }
public void TestDataBindingIsSulfur() { var dataSchema = new DataSchema(); var viewSpec = new ViewSpec().SetColumns(new[] { new ColumnSpec(PropertyPath.Parse("Code")), new ColumnSpec(PropertyPath.Parse("Molecule!*.Key")), }) .SetFilters(new[] { new FilterSpec(PropertyPath.Parse("Molecule!*.Key"), FilterPredicate.CreateFilterPredicate(dataSchema, typeof(string), FilterOperations.OP_EQUALS, "S")) }); var bindingListSource = new BindingListSource(); bindingListSource.SetView(new ViewInfo(dataSchema, typeof(AminoAcid), viewSpec), AminoAcid.AMINO_ACIDS); Assert.AreEqual(2, bindingListSource.Count); }
public override string PushDown() { if (!IsPredicateSet) { return(String.Empty); } IsPushedDown = true; string result = "("; bool hasPositives = false; bool hasNegatives = false; for (int i = 0; i < ComparisonOperator.Length; i++) { if (ComparisonOperator[i] == FilterComparisonOperator.Not_Equal) { hasNegatives = true; } else { hasPositives = true; } } for (int i = 0; i < PredicateValue.Length; i++) { if (hasNegatives && hasPositives && ComparisonOperator[i] == FilterComparisonOperator.Not_Equal) { // In this case I only care for the positives continue; } if (i > 0) { if (hasNegatives && !hasPositives) { result += " AND "; } else { result += " OR "; } } result += ColumnName.ToString(); result += " " + FilterPredicate.ComparisonOperatorAsString(ComparisonOperator[i]) + " '" + EscapeFilter(PredicateValue[i]) + "'"; } result += ")"; return(result); }
private List <TItem> ApplyFilter <TItem>(IFilterOperation filterOperation, string operand, IEnumerable <TItem> items) { var dataSchema = new DataSchema(new DataSchemaLocalizer(CultureInfo.CurrentCulture)); var columnDescriptor = ColumnDescriptor.RootColumn(dataSchema, typeof(TItem)); if (null != operand) { Assert.IsNotNull(filterOperation.GetOperandType(columnDescriptor)); } var filterPredicate = FilterPredicate.CreateFilterPredicate(dataSchema, typeof(TItem), filterOperation, operand); var predicate = filterPredicate.MakePredicate(dataSchema, typeof(TItem)); return(items.Where(item => predicate(item)).ToList()); }
public FilterPredicate(FilterOperator op, FilterPredicate clause) { if (op != FilterOperator.OR && op != FilterOperator.AND) { throw new IllegalArgumentException("Operator must be AND or OR"); } if (clause == null) { throw new IllegalArgumentException("clause is null"); } _propertyName = null; _operator = op; _clauses = new ArrayList <FilterPredicate>(1); _clauses.add(clause); _values = null; }
public AgilityContentFilterBuilder AddFilter( string property, string value, FilterPredicate predicate = FilterPredicate.Equal, FilterExpression expression = FilterExpression.And) { string pred; switch (predicate) { case FilterPredicate.Like: pred = "like"; break; case FilterPredicate.LessThan: pred = "lt"; break; case FilterPredicate.LessThanOrEqual: pred = "lte"; break; case FilterPredicate.GreaterThan: pred = "gt"; break; case FilterPredicate.GreaterThanOrEqual: pred = "gte"; break; case FilterPredicate.NotEqual: pred = "ne"; break; case FilterPredicate.Equal: default: pred = "eq"; break; } string expr = expression == FilterExpression.And ? "AND" : "OR"; _filters.Add($"{expr} {property}[{pred}]{value}"); return(this); }
public ContrailQuery addFilter <T>(String propertyName, FilterOperator op, T value) where T : IComparable { FilterPredicate clause = new FilterPredicate(propertyName, op, new QuantifiedValues(value)); if (_filterPredicate == null) { _filterPredicate = clause; } else if (_filterPredicate._operator == FilterOperator.AND) { _filterPredicate._clauses.add(clause); } else { _filterPredicate = and(_filterPredicate, clause); } return(this); }
public void InitializeFilterPredicate() { FilterPredicate = PredicateBuilder.True <Playerstatistic>(); if (FilterModelCollection == null) { return; } foreach (var filter in FilterModelCollection) { var filterPredicate = filter.GetFilterPredicate(); if (filterPredicate != null) { FilterPredicate = FilterPredicate.And(filterPredicate); } } }
private static FilterPredicate TranslateFilterPredicate(Expression expression) { var binaryExpression = expression as BinaryExpression; if (binaryExpression != null) { var filterPredicate = new FilterPredicate(); var groups = TranslateFilterGroup(binaryExpression); groups.Each(g => filterPredicate.Groups.Add(g)); return(filterPredicate); } throw new NotSupportedException( string.Format( "Cannot translate FilterPredicate \"{0}\" because {1} node is not supported.", expression, expression.NodeType)); }
public LogBuilder WithFilter(FilterPredicate filter) { switch (Context) { case Contexts.Log: LogFilter.Filters.Add(new DelegatedFilter(filter)); break; case Contexts.Listener: LastListener.FilterManager.Filters.Add(new DelegatedFilter(filter)); break; case Contexts.Sink: LastSink.FilterManager.Filters.Add(new DelegatedFilter(filter)); break; } return(this); }
public void MultiOrTest(FilterPredicate pred, string predStr) { var titleProp = "title"; var titleVal = "test title"; var nameProp = "name"; var nameVal = "Agility"; var builder = new AgilityContentFilterBuilder() .AddFilter(titleProp, titleVal, pred, FilterExpression.Or) .AddFilter(nameProp, nameVal, pred, FilterExpression.Or); var filterStr = builder.Build(); var expected = WebUtility.UrlEncode($"{titleProp}[{predStr}]{titleVal} OR {nameProp}[{predStr}]{nameVal}"); Assert.Equal(expected, filterStr); }
private static string TranslateFilterGroup(FilterPredicate filterPredicate) { if (!filterPredicate.Groups.Any()) { return(null); } using (var writer = new StringWriter()) using (var xmlWriter = XmlWriter.Create(writer, new XmlWriterSettings { Encoding = new UTF8Encoding(false), Indent = false, OmitXmlDeclaration = true })) { var serializer = new XmlSerializer(typeof(FilterPredicate)); var absorbXsdAndXsiXmlns = new XmlSerializerNamespaces(new[] { new XmlQualifiedName(string.Empty, string.Empty) }); serializer.Serialize(xmlWriter, filterPredicate, absorbXsdAndXsiXmlns); return(writer.ToString()); } }
private void DataGridViewFilterOnCellEndEdit(object sender, DataGridViewCellEventArgs e) { if (InChangeView) { return; } if (e.ColumnIndex == colFilterOperation.Index || e.ColumnIndex == colFilterOperand.Index) { var newFilters = ViewSpec.Filters.ToArray(); var filterInfo = ViewInfo.Filters[e.RowIndex]; var filterPredicate = FilterPredicate.CreateFilterPredicate( filterInfo.ColumnDescriptor.DataSchema, filterInfo.ColumnDescriptor.PropertyType, FilterOperationFromDisplayName( dataGridViewFilter.Rows[e.RowIndex].Cells[colFilterOperation.Index].Value as string), dataGridViewFilter.Rows[e.RowIndex].Cells[colFilterOperand.Index].Value as string); newFilters[e.RowIndex] = new FilterSpec(filterInfo.ColumnDescriptor.PropertyPath, filterPredicate); ViewSpec = ViewSpec.SetFilters(newFilters); } }
public void ComplexFilter__WithAllowedProperty__ShouldBeOk() { var provider = new SieveProvider() .AddModel <SimpleTestModel>(builder => { builder.CanFilter(model => model.Boolean); builder.CanFilter(model => model.Number); }); var query = new[] { new SimpleTestModel { Boolean = false, Number = 1 }, new SimpleTestModel { Boolean = true, Number = 2 }, new SimpleTestModel { Boolean = true, Number = 3 } }.AsQueryable(); var filterPredicate = new FilterPredicate <SimpleTestModel>(new ComplexFilterPipeline <SimpleTestModel>( ComplexFilterOperation.Or, new IFilterPipeline <SimpleTestModel>[] { new ComplexFilterPipeline <SimpleTestModel>(ComplexFilterOperation.And, new IFilterPipeline <SimpleTestModel>[] { new SimpleFilterPipeline <SimpleTestModel, bool>(model => model.Boolean, SimpleFilterOperation.Equal, true), new SimpleFilterPipeline <SimpleTestModel, int>(model => model.Number, SimpleFilterOperation.Equal, 3), }), new SimpleFilterPipeline <SimpleTestModel, bool>(model => model.Boolean, SimpleFilterOperation.Equal, false) })); var result = provider.Apply(query, new[] { filterPredicate }).ToList(); Assert.Equal(2, result.Count); Assert.Single(result, model => model.Boolean == true && model.Number == 3); Assert.Single(result, model => model.Boolean == false && model.Number == 1); }
public static IList<IASTNode> CollectChildren(IASTNode root, FilterPredicate predicate) { return new CollectingNodeVisitor(predicate).Collect(root); }
public CollectingNodeVisitor(FilterPredicate predicate) { this.predicate = predicate; }