Example #1
0
        public static QueryFilter ParseAndBuildQuery(string query, AqsParser.ParseOption parseOption, CultureInfo culture, RescopedAll rescopedAll, IRecipientResolver recipientResolver, IPolicyTagProvider policyTagProvider)
        {
            AqsParser   aqsParser   = new AqsParser();
            QueryFilter queryFilter = null;

            using (Condition condition = aqsParser.Parse(query, parseOption, culture))
            {
                QueryFilterBuilder queryFilterBuilder = new QueryFilterBuilder(culture, parseOption);
                queryFilterBuilder.RescopedAll       = rescopedAll;
                queryFilterBuilder.RecipientResolver = recipientResolver;
                queryFilterBuilder.PolicyTagProvider = policyTagProvider;
                queryFilterBuilder.AllowedKeywords   = aqsParser.AllowedKeywords;
                if (condition != null)
                {
                    queryFilter = queryFilterBuilder.Build(condition);
                }
                if (queryFilter == null)
                {
                    if (!aqsParser.SuppressError)
                    {
                        throw new ParserException(new ParserErrorInfo(ParserErrorCode.ParserError));
                    }
                    queryFilter = queryFilterBuilder.BuildAllFilter(1, query);
                }
            }
            return(queryFilter);
        }
Example #2
0
        public static ICollection <QueryFilter> FlattenQueryFilter(QueryFilter filter)
        {
            List <QueryFilter> list       = new List <QueryFilter>();
            TextFilter         textFilter = filter as TextFilter;

            if (textFilter != null)
            {
                list.Add(textFilter);
            }
            AndFilter andFilter = filter as AndFilter;

            if (andFilter != null)
            {
                list.Add(andFilter);
            }
            NotFilter notFilter = filter as NotFilter;

            if (notFilter != null)
            {
                list.Add(notFilter);
            }
            NearFilter nearFilter = filter as NearFilter;

            if (nearFilter != null)
            {
                list.Add(nearFilter);
            }
            OrFilter orFilter = filter as OrFilter;

            if (orFilter != null)
            {
                foreach (QueryFilter filter2 in orFilter.Filters)
                {
                    list.AddRange(AqsParser.FlattenQueryFilter(filter2));
                }
            }
            return(list);
        }
Example #3
0
        static AqsParser()
        {
            bool flag = AqsParser.IsOsVersionOrLater(6, 1);

            if (flag)
            {
                AqsParser.CanonicalKeywords = new Dictionary <PropertyKeyword, string>
                {
                    {
                        PropertyKeyword.From,
                        "System.StructuredQuery.Virtual.From"
                    },
                    {
                        PropertyKeyword.To,
                        "System.StructuredQuery.Virtual.To"
                    },
                    {
                        PropertyKeyword.Cc,
                        "System.StructuredQuery.Virtual.Cc"
                    },
                    {
                        PropertyKeyword.Bcc,
                        "System.StructuredQuery.Virtual.Bcc"
                    },
                    {
                        PropertyKeyword.Participants,
                        "System.ItemParticipants"
                    },
                    {
                        PropertyKeyword.Subject,
                        "System.Subject"
                    },
                    {
                        PropertyKeyword.Body,
                        "System.Search.Contents"
                    },
                    {
                        PropertyKeyword.Sent,
                        "System.Message.DateSent"
                    },
                    {
                        PropertyKeyword.Received,
                        "System.Message.DateReceived"
                    },
                    {
                        PropertyKeyword.Attachment,
                        "System.Message.AttachmentContents"
                    },
                    {
                        PropertyKeyword.PolicyTag,
                        "System.Communication.PolicyTag"
                    },
                    {
                        PropertyKeyword.Expires,
                        "System.Communication.DateItemExpires"
                    },
                    {
                        PropertyKeyword.HasAttachment,
                        "System.Message.HasAttachments"
                    },
                    {
                        PropertyKeyword.Category,
                        "System.Category"
                    },
                    {
                        PropertyKeyword.IsFlagged,
                        "System.IsFlagged"
                    },
                    {
                        PropertyKeyword.IsRead,
                        "System.StructuredQuery.Virtual.IsRead"
                    },
                    {
                        PropertyKeyword.Importance,
                        "System.Importance"
                    },
                    {
                        PropertyKeyword.Size,
                        "System.Size"
                    },
                    {
                        PropertyKeyword.Kind,
                        "System.Kind"
                    }
                };
                AqsParser.CanonicalKindKeys = AqsParser.KindKeywordMap.ToDictionary((KeyValuePair <string, KindKeyword> x) => x.Value, (KeyValuePair <string, KindKeyword> x) => string.Format("System.Kind#{0}", x.Key));
            }
            else
            {
                AqsParser.CanonicalKeywords = (from x in Enum.GetValues(typeof(PropertyKeyword)).OfType <PropertyKeyword>()
                                               where x != PropertyKeyword.All
                                               select x).ToDictionary((PropertyKeyword x) => x, (PropertyKeyword x) => Enum.GetName(typeof(PropertyKeyword), x));
                AqsParser.CanonicalKindKeys = Enum.GetValues(typeof(KindKeyword)).OfType <KindKeyword>().ToDictionary((KindKeyword x) => x, (KindKeyword x) => Enum.GetName(typeof(KindKeyword), x));
            }
            using (ParserManager parserManager = new ParserManager())
            {
                using (Parser parser = parserManager.CreateLoadedParser(CultureInfo.CurrentCulture))
                {
                    parserManager.InitializeOptions(false, true, parser);
                    parser.Parse("foo").Dispose();
                }
            }
        }
