/// <summary> /// Recursively finds the operation. /// </summary> /// <param name="so">The so.</param> /// <returns></returns> public SearchOperation FindOperation(string operationID) { SearchOperation r = null; foreach (var c in Criteria) { if (c.ID == operationID) { return(c); } var sog = c as SearchOperationGroup; if (sog != null) { r = sog.FindOperation(operationID); if (r != null) { return(r); } } } return(r); }
/// <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); }
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); } }
public void AddCriteria(SearchOperation op) { Criteria.Add(op); }
/// <summary> /// Recursively finds the operation. /// </summary> /// <param name="so">The so.</param> /// <returns></returns> public SearchOperation FindOperation(SearchOperation so) { return(FindOperation(so.ID)); }