Exemple #1
0
 void Parse(string conditions)
 {
     this.Context = new FilterParserContext(conditions);
     GetConditions(conditions, this.Context);
 }
Exemple #2
0
        static void GetConditions(string filter, FilterParserContext context)
        {
            List<Guid> activities = new List<Guid>();
            List<uint> processes = new List<uint>();
            List<int> threads = new List<int>();
            List<int> ids = new List<int>();
            List<int> levels = new List<int>();
            List<string> texts = new List<string>();
            string normalizedFilterString = string.Empty;

            Token current = null;
            try
            {
                foreach (Token token in GetNextToken(filter))
                {
                    current = token;
                    switch (token.Type)
                    {
                        case TokenType.Id:
                            ids.Add((int)token.Value);
                            break;
                        case TokenType.Pid:
                            processes.Add((uint)token.Value);
                            break;
                        case TokenType.Tid:
                            threads.Add((int)token.Value);
                            break;
                        case TokenType.ActivityId:
                            activities.Add((Guid)token.Value);
                            break;
                        case TokenType.RootActivity:
                            context.RootActivityFilter = (Guid)token.Value;
                            break;
                        case TokenType.Level:
                            levels.Add((int)token.Value);
                            break;
                        case TokenType.MinLevel:
                            if (context.MinLevel != null)
                            {
                                throw new InvalidOperationException("Cannot have more than one MinValue clause");
                            }
                            context.MinLevel = (int)token.Value;
                            break;
                        case TokenType.Text:
                            texts.Add((string)token.Value);
                            break;
                        case TokenType.Where:
                            if (context.WhereFilter != null)
                            {
                                throw new FilterParserException("Cannot have more than one where clause",
                                                                current.Type.ToString(),
                                                                current.Index,
                                                                null);
                            }
                            context.WhereFilter = (string)token.Value;
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is FilterParserException)
                {
                    throw;
                }

                if (current != null)
                {
                    throw new FilterParserException(current.Type.ToString(), current.Index, ex);
                }
                else
                {
                    throw;
                }
            }

            if (processes.Count > 0)
                context.ProcessFilters = processes.ToArray();
            if (threads.Count > 0)
                context.ThreadsFilter = threads.ToArray();
            if (ids.Count > 0)
                context.IdFilters = ids.ToArray();
            if (levels.Count > 0)
                context.LevelFilters = levels.ToArray();
            if (activities.Count > 0)
                context.ActivityIdFilters = activities.ToArray();
            if (texts.Count > 0)
                context.TextFilters = texts.ToArray();
        }
Exemple #3
0
        static void GetConditions(string filter, FilterParserContext context)
        {
            List <Guid>   activities             = new List <Guid>();
            List <uint>   processes              = new List <uint>();
            List <int>    threads                = new List <int>();
            List <int>    ids                    = new List <int>();
            List <int>    levels                 = new List <int>();
            List <string> texts                  = new List <string>();
            string        normalizedFilterString = string.Empty;

            Token current = null;

            try
            {
                foreach (Token token in GetNextToken(filter))
                {
                    current = token;
                    switch (token.Type)
                    {
                    case TokenType.Id:
                        ids.Add((int)token.Value);
                        break;

                    case TokenType.Pid:
                        processes.Add((uint)token.Value);
                        break;

                    case TokenType.Tid:
                        threads.Add((int)token.Value);
                        break;

                    case TokenType.ActivityId:
                        activities.Add((Guid)token.Value);
                        break;

                    case TokenType.RootActivity:
                        context.RootActivityFilter = (Guid)token.Value;
                        break;

                    case TokenType.Level:
                        levels.Add((int)token.Value);
                        break;

                    case TokenType.MinLevel:
                        if (context.MinLevel != null)
                        {
                            throw new InvalidOperationException("Cannot have more than one MinValue clause");
                        }
                        context.MinLevel = (int)token.Value;
                        break;

                    case TokenType.Text:
                        texts.Add((string)token.Value);
                        break;

                    case TokenType.Where:
                        if (context.WhereFilter != null)
                        {
                            throw new FilterParserException("Cannot have more than one where clause",
                                                            current.Type.ToString(),
                                                            current.Index,
                                                            null);
                        }
                        context.WhereFilter = (string)token.Value;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is FilterParserException)
                {
                    throw;
                }

                if (current != null)
                {
                    throw new FilterParserException(current.Type.ToString(), current.Index, ex);
                }
                else
                {
                    throw;
                }
            }

            if (processes.Count > 0)
            {
                context.ProcessFilters = processes.ToArray();
            }
            if (threads.Count > 0)
            {
                context.ThreadsFilter = threads.ToArray();
            }
            if (ids.Count > 0)
            {
                context.IdFilters = ids.ToArray();
            }
            if (levels.Count > 0)
            {
                context.LevelFilters = levels.ToArray();
            }
            if (activities.Count > 0)
            {
                context.ActivityIdFilters = activities.ToArray();
            }
            if (texts.Count > 0)
            {
                context.TextFilters = texts.ToArray();
            }
        }