예제 #1
0
        internal static void CheckDiscoveryBudget(ADUser arbitrationMailbox, IRecipientSession recipientSession)
        {
            uint discoveryMaxConcurrency = SearchUtils.GetDiscoveryMaxConcurrency(recipientSession);

            if (discoveryMaxConcurrency == 0U)
            {
                throw new SearchDisabledException();
            }
            MailboxDataProvider        mailboxDataProvider = new MailboxDataProvider(arbitrationMailbox, recipientSession);
            IEnumerable <SearchObject> enumerable          = mailboxDataProvider.FindPaged <SearchObject>(null, null, false, null, 0);

            if (enumerable != null)
            {
                Dictionary <ADObjectId, ADUser> dictionary  = new Dictionary <ADObjectId, ADUser>();
                Dictionary <ADObjectId, string> dictionary2 = new Dictionary <ADObjectId, string>();
                ADUser       aduser       = null;
                string       text         = null;
                SearchStatus searchStatus = null;
                uint         num          = 0U;
                try
                {
                    foreach (SearchObject searchObject in from so in enumerable
                             where (so.SearchStatus != null && so.SearchStatus.Status == SearchState.InProgress) || (so.SearchStatus != null && so.SearchStatus.Status == SearchState.EstimateInProgress)
                             select so)
                    {
                        if (!dictionary.TryGetValue(searchObject.TargetMailbox, out aduser))
                        {
                            aduser = (ADUser)recipientSession.Read(searchObject.TargetMailbox);
                            if (aduser != null)
                            {
                                dictionary.Add(searchObject.TargetMailbox, aduser);
                            }
                        }
                        if (aduser != null && !dictionary2.TryGetValue(searchObject.TargetMailbox, out text))
                        {
                            text = ExchangePrincipal.FromADUser(recipientSession.SessionSettings, aduser, RemotingOptions.AllowCrossSite).MailboxInfo.Location.ServerFqdn;
                            if (!string.IsNullOrEmpty(text))
                            {
                                dictionary2.Add(searchObject.TargetMailbox, text);
                            }
                        }
                        if (aduser != null && !string.IsNullOrEmpty(text))
                        {
                            SearchId searchId = new SearchId(mailboxDataProvider.ADUser.Id.DistinguishedName, mailboxDataProvider.ADUser.Id.ObjectGuid, searchObject.Id.Guid.ToString());
                            try
                            {
                                using (MailboxSearchClient mailboxSearchClient = new MailboxSearchClient(text))
                                {
                                    searchStatus = mailboxSearchClient.GetStatus(searchId);
                                }
                            }
                            catch (RpcConnectionException arg)
                            {
                                SearchUtils.Tracer.TraceError <RpcConnectionException>(0L, "SearchUtils.CheckDiscoveryBudget error querying for status: {0}", arg);
                                continue;
                            }
                            catch (RpcException arg2)
                            {
                                SearchUtils.Tracer.TraceError <RpcException>(0L, "SearchUtils.CheckDiscoveryBudget error querying for status: {0}", arg2);
                                continue;
                            }
                            catch (SearchServerException arg3)
                            {
                                SearchUtils.Tracer.TraceError <SearchServerException>(0L, "SearchUtils.CheckDiscoveryBudget error querying for status: {0}", arg3);
                                continue;
                            }
                            if (searchStatus != null && (searchStatus.Status == 0 || searchStatus.Status == 6))
                            {
                                num += 1U;
                            }
                        }
                        if (num >= discoveryMaxConcurrency)
                        {
                            throw new SearchOverBudgetException((int)discoveryMaxConcurrency);
                        }
                    }
                }
                finally
                {
                    dictionary.Clear();
                    dictionary2.Clear();
                }
            }
        }
예제 #2
0
 internal static bool DiscoveryEnabled(IRecipientSession recipientSession)
 {
     return(SearchUtils.GetDiscoveryMaxConcurrency(recipientSession) > 0U);
 }