public static Search SearchForFolder(string path) { QueryScope scope = new QueryScope(ObjectTypes.AllIncFolders); QueryFilter innerFilter = new StringPropertyQuery(PropertyNames.uuid, path, StringPropertyQuery.PropertyQueryType.exactmatch, true); QueryFilter filter = new RecursiveXMOPropertyQuery <Folder>(PropertyNames.folder, innerFilter); Query q = new Query(scope, filter); Grouping grouping = new FolderGrouping((Grouping)null); string[] pathParts = Folders.PointToPath(path); string name = ((pathParts.Length == 0 || (pathParts.Length == 1 && pathParts[pathParts.Length - 1] == String.Empty)) ? Messages.FOLDERS : pathParts[pathParts.Length - 1]); return(new Search(q, grouping, false, name, null, false)); }
/// <summary> /// This gets the default search for the overview panel when an object in the tree is selected. /// Pass null as value and you'll get the default search (this could be the default overview or default treeview search, /// depending on the value of scope). /// </summary> /// <param name="value"></param> /// <returns></returns> public static Search SearchFor(IXenObject value, QueryScope scope) { if (value is Host) { Grouping hostGrouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null); QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(value), StringPropertyQuery.PropertyQueryType.exactmatch, true); QueryFilter hostQuery = new RecursiveXMOListPropertyQuery <Host>(PropertyNames.host, uuidQuery); Query query = new Query(scope, hostQuery); return(new Search(query, hostGrouping, false, String.Format(Messages.SEARCH_TITLE_HOST, Helpers.GetName(value)), null, false)); } else if (value is Pool) { Grouping hostGrouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, null); Grouping poolGrouping = new XenModelObjectPropertyGrouping <Pool>(PropertyNames.pool, hostGrouping); QueryFilter uuidQuery = new StringPropertyQuery(PropertyNames.uuid, Helpers.GetUuid(value), StringPropertyQuery.PropertyQueryType.exactmatch, true); QueryFilter poolQuery = new RecursiveXMOPropertyQuery <Pool>(PropertyNames.pool, uuidQuery); Query query = new Query(scope, poolQuery); return(new Search(query, poolGrouping, false, String.Format(Messages.SEARCH_TITLE_POOL, Helpers.GetName(value)), null, false)); } else if (value is Folder) { Folder folder = value as Folder; return(Search.SearchForFolder(folder.opaque_ref)); } else { // This is the default search on the treeview //Grouping storageLinkPoolGrouping = new XenModelObjectPropertyGrouping<StorageLinkPool>(PropertyNames.storageLinkPool, (Grouping)null); //Grouping storageLinkSystemGrouping = new XenModelObjectPropertyGrouping<StorageLinkSystem>(PropertyNames.storageLinkSystem, storageLinkPoolGrouping); //Grouping storageLinkServerGrouping = new XenModelObjectPropertyGrouping<StorageLinkServer>(PropertyNames.storageLinkServer, storageLinkSystemGrouping); Grouping dockervmGrouping = new XenModelObjectPropertyGrouping <VM>(PropertyNames.dockervm, null); Grouping hostGrouping = new XenModelObjectPropertyGrouping <Host>(PropertyNames.host, dockervmGrouping); Grouping poolGrouping = new XenModelObjectPropertyGrouping <Pool>(PropertyNames.pool, hostGrouping); return(new Search(new Query(scope, null), poolGrouping, false, String.Format(Messages.SEARCH_TITLE_OVERVIEW), null, false)); } }