/// <summary>
        ///     Adds the specified operation to this group. If the group's type (and/or) is different than the groupType
        ///     parameter, a new group is spawned and added to this one,
        /// </summary>
        /// <param name="groupType"></param>
        /// <param name="operationToAdd"></param>
        public void InjectCriteriaAndReformatGroupIfNecessary(SearchOperationGroupType groupType,
                                                              SearchOperation operationToAdd)
        {
            if (GroupType == groupType)
            {
                Criteria.Add(operationToAdd); // easy
                return;
            }

            // ok, so the group type is different
            // we create a new group
            var sog = new SearchOperationGroup();

            sog.GroupType = GroupType;

            // copy over the current criteria
            sog.Criteria.AddRange(Criteria);

            // clear the criteria from this group
            Criteria.Clear();

            // set the new type
            GroupType = GroupType;

            // add the old criteria, grouped
            Criteria.Add(sog);

            // and add the new operatoin
            Criteria.Add(operationToAdd);
        }
Пример #2
0
 public SearchBuilder(Search s)
 {
     _search = s;
     _currentSearchOperationGroup = _search;
     //MS-1749
     //_search.GroupType = SearchOperationGroupType.And;
     _parenthesesStack = new Stack <SearchOperationGroup>();
 }
Пример #3
0
        public void OpenParenthesis()
        {
            var sog = new SearchOperationGroup();

            sog.Parent = _currentSearchOperationGroup;
            _currentSearchOperationGroup.Criteria.Add(sog);

            // push the current group on the stack - this is where we are coming back to
            _parenthesesStack.Push(_currentSearchOperationGroup);

            _currentSearchOperationGroup = sog;
        }
Пример #4
0
        public void AddOperation(SearchOperation so, SearchOperationGroupType groupType)
        {
            if (so == null)
            {
                throw new ArgumentNullException("so");
            }

            if (_currentSearchOperationGroup.GroupType == groupType) // no problem
            {
                _currentSearchOperationGroup.Criteria.Add(so);
                return;
            }

            // ok - it's different, so...
            if (_currentSearchOperationGroup.Criteria.Count <= 1) // just change the type!
            {
                _currentSearchOperationGroup.GroupType = groupType;
                _currentSearchOperationGroup.Criteria.Add(so);
                return;
            }

            // we must split off another group
            var sog = new SearchOperationGroup();

            sog.GroupType = groupType;

            if (_currentSearchOperationGroup.Parent != null) // we have to replace the parent
            {
                var index = _currentSearchOperationGroup.Parent.Criteria.IndexOf(_currentSearchOperationGroup);
                _currentSearchOperationGroup.Parent.Criteria.RemoveAt(index);
                _currentSearchOperationGroup.Parent.Criteria.Insert(index, sog);
                sog.Criteria.Add(_currentSearchOperationGroup);
                sog.Criteria.Add(so);
                _currentSearchOperationGroup = sog; // reset the current group
            }
            else
            {
                // we're at the top
                var soBase = new SearchOperationGroup();
                soBase.GroupType = _currentSearchOperationGroup.GroupType;
                soBase.Criteria.AddRange(_currentSearchOperationGroup.Criteria);
                _currentSearchOperationGroup.Criteria.Clear();
                _currentSearchOperationGroup.Criteria.Add(soBase);
                _currentSearchOperationGroup.GroupType = groupType;
                _currentSearchOperationGroup.Criteria.Add(so);
            }
        }
        private void _getParameterizedOperatoinHelper(List <SearchOperation> ops,
                                                      SearchOperationGroup searchOperationGroup)
        {
            foreach (var so in searchOperationGroup.Criteria)
            {
                // we'll do our recursion up front
                var sog = so as SearchOperationGroup;
                if (sog != null)
                {
                    _getParameterizedOperatoinHelper(ops, sog);
                }

                else if (so.EnableParameterization)
                {
                    ops.Add(so);
                }
            }
        }
Пример #6
0
 public void CloseParenthesis()
 {
     // pop the group off of the stack
     _currentSearchOperationGroup = _parenthesesStack.Pop();
 }