internal IAsyncResult BeginGetMailTipsInBatches(RecipientInfo[] recipientsInfo, RecipientInfo senderInfo, bool doesNeedConfig, AsyncCallback asyncCallback, object asyncCallbackData) { this.primarySmtpAddress = this.userContext.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString(); ClientSecurityContext clientSecurityContext = this.userContext.LogonIdentity.ClientSecurityContext.Clone(); string weekdayDateTimeFormat = this.userContext.UserOptions.GetWeekdayDateTimeFormat(true); MailTipsState mailTipsState = new MailTipsState(recipientsInfo, senderInfo, doesNeedConfig, this.userContext.ExchangePrincipal.LegacyDn, this.primarySmtpAddress, clientSecurityContext, this.userContext.TimeZone, this.userContext.UserCulture, this.userContext.ExchangePrincipal.MailboxInfo.OrganizationId, this.userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN, this.userContext.UserOptions.HideMailTipsByDefault, this.userContext.PendingRequestManager, Query <IEnumerable <MailTips> > .GetCurrentHttpRequestServerName(), weekdayDateTimeFormat); OwaAsyncResult owaAsyncResult = new OwaAsyncResult(asyncCallback, asyncCallbackData); Interlocked.Increment(ref this.concurrentRequestCount); if (3 >= this.concurrentRequestCount) { ExTraceGlobals.CoreCallTracer.TraceError <int, string>((long)this.GetHashCode(), "MailTipsNotificationHandler.BeginGetMailTipsInBatches, serving concurrent request {0} for {1}", this.concurrentRequestCount, this.primarySmtpAddress); ThreadPool.QueueUserWorkItem(new WaitCallback(this.GetMailTipsWorker), mailTipsState); return(owaAsyncResult); } IAsyncResult result; try { ExTraceGlobals.CoreCallTracer.TraceError <int>((long)this.GetHashCode(), "MailTipsNotificationHandler.BeginGetMailTipsInBatches, maximum concurrent request limit {0} has been reached", 3); MailTipsNotificationHandler.PopulateException(mailTipsState, new OwaMaxConcurrentRequestsExceededException("Maximum MailTips concurrent requests exceeded"), this.GetHashCode()); this.mailTipsNotifier.AddToPayload(mailTipsState); this.mailTipsNotifier.PickupData(); result = owaAsyncResult; } finally { Interlocked.Decrement(ref this.concurrentRequestCount); } return(result); }
private IEnumerable <MailTips> GetMailTipsInBatches(MailTipsState mailTipsState) { Exception ex = null; try { using (IStandardBudget standardBudget = StandardBudget.Acquire(mailTipsState.ClientSecurityContext.UserSid, BudgetType.Owa, ADSessionSettings.FromRootOrgScopeSet())) { string callerInfo = "MailTipsNotificationHandler.GetMailTipsInBatches"; standardBudget.CheckOverBudget(); standardBudget.StartConnection(callerInfo); standardBudget.StartLocal(callerInfo, default(TimeSpan)); mailTipsState.Budget = standardBudget; ClientContext clientContext = ClientContext.Create(mailTipsState.ClientSecurityContext, mailTipsState.Budget, mailTipsState.LogonUserTimeZone, mailTipsState.LogonUserCulture); ((InternalClientContext)clientContext).QueryBaseDN = mailTipsState.QueryBaseDn; ExTraceGlobals.CoreCallTracer.TraceDebug <ADObjectId>((long)this.GetHashCode(), "QueryBaseDN set to {0}", mailTipsState.QueryBaseDn); ProxyAddress sendingAsProxyAddress = this.GetSendingAsProxyAddress(mailTipsState); mailTipsState.CachedOrganizationConfiguration = CachedOrganizationConfiguration.GetInstance(mailTipsState.LogonUserOrgId, CachedOrganizationConfiguration.ConfigurationTypes.All); ExTraceGlobals.CoreCallTracer.TraceDebug <OrganizationId>((long)this.GetHashCode(), "Organization ID = {0}", mailTipsState.LogonUserOrgId); try { int num = 0; do { ProxyAddress[] nextBatch = MailTipsNotificationHandler.GetNextBatch(mailTipsState.RecipientsInfo, ref num); mailTipsState.GetMailTipsQuery = new GetMailTipsQuery(this.GetHashCode(), clientContext, sendingAsProxyAddress, mailTipsState.CachedOrganizationConfiguration, nextBatch, MailTipTypes.OutOfOfficeMessage | MailTipTypes.MailboxFullStatus | MailTipTypes.CustomMailTip | MailTipTypes.ExternalMemberCount | MailTipTypes.TotalMemberCount | MailTipTypes.DeliveryRestriction | MailTipTypes.ModerationStatus, mailTipsState.LogonUserCulture.LCID, mailTipsState.Budget, null); mailTipsState.GetMailTipsQuery.ServerName = mailTipsState.ServerName; mailTipsState.RequestLogger = mailTipsState.GetMailTipsQuery.RequestLogger; IEnumerable <MailTips> collection = mailTipsState.GetMailTipsQuery.Execute(); mailTipsState.MailTipsResult.AddRange(collection); }while (num < mailTipsState.RecipientsInfo.Length); } catch (UserWithoutFederatedProxyAddressException ex2) { ex = ex2; } catch (InvalidFederatedOrganizationIdException ex3) { ex = ex3; } } } catch (OverBudgetException ex4) { ex = ex4; } catch (ObjectDisposedException ex5) { ex = ex5; } catch (OwaInvalidOperationException ex6) { ex = ex6; } finally { if (ex != null) { MailTipsNotificationHandler.PopulateException(mailTipsState, ex, this.GetHashCode()); } } return(mailTipsState.MailTipsResult); }