Exemplo n.º 1
0
        public void SearchFor(string searchTerm)
        {
            LALRParser lalrParser = GrammarReader.CreateNewParser();
            _wiqlBuilder = new WiqlBuilder();
            _fieldName = "";
            _comparisonType = FieldComparison.Contains;

            lalrParser.OnTokenRead += new LALRParser.TokenReadHandler(lalrParser_OnTokenRead);
            lalrParser.OnParseError += new LALRParser.ParseErrorHandler(lalrParser_OnParseError);
            lalrParser.OnTokenError += new LALRParser.TokenErrorHandler(lalrParser_OnTokenError);
            lalrParser.Parse(searchTerm);
        }
Exemplo n.º 2
0
        public void SearchFor(string searchTerm)
        {
            LALRParser lalrParser = GrammarReader.CreateNewParser();

            _wiqlBuilder    = new WiqlBuilder();
            _fieldName      = "";
            _comparisonType = FieldComparison.Contains;

            lalrParser.OnTokenRead  += new LALRParser.TokenReadHandler(lalrParser_OnTokenRead);
            lalrParser.OnParseError += new LALRParser.ParseErrorHandler(lalrParser_OnParseError);
            lalrParser.OnTokenError += new LALRParser.TokenErrorHandler(lalrParser_OnTokenError);
            lalrParser.Parse(searchTerm);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="field">If this is blank, then the title field is used as the default.</param>
        /// <param name="value"></param>
        /// <returns></returns>
        public void AppendField(string fieldName,string value,FieldComparison fieldType)
        {
            if (string.IsNullOrEmpty(fieldName))
                fieldName = "Title";

            Field field = null;
            string key = fieldName + _nextFieldIsNot;

            if (_queryStack.Count > 0)
            {
                field = _queryStack.Peek() as Field;
                if (field != null)
                {
                    if (!_fieldLookup.ContainsKey(key) && field.ToString() != "")
                    {
                        _queryStack.Push("AND");
                    }
                }
            }

            if (_fieldLookup.ContainsKey(key))
            {
                // Combine repeated field definitions into a single = (instead of repeating them with ANDs)
                _fieldLookup[key].Value += " " + value;
            }
            else
            {
                switch (fieldType)
                {
                    case FieldComparison.User:
                        field = new UserField();
                        break;

                    case FieldComparison.Date:
                        field = new DateField();
                        break;

                    case FieldComparison.Project:
                        field = new ProjectField();
                        break;

                    case FieldComparison.Contains:
                        field = new ContainsField();
                        break;

                    case FieldComparison.ExactMatch:
                    default:
                        field = new Field();
                        break;
                }

                field.ColumnName = ToColumnName(fieldName);
                field.ParameterName = fieldName;
                field.Value = value;
                field.IsNot = _nextFieldIsNot;

                _queryStack.Push(field);
                _fieldLookup.Add(key, field);
            }

            // reset for future fields
            _nextFieldIsNot = false;
        }
Exemplo n.º 4
0
        private void lalrParser_OnTokenRead(LALRParser parser, TokenReadEventArgs e)
        {
            // Pass these names to the WIQLBuilder. It can translate them using its own lookup table
            // in to the appropriate field name.

            // Huge switch statement for each token type. Originally this was going to be transformed
            // into a type per symbol, however leaving the WiqlBuilder to deal with it seems a lot simpler.
            switch (e.Token.Symbol.Name)
            {
            //
            // Matched field identifiers
            //
            case "Project":
                _comparisonType = FieldComparison.Project;
                _fieldName      = e.Token.Symbol.Name;
                break;

            case "CreatedBy":
            case "AssignedTo":
            case "ResolvedBy":
                _comparisonType = FieldComparison.User;
                _fieldName      = e.Token.Symbol.Name;
                break;

            case "CreatedOn":
            case "ResolvedOn":
                _comparisonType = FieldComparison.Date;
                _fieldName      = e.Token.Symbol.Name;
                break;

            case "Description":
                _comparisonType = FieldComparison.Contains;
                _fieldName      = e.Token.Symbol.Name;
                break;

            case "State":
            case "Type":
            case "Area":
            case "Iteration":
                _comparisonType = FieldComparison.ExactMatch;
                _fieldName      = e.Token.Symbol.Name;
                break;

            //
            // OR/NOT
            //
            case "Or":
                _fieldName = "";
                _wiqlBuilder.Or();
                break;

            case "Negate":
                _wiqlBuilder.Not();
                break;

            //
            // Strings
            //
            case "StringLiteral":

                // Make sure contains is kept for literals - mainly so the description field works.
                if (_comparisonType == FieldComparison.Contains)
                {
                    _wiqlBuilder.AppendField(_fieldName, e.Token.Text.Replace("\"", ""), FieldComparison.Contains);
                }
                else
                {
                    _wiqlBuilder.AppendField(_fieldName, e.Token.Text.Replace("\"", ""), FieldComparison.ExactMatch);
                }

                _fieldName      = "";
                _comparisonType = FieldComparison.Contains;
                break;

            case "AnyChar":
                _wiqlBuilder.AppendField(_fieldName, e.Token.Text, _comparisonType);
                _fieldName      = "";
                _comparisonType = FieldComparison.Contains;
                break;

            // End of parsing
            case "(EOF)":
                OnParseComplete(EventArgs.Empty);
                break;

            default:
                // Exception?
                throw new NotImplementedException(string.Format("{0} is not supported", e.Token.Symbol.Name));
            }
        }
Exemplo n.º 5
0
 public QueryElement(string field, FieldComparison comparison, object value)
 {
     _element = Tuple.Create(field, comparison, value);
 }
Exemplo n.º 6
0
 public static QueryElement FieldCompare(string field, FieldComparison comparison, object value)
 {
     return(new QueryElement(field, comparison, value));
 }
Exemplo n.º 7
0
        private void lalrParser_OnTokenRead(LALRParser parser, TokenReadEventArgs e)
        {
            // Pass these names to the WIQLBuilder. It can translate them using its own lookup table
            // in to the appropriate field name.

            // Huge switch statement for each token type. Originally this was going to be transformed
            // into a type per symbol, however leaving the WiqlBuilder to deal with it seems a lot simpler.
            switch (e.Token.Symbol.Name)
            {
                //
                // Matched field identifiers
                //
                case "Project":
                    _comparisonType = FieldComparison.Project;
                    _fieldName = e.Token.Symbol.Name;
                    break;

                case "CreatedBy":
                case "AssignedTo":
                case "ResolvedBy":
                    _comparisonType = FieldComparison.User;
                    _fieldName = e.Token.Symbol.Name;
                    break;

                case "CreatedOn":
                case "ResolvedOn":
                    _comparisonType = FieldComparison.Date;
                    _fieldName = e.Token.Symbol.Name;
                    break;

                case "Description":
                    _comparisonType = FieldComparison.Contains;
                    _fieldName = e.Token.Symbol.Name;
                    break;

                case "State":
                case "Type":
                case "Area":
                case "Iteration":
                    _comparisonType = FieldComparison.ExactMatch;
                    _fieldName = e.Token.Symbol.Name;
                    break;

                //
                // OR/NOT
                //
                case "Or":
                    _fieldName = "";
                    _wiqlBuilder.Or();
                    break;

                case "Negate":
                    _wiqlBuilder.Not();
                    break;

                //
                // Strings
                //
                case "StringLiteral":

                    // Make sure contains is kept for literals - mainly so the description field works.
                    if (_comparisonType == FieldComparison.Contains)
                        _wiqlBuilder.AppendField(_fieldName, e.Token.Text.Replace("\"",""), FieldComparison.Contains);
                    else
                        _wiqlBuilder.AppendField(_fieldName, e.Token.Text.Replace("\"", ""), FieldComparison.ExactMatch);

                    _fieldName = "";
                    _comparisonType = FieldComparison.Contains;
                    break;

                case "AnyChar":
                    _wiqlBuilder.AppendField(_fieldName, e.Token.Text,_comparisonType);
                    _fieldName = "";
                    _comparisonType = FieldComparison.Contains;
                    break;

                // End of parsing
                case "(EOF)":
                    OnParseComplete(EventArgs.Empty);
                    break;

                default:
                    // Exception?
                    throw new NotImplementedException(string.Format("{0} is not supported",e.Token.Symbol.Name));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="field">If this is blank, then the title field is used as the default.</param>
        /// <param name="value"></param>
        /// <returns></returns>
        public void AppendField(string fieldName, string value, FieldComparison fieldType)
        {
            if (string.IsNullOrEmpty(fieldName))
            {
                fieldName = "Title";
            }

            Field  field = null;
            string key   = fieldName + _nextFieldIsNot;

            if (_queryStack.Count > 0)
            {
                field = _queryStack.Peek() as Field;
                if (field != null)
                {
                    if (!_fieldLookup.ContainsKey(key) && field.ToString() != "")
                    {
                        _queryStack.Push("AND");
                    }
                }
            }

            if (_fieldLookup.ContainsKey(key))
            {
                // Combine repeated field definitions into a single = (instead of repeating them with ANDs)
                _fieldLookup[key].Value += " " + value;
            }
            else
            {
                switch (fieldType)
                {
                case FieldComparison.User:
                    field = new UserField();
                    break;

                case FieldComparison.Date:
                    field = new DateField();
                    break;

                case FieldComparison.Project:
                    field = new ProjectField();
                    break;

                case FieldComparison.Contains:
                    field = new ContainsField();
                    break;

                case FieldComparison.ExactMatch:
                default:
                    field = new Field();
                    break;
                }

                field.ColumnName    = ToColumnName(fieldName);
                field.ParameterName = fieldName;
                field.Value         = value;
                field.IsNot         = _nextFieldIsNot;

                _queryStack.Push(field);
                _fieldLookup.Add(key, field);
            }

            // reset for future fields
            _nextFieldIsNot = false;
        }