private void PopulateSearchFolder(SearchFolder searchFolder, QueryFilter queryFilter) { IAsyncResult asyncResult = searchFolder.BeginApplyOneTimeSearch(new SearchFolderCriteria(queryFilter, new StoreId[] { this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Root) }) { DeepTraversal = true }, null, null); bool flag = asyncResult.AsyncWaitHandle.WaitOne(SearchFolderManager.MaximumSearchTime, false); if (flag) { searchFolder.EndApplyOneTimeSearch(asyncResult); } else { SearchFolderManager.Tracer.TraceDebug <SearchFolderManager>((long)this.GetHashCode(), "{0}: ELC Auto Tag search timed out.", this); } searchFolder.Save(); searchFolder.Load(); }
// Token: 0x06000942 RID: 2370 RVA: 0x000424EC File Offset: 0x000406EC public Folder Execute(UserContext userContext, Folder folder, SearchScope searchScope, string searchString, bool newSearch, bool asyncSearch) { if (userContext == null) { throw new ArgumentNullException("userContext"); } if (folder == null) { throw new ArgumentNullException("folder"); } MailboxSession mailboxSession = (MailboxSession)folder.Session; QueryFilter queryFilter = SearchFilterGenerator.Execute(searchString, mailboxSession.Mailbox.IsContentIndexingEnabled, userContext.UserCulture, new PolicyTagMailboxProvider(userContext.MailboxSession), folder, searchScope, this.advancedQueryFilter); string text = (queryFilter == null) ? string.Empty : queryFilter.ToString(); OwaStoreObjectId owaStoreObjectId = OwaStoreObjectId.CreateFromStoreObject(folder); SearchFolder searchFolder = null; bool flag = false; Folder result; try { if (userContext.SearchFolderId != null) { if (!newSearch && userContext.LastSearchFolderId.Equals(owaStoreObjectId) && userContext.LastSearchQueryFilter.CompareTo(text) == 0 && userContext.LastSearchScope == searchScope) { try { searchFolder = SearchFolder.Bind(userContext.SearchFolderId.GetSession(userContext), userContext.SearchFolderId.StoreObjectId, FolderSearch.PrefetchProperties); } catch (ObjectNotFoundException) { } if (searchFolder != null) { if (asyncSearch) { SearchPerformanceData searchPerformanceData = userContext.MapiNotificationManager.GetSearchPerformanceData(mailboxSession); if (searchPerformanceData != null) { searchPerformanceData.RefreshStart(); } OwaContext.Current.SearchPerformanceData = searchPerformanceData; } flag = true; return(searchFolder); } } if (userContext.IsPushNotificationsEnabled) { userContext.MapiNotificationManager.CancelSearchNotifications(mailboxSession); userContext.MapiNotificationManager.AddSearchFolderDeleteList(mailboxSession, userContext.SearchFolderId.StoreObjectId); } else { mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[] { userContext.SearchFolderId.StoreObjectId }); } userContext.SearchFolderId = null; } using (Folder folder2 = Folder.Bind(mailboxSession, userContext.GetSearchFoldersId(mailboxSession).StoreObjectId)) { searchFolder = SearchFolder.Create(mailboxSession, folder2.Id.ObjectId, "OWA Search " + userContext.Key.UserContextId + " " + DateTime.UtcNow.ToString("o"), CreateMode.CreateNew); } searchFolder.Save(); searchFolder.Load(FolderSearch.PrefetchProperties); userContext.SearchFolderId = OwaStoreObjectId.CreateFromStoreObject(searchFolder); userContext.LastSearchFolderId = owaStoreObjectId; userContext.LastSearchQueryFilter = text; userContext.LastSearchScope = searchScope; if (queryFilter == null) { flag = true; result = searchFolder; } else { bool flag2 = FolderSearch.FailNonContentIndexedSearch(folder, queryFilter); bool flag3; StoreId[] folderScope; if (searchScope == SearchScope.SelectedFolder || !mailboxSession.Mailbox.IsContentIndexingEnabled) { flag3 = false; folderScope = new StoreId[] { folder.Id.ObjectId }; } else if (searchScope == SearchScope.SelectedAndSubfolders) { flag3 = true; folderScope = new StoreId[] { folder.Id.ObjectId }; } else { if (searchScope != SearchScope.AllFoldersAndItems && searchScope != SearchScope.AllItemsInModule) { throw new ArgumentOutOfRangeException(); } flag3 = true; folderScope = new StoreId[] { userContext.GetRootFolderId(mailboxSession) }; } if (searchScope != SearchScope.SelectedFolder) { if (!folder.Id.ObjectId.Equals(userContext.JunkEmailFolderId)) { QueryFilter queryFilter2 = new ComparisonFilter(ComparisonOperator.NotEqual, StoreObjectSchema.ParentItemId, userContext.JunkEmailFolderId); queryFilter = new AndFilter(new QueryFilter[] { queryFilter, queryFilter2 }); } StoreObjectId storeObjectId = userContext.GetDeletedItemsFolderId((MailboxSession)folder.Session).StoreObjectId; if (!folder.Id.ObjectId.Equals(storeObjectId)) { QueryFilter queryFilter3 = new ComparisonFilter(ComparisonOperator.NotEqual, StoreObjectSchema.ParentItemId, storeObjectId); queryFilter = new AndFilter(new QueryFilter[] { queryFilter, queryFilter3 }); } } ExTraceGlobals.MailDataTracer.TraceDebug((long)this.GetHashCode(), "Search\nFilter: {0}\nDeep Traversal: {1}\nFolder: {2}\nContent Indexing Enabled: {3}", new object[] { queryFilter, flag3, folder.Id, mailboxSession.Mailbox.IsContentIndexingEnabled ? "Yes" : "No" }); SearchFolderCriteria searchFolderCriteria = new SearchFolderCriteria(queryFilter, folderScope); searchFolderCriteria.DeepTraversal = flag3; searchFolderCriteria.MaximumResultsCount = new int?(1000); searchFolderCriteria.FailNonContentIndexedSearch = flag2; SearchPerformanceData searchPerformanceData; if (!userContext.IsPushNotificationsEnabled || !asyncSearch) { searchPerformanceData = new SearchPerformanceData(); searchPerformanceData.StartSearch(searchString); IAsyncResult asyncResult = searchFolder.BeginApplyOneTimeSearch(searchFolderCriteria, null, null); Stopwatch stopwatch = Utilities.StartWatch(); bool flag4 = asyncResult.AsyncWaitHandle.WaitOne(30000, false); searchPerformanceData.Complete(!flag4, true); if (flag4) { searchFolder.EndApplyOneTimeSearch(asyncResult); } else { ExTraceGlobals.MailTracer.TraceDebug((long)this.GetHashCode(), "FolderSearch.Execute. Search timed out."); if (Globals.ArePerfCountersEnabled) { OwaSingleCounters.SearchesTimedOut.Increment(); } } Utilities.StopWatch(stopwatch, "FolderSearch.Execute (Wait for search to complete)"); if (Globals.ArePerfCountersEnabled) { PerformanceCounterManager.UpdateSearchTimePerformanceCounter(stopwatch.ElapsedMilliseconds); OwaSingleCounters.TotalSearches.Increment(); } searchFolder.Save(); searchFolder.Load(FolderSearch.PrefetchProperties); } else { userContext.MapiNotificationManager.InitSearchNotifications(mailboxSession, userContext.SearchFolderId.StoreObjectId, searchFolder, searchFolderCriteria, searchString); searchPerformanceData = userContext.MapiNotificationManager.GetSearchPerformanceData(mailboxSession); } if (!flag2) { searchPerformanceData.SlowSearchEnabled(); } OwaContext.Current.SearchPerformanceData = searchPerformanceData; flag = true; result = searchFolder; } } finally { if (!flag && searchFolder != null) { searchFolder.Dispose(); } } return(result); }
// Token: 0x060005CD RID: 1485 RVA: 0x0002BC64 File Offset: 0x00029E64 private StoreId SubmitSearch(QueryFilter searchCriteriaFilter) { StoreId result = null; MailboxSession mailboxSession = base.MailboxDataForTags.MailboxSession; if (searchCriteriaFilter != null) { if (!mailboxSession.Mailbox.IsContentIndexingEnabled) { DiscoveryHoldEnforcer.Tracer.TraceError <DiscoveryHoldEnforcer, string>((long)this.GetHashCode(), "{0}: CI search failed on the mailbox {1}. CI is not enabled on the mailbox database", this, mailboxSession.ToString()); throw new DiscoveryHoldSearchException(Strings.ErrorDiscoveryHoldsCIIndexDisabledOnDatabase(searchCriteriaFilter.ToString(), mailboxSession.ToString())); } DiscoveryHoldEnforcer.Tracer.TraceDebug <DiscoveryHoldEnforcer, string>((long)this.GetHashCode(), "{0} : Creating search folder for hold queries for mailbox {1}", this, mailboxSession.ToString()); using (SearchFolder searchFolder = SearchFolder.Create(mailboxSession, this.discoveryHoldsFolderId, DiscoveryHoldEnforcer.SearchDiscoveryHoldsFolderName, CreateMode.OpenIfExists)) { searchFolder.Save(); searchFolder.Load(); result = searchFolder.Id; QueryFilter searchQuery = new CountFilter(10000U, searchCriteriaFilter); SearchFolderCriteria searchFolderCriteria = new SearchFolderCriteria(searchQuery, new StoreId[] { this.discoveryHoldsFolderId }); searchFolderCriteria.DeepTraversal = true; searchFolderCriteria.UseCiForComplexQueries = true; searchFolderCriteria.FailNonContentIndexedSearch = true; int num = 0; bool flag = true; while (flag) { DiscoveryHoldEnforcer.Tracer.TraceDebug <DiscoveryHoldEnforcer, string, int>((long)this.GetHashCode(), "{0} : Begin search folder execution for mailbox {1}. Attempt#: {2}", this, mailboxSession.ToString(), num); IAsyncResult asyncResult = searchFolder.BeginApplyOneTimeSearch(searchFolderCriteria, null, null); bool flag2 = asyncResult.AsyncWaitHandle.WaitOne(60000, false); if (flag2) { DiscoveryHoldEnforcer.Tracer.TraceDebug <DiscoveryHoldEnforcer, string>((long)this.GetHashCode(), "{0} : Search folder execution completed for mailbox {1}", this, mailboxSession.ToString()); searchFolder.EndApplyOneTimeSearch(asyncResult); SearchFolderCriteria searchCriteria = searchFolder.GetSearchCriteria(); if ((searchCriteria.SearchState & SearchState.FailNonContentIndexedSearch) == SearchState.FailNonContentIndexedSearch && (searchCriteria.SearchState & SearchState.Failed) == SearchState.Failed) { DiscoveryHoldEnforcer.Tracer.TraceDebug <DiscoveryHoldEnforcer, string>((long)this.GetHashCode(), "{0} : Discovery Hold search failed because CI is not running, search query was not served by CI for mailbox {1}", this, mailboxSession.ToString()); throw new DiscoveryHoldSearchException(Strings.ErrorDiscoveryHoldsCIIndexNotRunning(searchCriteriaFilter.ToString(), mailboxSession.ToString())); } flag = false; } else { DiscoveryHoldEnforcer.Tracer.TraceDebug <DiscoveryHoldEnforcer, string>((long)this.GetHashCode(), "{0} : Discovery Hold Search folder execution has timed out for mailbox {1}", this, mailboxSession.ToString()); if (num >= 3) { DiscoveryHoldEnforcer.Tracer.TraceDebug <DiscoveryHoldEnforcer, string, int>((long)this.GetHashCode(), "{0} : Discovery Hold Search folder execution has timed out for mailbox {1} and exceeded max retry count {2}. Give up.", this, mailboxSession.ToString(), 3); throw new DiscoveryHoldSearchException(Strings.ErrorDiscoverySearchTimeout(60.ToString(), searchCriteriaFilter.ToString(), mailboxSession.ToString())); } flag = true; num++; } } searchFolder.Save(); searchFolder.Load(); } } return(result); }