Example #4
0
 public static QueryFilter ParseAndBuildQuery(string query, AqsParser.ParseOption parseOption, CultureInfo culture, IRecipientResolver recipientResolver, IPolicyTagProvider policyTagProvider)
 {
     return(AqsParser.ParseAndBuildQuery(query, parseOption, culture, RescopedAll.Default, recipientResolver, policyTagProvider));
 }
Example #5
0
        private void ValidatePredicate(Solution solution, LeafCondition leaf, List <ParserErrorInfo> errors, bool postResolving)
        {
            this.ValidatePredicateOperator(solution, leaf, errors);
            TokenInfo       errorToken = (leaf.PropertyTermInfo == null) ? null : new TokenInfo(solution.Tokens[leaf.PropertyTermInfo.FirstToken]);
            PropertyKeyword propertyKeyword;

            if (postResolving)
            {
                if (!AqsParser.PropertyKeywordMap.TryGetValue(leaf.PropertyName, out propertyKeyword))
                {
                    propertyKeyword = PropertyKeyword.All;
                }
            }
            else if (leaf.PropertyTermInfo != null)
            {
                if (!AqsParser.PropertyKeywordMap.TryGetValue(leaf.PropertyName, out propertyKeyword))
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidPropertyKey, errorToken));
                    return;
                }
                if (!this.AllowedKeywords.Contains(propertyKeyword))
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidPropertyKey, errorToken));
                    return;
                }
            }
            else
            {
                propertyKeyword = PropertyKeyword.All;
                if (leaf.ValueTermInfo == null)
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.UnexpectedToken));
                    return;
                }
            }
            if (!postResolving && leaf.ValueTermInfo == null)
            {
                ParserErrorCode parserErrorCode  = ParserErrorCode.MissingPropertyValue;
                PropertyKeyword propertyKeyword2 = propertyKeyword;
                switch (propertyKeyword2)
                {
                case PropertyKeyword.Sent:
                case PropertyKeyword.Received:
                    parserErrorCode = ParserErrorCode.InvalidDateTimeFormat;
                    break;

                default:
                    if (propertyKeyword2 == PropertyKeyword.Kind)
                    {
                        parserErrorCode = ParserErrorCode.InvalidKindFormat;
                    }
                    break;
                }
                if (parserErrorCode != ParserErrorCode.MissingPropertyValue)
                {
                    int num = leaf.PropertyTermInfo.FirstToken + leaf.PropertyTermInfo.Length + 1;
                    if (leaf.OperationTermInfo != null)
                    {
                        num += leaf.PropertyTermInfo.Length;
                    }
                    if (num < solution.Tokens.Count)
                    {
                        errorToken = new TokenInfo(solution.Tokens[num]);
                    }
                }
                errors.Add(new ParserErrorInfo(parserErrorCode, errorToken));
                return;
            }
            if (leaf.ValueTermInfo != null)
            {
                int firstChar = solution.Tokens[leaf.ValueTermInfo.FirstToken].FirstChar;
                errorToken = new TokenInfo(firstChar, leaf.ValueTermInfo.Text.Length);
            }
            if (propertyKeyword == PropertyKeyword.Kind)
            {
                if (!AqsParser.KindKeywordMap.ContainsKey((string)leaf.Value))
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidKindFormat, errorToken));
                    return;
                }
            }
            else
            {
                if (propertyKeyword == PropertyKeyword.Sent || propertyKeyword == PropertyKeyword.Received)
                {
                    if (postResolving || !(leaf.Value is string[]) || ((string[])leaf.Value).Length != 2)
                    {
                        return;
                    }
                    using (Condition condition = solution.Resolve(leaf, 0, (DateTime)ExDateTime.Now))
                    {
                        LeafCondition leafCondition  = (LeafCondition)((CompoundCondition)condition).Children[0];
                        LeafCondition leafCondition2 = (LeafCondition)((CompoundCondition)condition).Children[1];
                        ExDateTime    t  = (ExDateTime)((DateTime)leafCondition.Value);
                        ExDateTime    t2 = (ExDateTime)((DateTime)leafCondition2.Value);
                        if (t > t2)
                        {
                            errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidDateTimeRange, errorToken));
                        }
                        return;
                    }
                }
                if (postResolving && leaf.Value is string)
                {
                    string text = (string)leaf.Value;
                    if (!AqsParser.ContainsAlphanumericChars(text))
                    {
                        errors.Add(new ParserErrorInfo(ParserErrorCode.UnexpectedToken, errorToken));
                    }
                    int num2 = text.IndexOf('*');
                    if (num2 >= 0)
                    {
                        string s = text.Substring(0, num2);
                        if (!AqsParser.ContainsAlphanumericChars(s))
                        {
                            errors.Add(new ParserErrorInfo(ParserErrorCode.SuffixMatchNotSupported, errorToken));
                        }
                    }
                }
            }
        }