コード例 #1
0
        public override void Clean()
        {
            if (Criteria == null)
            {
                return;
            }

            for (var i = Criteria.Count - 1; i >= 0; i--)
            {
                var op  = Criteria[i];
                var sog = op as SearchOperationGroup;

                if (sog != null && (sog.Criteria == null || sog.Criteria.Count == 0)) // its useless
                {
                    Criteria.RemoveAt(i);
                    continue;
                }
                op.Parent = this;
                op.Clean();
            }

            if (Criteria.Count == 1 && Criteria[0] is SearchOperationGroup) // just collapse the group
            {
                var sog = (SearchOperationGroup)Criteria[0];
                GroupType = sog.GroupType;
                Criteria.Remove(sog);
                Criteria.AddRange(sog.Criteria); // add the criteria to this group
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
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);
            }
        }