public override SearchErrorInfo Remove(SearchId searchId, bool removeLogs) { MailboxSearchServer.Tracer.TraceFunction <string>((long)this.GetHashCode(), "MailboxSearchServer.Remove on {0}", searchId.SearchName); SearchErrorInfo errorInfo = null; SearchUtils.ExWatsonWrappedCall(delegate() { lock (this) { if (this.IsShutDown) { errorInfo = new SearchErrorInfo(-2147220983, Strings.SearchServerShutdown); } else if (this.searchWorkItemMap.ContainsKey(searchId)) { MailboxSearchServer.Tracer.TraceWarning <string>((long)this.GetHashCode(), "The search {0} is already started", searchId.SearchName); errorInfo = new SearchErrorInfo(-2147220980, Strings.ErrorRemoveOngoingSearch); } else if (this.pendingSearchIdMap.ContainsKey(searchId)) { this.pendingSearchIdMap.Remove(searchId); SearchEventLogger.Instance.LogDiscoverySearchPendingWorkItemsChangedEvent("RemovedFromPendingWorkItemsOnRemove", searchId.SearchName, searchId.MailboxDsName, this.pendingSearchIdMap.Count); } else { this.QueueSearchForDeletion(searchId, removeLogs, ref errorInfo); } } }); if (errorInfo != null && errorInfo.Failed) { MailboxSearchServer.LogErrorInfo("Error occured when trying to remove the search workitem", searchId, errorInfo); } return(errorInfo); }
public override SearchErrorInfo GetStatus(SearchId searchId, out SearchStatus searchStatus) { MailboxSearchServer.Tracer.TraceFunction <string>((long)this.GetHashCode(), "MailboxSearchServer.GetStatus {0}", searchId.SearchName); SearchErrorInfo errorInfo = null; searchStatus = null; SearchStatus theSearchStatus = null; SearchUtils.ExWatsonWrappedCall(delegate() { MailboxSearchWorkItem mailboxSearchWorkItem = null; if (!this.searchWorkItemMap.TryGetValue(searchId, out mailboxSearchWorkItem)) { MailboxSearchServer.Tracer.TraceWarning <string>((long)this.GetHashCode(), "The search {0} is not started", searchId.SearchName); errorInfo = new SearchErrorInfo(262658, Strings.SearchNotStarted); return; } try { theSearchStatus = mailboxSearchWorkItem.GetStatus(); } catch (ExportException ex) { MailboxSearchServer.Tracer.TraceError <ExportException>((long)this.GetHashCode(), "MailboxSearchServer.GetStatus error {0}", ex); errorInfo = new SearchErrorInfo(-2147220991, ex); } }); searchStatus = theSearchStatus; if (errorInfo != null && errorInfo.Failed) { MailboxSearchServer.LogErrorInfo("Error occured when trying to get the status of the search workitem", searchId, errorInfo); } return(errorInfo); }
public override SearchErrorInfo UpdateStatus(SearchId searchId) { MailboxSearchServer.Tracer.TraceFunction <string>((long)this.GetHashCode(), "MailboxSearchServer.UpdateStatus on {0}", searchId.SearchName); SearchErrorInfo errorInfo = null; SearchUtils.ExWatsonWrappedCall(delegate() { lock (this) { if (this.searchWorkItemMap.ContainsKey(searchId) || this.pendingSearchIdMap.ContainsKey(searchId)) { MailboxSearchServer.Tracer.TraceDebug <string>((long)this.GetHashCode(), "The search {0} is still in the queue. Not updating status", searchId.SearchName); } else { try { ADObjectId discoverySystemMailboxId = new ADObjectId(searchId.MailboxDsName, searchId.MailboxGuid); IMailboxSearchConfigurationProvider mailboxSearchConfigurationProvider = new MailboxSearchConfigurationProvider(discoverySystemMailboxId, searchId.SearchName); if (MailboxDiscoverySearch.IsInProgressState(mailboxSearchConfigurationProvider.SearchObject.Status)) { mailboxSearchConfigurationProvider.SearchObject.UpdateState(SearchStateTransition.Fail); mailboxSearchConfigurationProvider.UpdateSearchObject("UpdateStatus", 452); } else if (MailboxDiscoverySearch.IsInDeletionState(mailboxSearchConfigurationProvider.SearchObject.Status)) { this.QueueSearchForDeletion(searchId, true, ref errorInfo); } } catch (FormatException exception) { errorInfo = new SearchErrorInfo(-2147220990, exception); } catch (SearchObjectNotFoundException exception2) { errorInfo = new SearchErrorInfo(-2147220990, exception2); } catch (DataSourceOperationException exception3) { errorInfo = new SearchErrorInfo(-2147220990, exception3); } catch (NoInternalEwsAvailableException exception4) { errorInfo = new SearchErrorInfo(-2147220990, exception4); } } } }); if (errorInfo != null && errorInfo.Failed) { MailboxSearchServer.LogErrorInfo("Error occured when trying to update the status of the search workitem", searchId, errorInfo); } return(errorInfo); }
internal void RemoveWorkItem(SearchId searchId, bool releaseSemaphore, bool isEstimateOnly) { lock (this) { MailboxSearchWorkItem mailboxSearchWorkItem; if (this.searchWorkItemMap.TryGetValue(searchId, out mailboxSearchWorkItem)) { this.searchWorkItemMap.Remove(searchId); int num = -1; if (releaseSemaphore) { num = this.workItemSemaphore.Release(); } if (!isEstimateOnly && mailboxSearchWorkItem.Action == WorkItemAction.Start) { this.copySearchesInProgress--; } MailboxSearchServer.Tracer.TraceDebug <int, int>((long)this.GetHashCode(), "A search job is removed, Queue Length {0} and semaphore {1}", this.workItemQueue.Count, num + 1); SearchEventLogger.Instance.LogDiscoverySearchWorkItemQueueChangedEvent("RemovedFromRunningWorkItems", searchId.SearchName, searchId.MailboxDsName, mailboxSearchWorkItem.Action.ToString(), mailboxSearchWorkItem.IsEstimateOnly, this.workItemQueue.Count, this.searchWorkItemMap.Count, this.copySearchesInProgress, num + 1); SearchUtils.ExWatsonWrappedCall(delegate() { string ownerId = null; if (this.pendingSearchIdMap.TryGetValue(searchId, out ownerId)) { SearchErrorInfo searchErrorInfo = this.AddSearchToWorkItemQueue(searchId, ownerId); if (searchErrorInfo != null && searchErrorInfo.Failed) { MailboxSearchServer.LogErrorInfo("Error occured when try to Add a pending workitem to workitem queue", searchId, searchErrorInfo); } this.pendingSearchIdMap.Remove(searchId); MailboxSearchServer.Tracer.TraceDebug <int>((long)this.GetHashCode(), "Add pending search to the Queue, length = {0}", this.workItemQueue.Count); SearchEventLogger.Instance.LogDiscoverySearchPendingWorkItemsChangedEvent("RemovedFromPendingWorkItems", searchId.SearchName, searchId.MailboxDsName, this.pendingSearchIdMap.Count); } }); } else { MailboxSearchServer.Tracer.TraceError <string>((long)this.GetHashCode(), "Removing search {0} failed becasue it is not in the work item map.", searchId.SearchName); } } }
public override SearchErrorInfo StartEx(SearchId searchId, string ownerId) { MailboxSearchServer.Tracer.TraceFunction <string, string>((long)this.GetHashCode(), "MailboxSearchServer.Start {0}, {1}", searchId.SearchName, ownerId); SearchErrorInfo errorInfo = null; SearchUtils.ExWatsonWrappedCall(delegate() { lock (this) { if (this.IsShutDown) { errorInfo = new SearchErrorInfo(-2147220983, Strings.SearchServerShutdown); } else { bool flag2 = false; bool flag3 = this.searchWorkItemMap.ContainsKey(searchId); bool flag4 = this.pendingSearchIdMap.ContainsKey(searchId); if (flag3 || flag4) { bool flag5 = false; if (flag3) { MailboxSearchWorkItem mailboxSearchWorkItem = this.searchWorkItemMap[searchId]; if (mailboxSearchWorkItem.Action != WorkItemAction.Remove) { flag5 = true; } } if (flag4) { flag5 = true; } if (flag5) { MailboxSearchServer.Tracer.TraceWarning <string>((long)this.GetHashCode(), "Search {0} is already started", searchId.SearchName); errorInfo = new SearchErrorInfo(262657, Strings.SearchAlreadStarted); } else { flag2 = true; } } if (errorInfo == null) { if (flag2) { this.pendingSearchIdMap.Add(searchId, ownerId); SearchEventLogger.Instance.LogDiscoverySearchPendingWorkItemsChangedEvent("AddedToPendingWorkItems", searchId.SearchName, searchId.MailboxDsName, this.pendingSearchIdMap.Count); } else { errorInfo = this.AddSearchToWorkItemQueue(searchId, ownerId); } } } } }); if (errorInfo != null && errorInfo.Failed) { MailboxSearchServer.LogErrorInfo("Error occured when trying to start the search by adding it to queue", searchId, errorInfo); } return(errorInfo); }
public override SearchErrorInfo AbortEx(SearchId searchId, string userId) { MailboxSearchServer.Tracer.TraceFunction <string>((long)this.GetHashCode(), "MailboxSearchServer.Abort on {0}", searchId.SearchName); SearchErrorInfo errorInfo = null; SearchUtils.ExWatsonWrappedCall(delegate() { lock (this) { if (!this.searchWorkItemMap.ContainsKey(searchId) && !this.pendingSearchIdMap.ContainsKey(searchId)) { MailboxSearchServer.Tracer.TraceWarning <string>((long)this.GetHashCode(), "The search {0} is not started", searchId.SearchName); try { ADObjectId discoverySystemMailboxId = new ADObjectId(searchId.MailboxDsName, searchId.MailboxGuid); IMailboxSearchConfigurationProvider mailboxSearchConfigurationProvider = new MailboxSearchConfigurationProvider(discoverySystemMailboxId, searchId.SearchName); if (MailboxDiscoverySearch.IsInProgressState(mailboxSearchConfigurationProvider.SearchObject.Status)) { mailboxSearchConfigurationProvider.SearchObject.UpdateState(SearchStateTransition.Fail); mailboxSearchConfigurationProvider.UpdateSearchObject("AbortEx", 317); } errorInfo = new SearchErrorInfo(262658, Strings.SearchNotStarted); goto IL_3A4; } catch (FormatException exception) { errorInfo = new SearchErrorInfo(-2147220990, exception); goto IL_3A4; } catch (SearchObjectNotFoundException exception2) { errorInfo = new SearchErrorInfo(-2147220990, exception2); goto IL_3A4; } catch (DataSourceOperationException exception3) { errorInfo = new SearchErrorInfo(-2147220990, exception3); goto IL_3A4; } } if (this.searchWorkItemMap.ContainsKey(searchId)) { MailboxSearchWorkItem searchWorkItem = this.searchWorkItemMap[searchId]; if (searchWorkItem.IsCompleted) { goto IL_3A4; } try { searchWorkItem.Abort(userId); } catch (ExportException ex) { MailboxSearchServer.Tracer.TraceError <ExportException>((long)this.GetHashCode(), "MailboxSearchServer.Abort error {0}", ex); errorInfo = new SearchErrorInfo(-2147220991, ex); } catch (DataSourceOperationException ex2) { MailboxSearchServer.Tracer.TraceError <DataSourceOperationException>((long)this.GetHashCode(), "MailboxSearchServer.Abort error {0}", ex2); errorInfo = new SearchErrorInfo(-2147220991, ex2); } lock (this.workItemQueue) { int num = this.workItemQueue.FindIndex((MailboxSearchWorkItem x) => x == searchWorkItem); if (num != -1) { if (num != 0) { this.workItemQueue.RemoveAt(num); this.workItemQueue.Insert(0, searchWorkItem); } int num2 = this.workItemSemaphore.Release(); MailboxSearchServer.Tracer.TraceDebug <int, int>((long)this.GetHashCode(), "MailboxSearch is aborted with Queue Length {0} and semaphore {1}", this.workItemQueue.Count, num2 + 1); SearchEventLogger.Instance.LogDiscoverySearchWorkItemQueueChangedEvent("MovedToFrontOfQueueOnAbort", searchId.SearchName, searchId.MailboxDsName, searchWorkItem.Action.ToString(), searchWorkItem.IsEstimateOnly, this.workItemQueue.Count, this.searchWorkItemMap.Count, this.copySearchesInProgress, num2 + 1); } goto IL_3A4; } } if (this.pendingSearchIdMap.ContainsKey(searchId)) { this.pendingSearchIdMap.Remove(searchId); SearchEventLogger.Instance.LogDiscoverySearchPendingWorkItemsChangedEvent("RemovedFromPendingWorkItemsOnAbort", searchId.SearchName, searchId.MailboxDsName, this.pendingSearchIdMap.Count); } IL_3A4:; } }); if (errorInfo != null && errorInfo.Failed) { MailboxSearchServer.LogErrorInfo("Error occured when trying to abort the search workitem", searchId, errorInfo); } return(errorInfo); }