Example #1
0
        internal Condition Parse(string query, AqsParser.ParseOption parseOption, CultureInfo cultureInfo)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            if (cultureInfo == null)
            {
                throw new ArgumentNullException("cultureInfo");
            }
            this.parseOption = parseOption;
            if (this.SupportNqs && !this.SuppressError)
            {
                throw new ArgumentException("parserOption: NQS must be combined with SuppressError");
            }
            if (this.UseCiKeywordOnly && this.UseBasicKeywordOnly)
            {
                throw new ArgumentException("UseBasicKeywordOnly can not be combined with UseCIKeywordOnly");
            }
            if (this.UseCiKeywordOnly)
            {
                this.AllowedKeywords = PropertyKeywordHelper.CiPropertyKeywords;
            }
            else if (this.UseBasicKeywordOnly)
            {
                this.AllowedKeywords = PropertyKeywordHelper.BasicPropertyKeywords;
            }
            Condition result;

            try
            {
                int num = 0;
                int i   = 0;
                while (i < query.Length)
                {
                    char c = query[i];
                    if (c == '(' && ++num > 50)
                    {
                        if (this.SuppressError)
                        {
                            return(null);
                        }
                        throw new ParserException(new ParserErrorInfo(ParserErrorCode.ParserError));
                    }
                    else
                    {
                        i++;
                    }
                }
                using (ParserManager parserManager = new ParserManager())
                {
                    using (Parser parser = parserManager.CreateLoadedParser(cultureInfo))
                    {
                        parserManager.InitializeOptions(this.SupportNqs, !this.DisablePrefixMatch, parser);
                        using (Solution solution = parser.Parse(query))
                        {
                            List <ParserErrorInfo> list = new List <ParserErrorInfo>();
                            if (!this.SuppressError)
                            {
                                this.PreResolvingValidate(solution, list);
                                if (list.Count > 0)
                                {
                                    throw new ParserException(list);
                                }
                            }
                            ResolveOptions resolveOptions = 0;
                            if (!this.SplitWords)
                            {
                                resolveOptions |= 64;
                            }
                            Condition condition = solution.Resolve(solution.Condition, resolveOptions, (DateTime)ExDateTime.Now);
                            if (condition == null && !this.SuppressError)
                            {
                                throw new ParserException(new ParserErrorInfo(ParserErrorCode.ParserError));
                            }
                            if (!this.SuppressError)
                            {
                                this.ValidateConditionTree(solution, condition, list, true);
                                if (list.Count > 0)
                                {
                                    throw new ParserException(list);
                                }
                            }
                            result = condition;
                        }
                    }
                }
            }
            catch (StructuredQueryException innerException)
            {
                if (!this.SuppressError)
                {
                    throw new ParserException(new ParserErrorInfo(ParserErrorCode.StructuredQueryException), innerException);
                }
                result = null;
            }
            return(result);
        }
Example #2
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();
                }
            }
        }