private static QueryFilter BuildBooleanFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { int num; if (int.TryParse(value, out num) && (num == 0 || num == 1)) { return(QueryFilterBuilder.BuildComparisonFilter(properties, ComparisonOperator.Equal, num)); } return(null); }
public override void Visit <T>(NumericNode <T> node) { PropertyKeyword key; if (this.TryGetCurrentPropertyKeyword(out key)) { this.CurrentLevelFilters.Add(QueryFilterBuilder.BuildComparisonFilter(Globals.PropertyKeywordToDefinitionMap[key], ComparisonOperator.Equal, node.Value)); return; } this.isQueryFilterValid = false; }
private static QueryFilter BuildAllFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { List <PropertyKeyword> list = new List <PropertyKeyword>(); switch (builder.rescopedAll) { case RescopedAll.Default: return(QueryFilterBuilder.BuildStringFilter(builder, properties, value, options)); case RescopedAll.Subject: list.Add(PropertyKeyword.Subject); break; case RescopedAll.Body: list.Add(PropertyKeyword.Body); break; case RescopedAll.BodyAndSubject: list.Add(PropertyKeyword.Subject); list.Add(PropertyKeyword.Body); break; case RescopedAll.From: list.Add(PropertyKeyword.From); break; case RescopedAll.Participants: list.Add(PropertyKeyword.Participants); break; default: throw new ArgumentException("RescopedAll"); } List <QueryFilter> list2 = new List <QueryFilter>(); foreach (PropertyKeyword key in list) { QueryFilter queryFilter = QueryFilterBuilder.stringNodeBuilderMap[key](builder, Globals.PropertyKeywordToDefinitionMap[key], value, options); if (queryFilter == null) { builder.isQueryFilterValid = false; return(null); } list2.Add(queryFilter); } if (list2.Count == 1) { return(list2[0]); } return(new OrFilter(list2.ToArray())); }
private static QueryFilter BuildImportanceFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { Importance importance; if (!builder.keywordMapping.TryGetImportance(value, out importance)) { return(null); } if ((builder.parseOptions & KqlParser.ParseOption.QueryPreserving) != KqlParser.ParseOption.None) { return(QueryFilterBuilder.BuildStringFilter(builder, properties, value, MatchOptions.FullString)); } return(QueryFilterBuilder.BuildComparisonFilter(properties, ComparisonOperator.Equal, (int)importance)); }
private static QueryFilter BuildAttachmentFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { QueryFilter queryFilter = QueryFilterBuilder.BuildStringFilter(builder, properties, value, options); if ((builder.parseOptions & KqlParser.ParseOption.ContentIndexingDisabled) != KqlParser.ParseOption.None) { return(new OrFilter(new QueryFilter[] { queryFilter, new SubFilter(SubFilterProperties.Attachments, QueryFilterBuilder.BuildStringFilter(builder, Globals.AttachmentSubMapping, value, options)) })); } return(queryFilter); }
private static QueryFilter BuildStringFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { List <QueryFilter> list = new List <QueryFilter>(); foreach (PropertyDefinition property in properties) { list.Add(new TextFilter(property, value, options, MatchFlags.Loose)); } if (list.Count != 1) { return(new OrFilter(list.ToArray())); } return(list[0]); }
private static QueryFilter BuildIsFlaggedFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { int num; if (!int.TryParse(value, out num) || (num != 0 && num != 1)) { return(null); } if (num == 1) { return(QueryFilterBuilder.BuildComparisonFilter(properties, ComparisonOperator.Equal, FlagStatus.Flagged)); } return(new OrFilter(new QueryFilter[] { QueryFilterBuilder.BuildComparisonFilter(properties, ComparisonOperator.Equal, FlagStatus.NotFlagged), new NotFilter(builder.BuildExistsFilter(properties)) })); }
private static QueryFilter BuildPolicyTagFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { List <QueryFilter> list = new List <QueryFilter>(); Guid guid; if (Guid.TryParse(value, out guid)) { list.Add(QueryFilterBuilder.BuildComparisonFilter(properties, ComparisonOperator.Equal, guid.ToByteArray())); } if (builder.policyTagProvider != null) { IEnumerable <PolicyTag> enumerable = null; PolicyTag[] policyTags = builder.policyTagProvider.PolicyTags; if (policyTags != null) { if (options == MatchOptions.PrefixOnWords || options == MatchOptions.SubString) { enumerable = from x in policyTags where x.Name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0 select x; } else { enumerable = from x in policyTags where x.Name.Equals(value, StringComparison.OrdinalIgnoreCase) select x; } } foreach (PolicyTag policyTag in enumerable) { list.Add(QueryFilterBuilder.BuildComparisonFilter(properties, ComparisonOperator.Equal, policyTag.PolicyGuid.ToByteArray())); } } if (list.Count == 0) { return(null); } if (list.Count == 1) { return(list[0]); } return(new OrFilter(list.ToArray())); }
public static QueryFilter ParseAndBuildQuery(string query, KqlParser.ParseOption parseOption, CultureInfo cultureInfo, RescopedAll rescopedAll, IRecipientResolver recipientResolver, IPolicyTagProvider policyTagProvider) { KqlParser kqlParser = new KqlParser(); LocalizedKeywordMapping mapping = LocalizedKeywordMapping.GetMapping(cultureInfo); TreeNode treeNode = kqlParser.Parse(query, parseOption, cultureInfo, mapping); QueryFilterBuilder queryFilterBuilder = new QueryFilterBuilder(mapping, parseOption, rescopedAll, recipientResolver, policyTagProvider, cultureInfo); queryFilterBuilder.AllowedKeywords = KqlParser.GetSupportedProperties(parseOption); QueryFilter queryFilter = queryFilterBuilder.Build(treeNode); if (queryFilter == null) { if ((parseOption & KqlParser.ParseOption.SuppressError) == KqlParser.ParseOption.None) { throw new ParserException(new ParserErrorInfo(ParserErrorCode.ParserError)); } queryFilter = queryFilterBuilder.BuildAllFilter(query); } return(queryFilter); }
private static QueryFilter BuildRecipientFilter(QueryFilterBuilder builder, IEnumerable <PropertyDefinition> properties, string value, MatchOptions options) { List <QueryFilter> list = new List <QueryFilter>(); IEnumerable <PropertyDefinition> modifiedRecipientPropertiesForEDiscovery = QueryFilterBuilder.GetModifiedRecipientPropertiesForEDiscovery(builder.parseOptions, properties); list.Add(QueryFilterBuilder.BuildStringFilter(builder, modifiedRecipientPropertiesForEDiscovery, value, options)); if ((builder.parseOptions & KqlParser.ParseOption.QueryPreserving) == KqlParser.ParseOption.None && builder.recipientResolver != null) { foreach (string text in builder.recipientResolver.Resolve(value)) { if (!text.Equals(value, StringComparison.OrdinalIgnoreCase)) { list.Add(QueryFilterBuilder.BuildStringFilter(builder, modifiedRecipientPropertiesForEDiscovery, text, options)); } } } if (list.Count == 1) { return(list[0]); } return(new OrFilter(list.ToArray())); }
public override void Visit <T>(RangeNode <T> node) { PropertyKeyword key; if (!this.TryGetCurrentPropertyKeyword(out key)) { this.isQueryFilterValid = false; return; } ComparisonOperator comparisonOperator = ComparisonOperator.Equal; bool flag = true; if (node.StartInclusive != null) { comparisonOperator = (node.StartInclusive.Value ? ComparisonOperator.GreaterThanOrEqual : ComparisonOperator.GreaterThan); flag = false; if (comparisonOperator == ComparisonOperator.GreaterThanOrEqual) { if (typeof(T) == typeof(DateTime)) { flag = (node.Start as DateTime? == DateTime.MinValue); } else if (typeof(T) == typeof(int)) { flag = (node.Start as int? == int.MinValue); } else if (typeof(T) == typeof(float)) { float?num = node.Start as float?; flag = (num.GetValueOrDefault() == float.MinValue && num != null); } else { this.isQueryFilterValid = false; } } } ComparisonOperator comparisonOperator2 = ComparisonOperator.Equal; bool flag2 = true; if (node.EndInclusive != null) { comparisonOperator2 = (node.EndInclusive.Value ? ComparisonOperator.LessThanOrEqual : ComparisonOperator.LessThan); flag2 = false; if (comparisonOperator2 == ComparisonOperator.LessThanOrEqual) { if (typeof(T) == typeof(DateTime)) { flag2 = (node.End as DateTime? == DateTime.MaxValue); } else if (typeof(T) == typeof(int)) { flag2 = (node.End as int? == int.MaxValue); } else if (typeof(T) == typeof(float)) { float?num2 = node.End as float?; flag2 = (num2.GetValueOrDefault() == float.MaxValue && num2 != null); } else { this.isQueryFilterValid = false; } } } PropertyDefinition[] properties = Globals.PropertyKeywordToDefinitionMap[key]; if (!flag2 && !flag) { this.CurrentLevelFilters.Add(new AndFilter(new QueryFilter[] { QueryFilterBuilder.BuildComparisonFilter(properties, comparisonOperator, node.Start), QueryFilterBuilder.BuildComparisonFilter(properties, comparisonOperator2, node.End) })); return; } if (!flag) { this.CurrentLevelFilters.Add(QueryFilterBuilder.BuildComparisonFilter(properties, comparisonOperator, node.Start)); return; } if (!flag2) { this.CurrentLevelFilters.Add(QueryFilterBuilder.BuildComparisonFilter(properties, comparisonOperator2, node.End)); return; } this.isQueryFilterValid = false; }