public static void WaitForSearchFolderPopulation(IXSOFactory xsoFactory, IMailboxSession mailboxSession, ISearchFolder searchFolder) { if (ContactsSearchFolderCriteria.IsSearchFolderPopulated(searchFolder)) { ContactsSearchFolderCriteria.Tracer.TraceDebug((long)mailboxSession.GetHashCode(), "Search folder is already populated. No wait required."); return; } ContactsSearchFolderCriteria.Tracer.TraceDebug((long)mailboxSession.GetHashCode(), "Waiting for search folder to complete current population."); searchFolder.Load(); using (SearchFolderAsyncSearch searchFolderAsyncSearch = new SearchFolderAsyncSearch((MailboxSession)mailboxSession, searchFolder.Id.ObjectId, null, null)) { if (ContactsSearchFolderCriteria.IsSearchFolderPopulated(searchFolder)) { ContactsSearchFolderCriteria.Tracer.TraceDebug((long)mailboxSession.GetHashCode(), "Search folder population completed."); } else { bool arg = searchFolderAsyncSearch.AsyncResult.AsyncWaitHandle.WaitOne(ContactsSearchFolderCriteria.SearchInProgressTimeout); ContactsSearchFolderCriteria.Tracer.TraceDebug <bool>((long)mailboxSession.GetHashCode(), "Done waiting, search folder population completed: {0}.", arg); } } }
private static void ApplySearchFolderCriteria(IXSOFactory xsoFactory, IMailboxSession mailboxSession, ISearchFolder searchFolder, SearchFolderCriteria searchFolderCriteria, Action <SearchFolderCriteria> applySearchCriteriaAction) { ArgumentValidator.ThrowIfNull("xsoFactory", xsoFactory); ArgumentValidator.ThrowIfNull("mailboxSession", mailboxSession); ArgumentValidator.ThrowIfNull("searchFolder", searchFolder); ArgumentValidator.ThrowIfNull("searchFolderCriteria", searchFolderCriteria); ContactsSearchFolderCriteria.Tracer.TraceDebug <SearchFolderCriteria>((long)mailboxSession.GetHashCode(), "Applying search folder criteria: {0}", searchFolderCriteria); try { applySearchCriteriaAction(searchFolderCriteria); } catch (ObjectNotFoundException) { List <StoreObjectId> list = new List <StoreObjectId>(searchFolderCriteria.FolderScope.Length); foreach (StoreId storeId in searchFolderCriteria.FolderScope) { list.Add((StoreObjectId)storeId); } searchFolderCriteria.FolderScope = ContactsSearchFolderCriteria.RemoveDeletedFoldersFromCollection(xsoFactory, mailboxSession, list); applySearchCriteriaAction(searchFolderCriteria); } }