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);
        }
        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);
        }