protected override object GetModel() { if (ContextNode == null) { return(null); } var content = Content.Create(ContextNode); var qs = new QuerySettings(); if (EnableAutofilters != FilterStatus.Default) { qs.EnableAutofilters = (EnableAutofilters == FilterStatus.Enabled); } if (EnableLifespanFilter != FilterStatus.Default) { qs.EnableLifespanFilter = (EnableLifespanFilter == FilterStatus.Enabled); } if (Top > 0) { qs.Top = Top; } if (State.Skip > 0) { qs.Skip = State.Skip; } if (!string.IsNullOrEmpty(State.SortColumn)) { qs.Sort = new[] { new SortInfo { FieldName = State.SortColumn, Reverse = State.SortDescending } }; } content.ChildrenQuerySettings = qs; content.ChildrenQueryFilter = GetQueryFilter(); content.XmlWriterExtender = writer => { }; switch (CollectionAxis) { case CollectionAxisMode.Children: return(content); case CollectionAxisMode.VersionHistory: var versionRoot = SearchFolder.Create(content.Versions); return(versionRoot); case CollectionAxisMode.ReferenceProperty: return(content); case CollectionAxisMode.External: return(SearchFolder.Create(RequestNodeList)); } return(null); }
public void ContentSerialization_1() { var query = new NodeQuery(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, Repository.Root.Id)); var folder = SearchFolder.Create(query); var xml0 = XDocument.Load(new StreamReader(folder.GetXml(true))); var s0 = xml0.Element(XName.Get("Content")).Element(XName.Get("Children")).ToString(); var content = Content.Create(Repository.Root); var xml1 = XDocument.Load(new StreamReader(content.GetXml(true))); var s1 = xml1.Element(XName.Get("Content")).Element(XName.Get("Children")).ToString(); Assert.IsTrue(s0 == s1); }
public IAsyncResult BeginAuditLogQuery(QueryFilter queryFilter, int maximumResultsCount) { if (this.pendingAsyncResult != null) { throw new InvalidOperationException("Asynchronous query is already pending."); } StoreId storeId = null; IAsyncResult result; using (DisposeGuard disposeGuard = default(DisposeGuard)) { Folder disposable; if (queryFilter != null) { SearchFolder searchFolder = SearchFolder.Create(this.auditLog.Session, this.auditLog.Session.GetDefaultFolderId(DefaultFolderType.SearchFolders), "SearchAuditMailboxFolder" + Guid.NewGuid().ToString(), CreateMode.OpenIfExists); disposeGuard.Add <SearchFolder>(searchFolder); searchFolder.Save(); searchFolder.Load(); storeId = searchFolder.Id; result = searchFolder.BeginApplyOneTimeSearch(new SearchFolderCriteria(queryFilter, new StoreId[] { this.auditLog.LogFolderId }) { DeepTraversal = false, UseCiForComplexQueries = true, FailNonContentIndexedSearch = true, MaximumResultsCount = new int?(maximumResultsCount) }, null, null); disposable = searchFolder; } else { disposable = Folder.Bind(this.auditLog.Session, this.auditLog.LogFolderId); disposeGuard.Add <Folder>(disposable); result = new CompletedAsyncResult(); } disposeGuard.Success(); this.pendingAsyncResult = result; this.folder = disposable; this.folderIdToDelete = storeId; } 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); }
protected override object GetModel() { var node = GetContextNode(); if (node == null) { return(null); } var top = this.MaxItems < 1 ? 10 : this.MaxItems; var nodeList = new List <Node>(); IEnumerable <JournalItem> items; if (ShowSystemContent) { items = Journals.Get(node.Path, top); nodeList.AddRange(items.Select(item => new JournalNode(node, item)).Cast <Node>()); } else { var tempTop = top; var tempSkip = 0; while (true) { items = Journals.Get(node.Path, tempTop, tempSkip, true); var query = new StringBuilder("+("); var pathAdded = false; foreach (var item in items) { query.AppendFormat("Path:\"{0}\" ", item.Wherewith); pathAdded = true; } //not found any journal items, finish the search if (!pathAdded) { break; } query.Append(") +IsSystemContent:yes"); var queryResults = ContentQuery.Query(query.ToString(), new QuerySettings() { EnableAutofilters = FilterStatus.Disabled, EnableLifespanFilter = FilterStatus.Disabled }); var pathList = queryResults.Nodes.Select(n => n.Path).ToArray(); var maxToAdd = Math.Max(0, top - nodeList.Count); nodeList.AddRange(items.Where(item => !pathList.Contains(item.Wherewith)).Take(maxToAdd).Select(ji => new JournalNode(node, ji))); if (nodeList.Count >= top || items.Count() == 0) { break; } tempSkip += tempTop; tempTop = Math.Max(tempTop * 2, 50); } } var folder = SearchFolder.Create(nodeList); return(folder.GetXml(true)); }
// 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); }
protected override object GetModel() { if (ContextNode == null) { return(null); } var content = Content.Create(ContextNode); var cdef = content.ChildrenDefinition; if (EnableAutofilters != FilterStatus.Default) { cdef.EnableAutofilters = EnableAutofilters; } if (EnableLifespanFilter != FilterStatus.Default) { cdef.EnableLifespanFilter = EnableLifespanFilter; } if (Top > 0) { cdef.Top = Top; } if (State.Skip > 0) { cdef.Skip = State.Skip; } if (!string.IsNullOrEmpty(State.SortColumn)) { cdef.Sort = new[] { new SortInfo { FieldName = State.SortColumn, Reverse = State.SortDescending } } } ; var filter = GetQueryFilter(); if (!string.IsNullOrEmpty(content.ChildrenDefinition.ContentQuery)) { // combine the two queries (e.g. in case of a Smart Folder or a container with a custom children query) if (!string.IsNullOrEmpty(filter)) { content.ChildrenDefinition.ContentQuery = ContentQuery.AddClause(content.ChildrenDefinition.ContentQuery, filter, ChainOperator.And); } } else { content.ChildrenDefinition.ContentQuery = filter; } content.XmlWriterExtender = writer => { }; switch (CollectionAxis) { case CollectionAxisMode.Children: return(content); case CollectionAxisMode.VersionHistory: var versionRoot = SearchFolder.Create(content.Versions); return(versionRoot); case CollectionAxisMode.ReferenceProperty: return(content); case CollectionAxisMode.External: return(SearchFolder.Create(RequestNodeList)); } return(null); }
public void Execute() { Folder folder = null; try { folder = Folder.Bind(this.mailboxSession, this.mailboxSession.GetDefaultFolderId(DefaultFolderType.SearchFolders)); string text = "EAS Search Device:" + this.context.Request.DeviceIdentity.DeviceId; bool flag = !this.forceResetSearchCriteria; AirSyncDiagnostics.TraceDebug <bool>(ExTraceGlobals.AlgorithmTracer, this, "reuseExistingSearchFolderCriteria = !this.forceResetSearchCriteria, therefore reuseExistingSearchFolderCriteria = {0}", flag); if (this.queryFilter != null) { StoreObjectId storeObjectId = null; using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, MailboxSearchProvider.displayNameSortBy, new PropertyDefinition[] { FolderSchema.Id, StoreObjectSchema.DisplayName })) { QueryFilter seekFilter = new ComparisonFilter(ComparisonOperator.Equal, StoreObjectSchema.DisplayName, text); if (queryResult.SeekToCondition(SeekReference.OriginBeginning, seekFilter)) { object[][] rows = queryResult.GetRows(1); storeObjectId = ((VersionedId)rows[0][0]).ObjectId; } } SearchFolderCriteria searchFolderCriteria = null; if (storeObjectId != null) { this.searchFolder = SearchFolder.Bind(this.mailboxSession, storeObjectId, new PropertyDefinition[] { MailboxSearchProvider.SearchFolderTextDescription, FolderSchema.ItemCount, FolderSchema.UnreadCount, FolderSchema.SearchFolderItemCount }); try { searchFolderCriteria = this.searchFolder.GetSearchCriteria(); AirSyncDiagnostics.TraceDebug <SearchFolderCriteria>(ExTraceGlobals.AlgorithmTracer, this, "Existing search folder has search criteria {0}", searchFolderCriteria); } catch (StoragePermanentException) { flag = false; AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "GetSearchCriteria() threw StoragePermanentException due to a pre-existing restriction on the search folder. This condition is expected and handled."); } catch (ArgumentException) { flag = false; AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "GetSearchCriteria() threw ArgumentException due to a pre-existing restriction on the search folder. This condition is expected and handled."); } catch (ObjectNotInitializedException) { flag = false; AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "Search folder has null search criteria, reuseExistingSearchFolderCriteria = false;"); } if (flag) { if (searchFolderCriteria.FolderScope == null || searchFolderCriteria.FolderScope.Length != this.folderScope.Length) { if (searchFolderCriteria.FolderScope == null) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "searchCriteria.FolderScope is null."); } else { AirSyncDiagnostics.TraceDebug <int>(ExTraceGlobals.AlgorithmTracer, this, "searchCriteria.FolderScope is not null and searchCriteria.FolderScope.Length is {0}", searchFolderCriteria.FolderScope.Length); } flag = false; AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "therefore reuseExistingSearchFolderCriteria = false"); } else { for (int i = 0; i < this.folderScope.Length; i++) { bool flag2 = false; for (int j = 0; j < searchFolderCriteria.FolderScope.Length; j++) { if (searchFolderCriteria.FolderScope[j].Equals(this.folderScope[i])) { flag2 = true; break; } } if (!flag2) { flag = false; AirSyncDiagnostics.TraceDebug <StoreId>(ExTraceGlobals.AlgorithmTracer, this, "foundIt == false for this.folderScope[idx1] == {0}, therefore reuseExistingSearchFolderCriteria = false", this.folderScope[i]); break; } AirSyncDiagnostics.TraceDebug <StoreId, bool>(ExTraceGlobals.AlgorithmTracer, this, "foundIt == true for this.folderScope[idx1] == {0}, therefore reuseExistingSearchFolderCriteria stays at value: {1}", this.folderScope[i], flag); } } } if (flag) { string text2 = this.searchFolder.TryGetProperty(MailboxSearchProvider.SearchFolderTextDescription) as string; if (searchFolderCriteria.SearchQuery == null) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "searchCriteria.SearchQuery == null, therefore reuseExistingSearchFolderCriteria = false"); flag = false; } else if (text2 != this.queryFilter.ToString()) { AirSyncDiagnostics.TraceDebug <string, QueryFilter>(ExTraceGlobals.AlgorithmTracer, this, "oldSearchFilter == {0}, and this.queryFilter.ToString() == {1}, therefore reuseExistingSearchFolderCriteria = false", text2, this.queryFilter); flag = false; } else if (searchFolderCriteria.DeepTraversal != this.deepTraversal) { AirSyncDiagnostics.TraceDebug <bool, bool>(ExTraceGlobals.AlgorithmTracer, this, "searchCriteria.DeepTraversal == {0}, and this.deepTraversal == {1}, therefore reuseExistingSearchFolderCriteria = false", searchFolderCriteria.DeepTraversal, this.deepTraversal); flag = false; } } } else { this.searchFolder = SearchFolder.Create(this.mailboxSession, folder.Id.ObjectId, text, CreateMode.OpenIfExists); AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.AlgorithmTracer, this, "Created a new search folder with display name: {0}", text); this.searchFolder.Save(); this.searchFolder.Load(new PropertyDefinition[] { FolderSchema.ItemCount, FolderSchema.UnreadCount, FolderSchema.SearchFolderItemCount }); flag = false; AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "Search folder was just recreated, therefore reuseExistingSearchFolderCriteria = false"); } if (!flag) { searchFolderCriteria = new SearchFolderCriteria(this.queryFilter, this.folderScope); searchFolderCriteria.DeepTraversal = this.deepTraversal; searchFolderCriteria.MaximumResultsCount = new int?(GlobalSettings.MaxMailboxSearchResults); AirSyncDiagnostics.TraceDebug <QueryFilter, int, bool>(ExTraceGlobals.AlgorithmTracer, this, "Created search criteria on search folder with queryFilter=={0}, folderScope.Length=={1}, deepTraversal=={2}", this.queryFilter, this.folderScope.Length, this.deepTraversal); Stopwatch stopwatch = Stopwatch.StartNew(); IAsyncResult asyncResult = this.searchFolder.BeginApplyOneTimeSearch(searchFolderCriteria, null, null); int millisecondsTimeout = this.mailboxSession.Mailbox.IsContentIndexingEnabled ? this.maximumSearchTime : this.maximumSearchTimeNoContentIndexing; bool flag3 = asyncResult.AsyncWaitHandle.WaitOne(millisecondsTimeout, false); stopwatch.Stop(); Command.CurrentCommand.Context.ProtocolLogger.SetValue(ProtocolLoggerData.SearchQueryTime, (int)stopwatch.ElapsedMilliseconds); if (!flag3) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.AlgorithmTracer, this, "MailboxSearchProvider.Execute. Search timed out."); throw new SearchTimeOutException(); } this.searchFolder[MailboxSearchProvider.SearchFolderTextDescription] = ((this.queryFilter == null) ? "null" : this.queryFilter.ToString()); this.searchFolder.EndApplyOneTimeSearch(asyncResult); this.searchFolder.Save(); this.searchFolder.Load(new PropertyDefinition[] { FolderSchema.ItemCount, FolderSchema.UnreadCount, FolderSchema.SearchFolderItemCount }); } } } catch (SearchTimeOutException) { throw; } catch (Exception innerException) { throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, innerException, false) { ErrorStringForProtocolLogger = "GeneralMbxSearchError" }; } finally { if (this.folderIdMappingSyncState != null) { this.folderIdMappingSyncState.Dispose(); } this.folderIdMappingSyncState = null; if (folder != null) { folder.Dispose(); } folder = null; } }