// Make a new search which is the same as the current search but with an additional filter public Search AddFilter(QueryFilter addFilter) { QueryScope scope = (Query == null ? null : Query.QueryScope); QueryFilter filter; if (Query == null || Query.QueryFilter == null) { filter = addFilter; } else if (addFilter == null) { filter = Query.QueryFilter; } else { filter = new GroupQuery(new QueryFilter[] { Query.QueryFilter, addFilter }, GroupQuery.GroupQueryType.And); } return(new Search(new Query(scope, filter), Grouping, ShowSearch, "", "", Columns, Sorting)); }
public override bool Equals(object obj) { GroupQuery other = obj as GroupQuery; if (other == null) { return(false); } if (other.type != this.type) { return(false); } int i; for (i = 0; i < subqueries.Length; i++) { if (i >= other.subqueries.Length) { return(false); } if (!subqueries[i].Equals(other.subqueries[i])) { return(false); } } if (i < other.subqueries.Length) { return(false); } return(true); }
public static Search SearchFor(IEnumerable <IXenObject> objects) { if (objects == null) { return(SearchFor((IXenObject)null)); } List <IXenObject> objectList = new List <IXenObject>(objects); if (objectList.Count == 0) { return(SearchFor((IXenObject)null)); } else if (objectList.Count == 1) { return(SearchFor(objectList[0])); } else { bool containsHost = false; bool containsPool = false; List <QueryFilter> queryFilters = new List <QueryFilter>(); foreach (IXenObject obj in objects) { Pool poolAncestor = obj != null?Helpers.GetPool(obj.Connection) : null; if (poolAncestor != null) { containsPool = true; QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(poolAncestor), StringPropertyQuery.PropertyQueryType.exactmatch, true); queryFilters.Add(new RecursiveXMOPropertyQuery <Pool>(PropertyNames.pool, uuidQuery)); } else { Host hostAncestor = Helpers.GetHostAncestor(obj); if (hostAncestor != null) { containsHost = true; QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(hostAncestor), StringPropertyQuery.PropertyQueryType.exactmatch, true); queryFilters.Add(new RecursiveXMOListPropertyQuery <Host>(PropertyNames.host, uuidQuery)); } } } Grouping grouping = null; if (containsPool) { Grouping hostGrouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null); grouping = new XenModelObjectPropertyGrouping <Pool>(PropertyNames.pool, hostGrouping); } else if (containsHost) { grouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null); } GroupQuery groupQuery = new GroupQuery(queryFilters.ToArray(), GroupQuery.GroupQueryType.Or); Query query = new Query(GetOverviewScope(), groupQuery); return(new Search(query, grouping, false, Messages.SEARCH_TITLE_OVERVIEW, null, false)); } }