private SearchFolder GetSearchFolder(MailboxSession session) { bool flag = false; StoreObjectId storeObjectId = this.GetCvsFolderIdIfPresent(session); SearchFolder searchFolder = null; try { if (storeObjectId == null) { storeObjectId = session.CreateDefaultFolder(DefaultFolderType.CalendarVersionStore); } try { searchFolder = SearchFolder.Bind(session, storeObjectId); } catch (ObjectNotFoundException innerException) { ExTraceGlobals.DefaultFoldersTracer.TraceError <string, StoreObjectId>((long)this.GetHashCode(), "CalendarVersionStoreGateway::GetSearchFolder - No item is found with the CVS search folder ID (Session Display Name: {0}; Folder ID: {1}).", session.DisplayName, storeObjectId); throw new CalendarVersionStoreNotPopulatedException(false, SearchState.None, TimeSpan.Zero, innerException); } catch (WrongObjectTypeException innerException2) { ExTraceGlobals.DefaultFoldersTracer.TraceError <string, StoreObjectId>((long)this.GetHashCode(), "CalendarVersionStoreGateway::GetSearchFolder - The CVS search folder ID does not belong to a search folder (Session Display Name: {0}; Folder ID: {1}).", session.DisplayName, storeObjectId); throw new CalendarVersionStoreNotPopulatedException(false, SearchState.None, TimeSpan.Zero, innerException2); } SearchState folderState; if (!this.IsSearchFolderPopulated(searchFolder, out folderState)) { if (this.Policy.WaitForPopulation) { using (SearchFolderAsyncSearch searchFolderAsyncSearch = new SearchFolderAsyncSearch(session, storeObjectId, null, null)) { if (!this.IsSearchFolderPopulated(searchFolder, out folderState) && !searchFolderAsyncSearch.AsyncResult.AsyncWaitHandle.WaitOne(this.Policy.WaitTimeForPopulation)) { ExTraceGlobals.DefaultFoldersTracer.TraceDebug <TimeSpan, string>((long)this.GetHashCode(), "CalendarVersionStoreGateway::GetSearchFolder - The CVS search folder is not populated, and timeout ({0}) is passed (Session Display Name: {1}).", this.Policy.WaitTimeForPopulation, session.DisplayName); throw new CalendarVersionStoreNotPopulatedException(true, folderState, this.Policy.WaitTimeForPopulation); } goto IL_151; } } ExTraceGlobals.DefaultFoldersTracer.TraceDebug <string>((long)this.GetHashCode(), "CalendarVersionStoreGateway::GetSearchFolder - The CVS search folder is not populated, and query policy has no wait time specified (Session Display Name: {0}).", session.DisplayName); throw new CalendarVersionStoreNotPopulatedException(true, folderState, TimeSpan.Zero); } IL_151: flag = true; } finally { if (!flag && searchFolder != null) { searchFolder.Dispose(); } } return(searchFolder); }
internal Folder GetNoArchiveTagSearchFolder() { bool flag = false; SearchFolder searchFolder = null; Folder result; try { searchFolder = this.CreateSearchFolder("NoArchiveTagSearchFolder8534F96D-4183-41fb-8A05-9B7112AE2100"); SearchFolderCriteria searchFolderCriteria = new SearchFolderCriteria(SearchFolderManager.NoArchiveTagFolderQuery, new StoreId[] { this.mailboxSession.GetDefaultFolderId(DefaultFolderType.Root) }); searchFolderCriteria.DeepTraversal = true; SearchFolderCriteria searchFolderCriteria2 = null; try { searchFolderCriteria2 = searchFolder.GetSearchCriteria(); } catch (ObjectNotInitializedException) { SearchFolderManager.Tracer.TraceDebug((long)this.GetHashCode(), "{0}: SearchFolderCriteria could not be retrieved from search folder. Need to set it."); } if (searchFolderCriteria2 == null || !this.SearchCriterionMatches(searchFolderCriteria2, searchFolderCriteria)) { this.PopulateDynamicSearchFolder(searchFolder, searchFolderCriteria); } flag = true; result = searchFolder; } finally { if (!flag && searchFolder != null) { searchFolder.Dispose(); } } return(result); }
private SearchFolder CreateSearchFolder(string searchFolderName) { bool flag = false; SearchFolder searchFolder = null; SearchFolder result; try { searchFolder = SearchFolder.Create(this.mailboxSession, this.mailboxSession.GetDefaultFolderId(DefaultFolderType.SearchFolders), searchFolderName, CreateMode.OpenIfExists); searchFolder.Save(); searchFolder.Load(); SearchFolderManager.Tracer.TraceDebug <SearchFolderManager>((long)this.GetHashCode(), "{0}: Created or opened archive search folder.", this); flag = true; result = searchFolder; } finally { if (!flag && searchFolder != null) { searchFolder.Dispose(); } } return(result); }
// 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); }