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);
        }
Beispiel #4
0
        public void CheckDiscoveryBudget(bool isEstimateOnly, MailboxSearchServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (this.MaxMailboxSearches == 0U)
            {
                throw new SearchDisabledException();
            }
            IEnumerable <MailboxDiscoverySearch> all = this.SearchDataProvider.GetAll <MailboxDiscoverySearch>();

            if (all != null)
            {
                uint num  = 0U;
                uint num2 = 0U;
                foreach (MailboxDiscoverySearch mailboxDiscoverySearch in from so in all
                         where so.Status == SearchState.InProgress || so.Status == SearchState.EstimateInProgress
                         select so)
                {
                    SearchStatus searchStatus = null;
                    SearchId     searchId     = new SearchId(this.SearchDataProvider.DistinguishedName, this.SearchDataProvider.ObjectGuid, mailboxDiscoverySearch.Name);
                    server.GetStatus(searchId, out searchStatus);
                    if (searchStatus != null)
                    {
                        if (searchStatus.Status == 0)
                        {
                            num += 1U;
                        }
                        else if (searchStatus.Status == 6)
                        {
                            num2 += 1U;
                        }
                        uint num3 = isEstimateOnly ? num2 : num;
                        if (num3 >= this.MaxMailboxSearches)
                        {
                            throw new SearchOverBudgetException((int)this.MaxMailboxSearches);
                        }
                    }
                }
            }
        }
 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);
         }
     }
 }
 private void QueueSearchForDeletion(SearchId searchId, bool removeLogs, ref SearchErrorInfo errorInfo)
 {
     try
     {
         MailboxSearchWorkItem mailboxSearchWorkItem = new MailboxSearchWorkItem(this, searchId);
         mailboxSearchWorkItem.PreRemove(removeLogs);
         if (!mailboxSearchWorkItem.IsCompleted)
         {
             this.searchWorkItemMap[mailboxSearchWorkItem.SearchId] = mailboxSearchWorkItem;
             lock (this.workItemQueue)
             {
                 this.workItemQueue.Insert(0, mailboxSearchWorkItem);
                 int num = this.queueSemaphore.Release();
                 MailboxSearchServer.Tracer.TraceDebug <SearchId, int, int>((long)this.GetHashCode(), "WorkItem '{0}' is enqueued for remove, Queue length is {1}, Semaphore signals {2}", searchId, this.workItemQueue.Count, num + 1);
                 SearchEventLogger.Instance.LogDiscoverySearchWorkItemQueueChangedEvent("EnqueuedAndAddedToRunningWorkItems", searchId.SearchName, searchId.MailboxDsName, mailboxSearchWorkItem.Action.ToString(), mailboxSearchWorkItem.IsEstimateOnly, this.workItemQueue.Count, this.searchWorkItemMap.Count, this.copySearchesInProgress, num + 1);
             }
         }
     }
     catch (FormatException ex)
     {
         MailboxSearchServer.Tracer.TraceError <FormatException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex);
         errorInfo = new SearchErrorInfo(-2147220988, ex);
     }
     catch (ArgumentException ex2)
     {
         MailboxSearchServer.Tracer.TraceError <ArgumentException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex2);
         errorInfo = new SearchErrorInfo(-2147220988, ex2);
     }
     catch (SearchObjectNotFoundException ex3)
     {
         MailboxSearchServer.Tracer.TraceError <SearchObjectNotFoundException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex3);
         errorInfo = new SearchErrorInfo(-2147220990, ex3);
     }
     catch (ObjectNotFoundException ex4)
     {
         MailboxSearchServer.Tracer.TraceError <ObjectNotFoundException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex4);
         errorInfo = new SearchErrorInfo(-2147220987, ex4);
     }
     catch (UnauthorizedAccessException ex5)
     {
         MailboxSearchServer.Tracer.TraceError <UnauthorizedAccessException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex5);
         errorInfo = new SearchErrorInfo(-2147220982, ex5);
     }
     catch (StoragePermanentException ex6)
     {
         MailboxSearchServer.Tracer.TraceError <StoragePermanentException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex6);
         errorInfo = new SearchErrorInfo(-2147220986, ex6);
     }
     catch (StorageTransientException ex7)
     {
         MailboxSearchServer.Tracer.TraceError <StorageTransientException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex7);
         errorInfo = new SearchErrorInfo(-2147220985, ex7);
     }
     catch (ExportException ex8)
     {
         MailboxSearchServer.Tracer.TraceError <ExportException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex8);
         errorInfo = new SearchErrorInfo(-2147220991, ex8);
     }
     catch (LocalizedException ex9)
     {
         MailboxSearchServer.Tracer.TraceError <LocalizedException>((long)this.GetHashCode(), "MailboxSearchServer.Remove error {0}", ex9);
         errorInfo = new SearchErrorInfo(-2147220991, ex9);
     }
     if (errorInfo != null && errorInfo.Failed)
     {
         MailboxSearchServer.LogErrorInfo("Error occured when trying to queue the search for deletion", searchId, errorInfo);
     }
 }
        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);
        }
 internal static void RestartServer()
 {
     MailboxSearchServer.StopServer();
     MailboxSearchServer.StartServer();
 }
        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);
        }