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 void GetMailTipsWorker(object state)
        {
            MailTipsState mailTipsState = null;

            try
            {
                mailTipsState = (MailTipsState)state;
                ExTraceGlobals.CoreCallTracer.TraceDebug((long)this.GetHashCode(), "MailTipsNotificationHandler.GetMailTipsWorker");
                this.GetMailTipsInBatches(mailTipsState);
                this.mailTipsNotifier.AddToPayload(mailTipsState);
                this.mailTipsNotifier.PickupData();
            }
            catch (Exception ex)
            {
                ExTraceGlobals.CoreTracer.TraceError <Exception>((long)this.GetHashCode(), "Generic exception caught during GetMailTipsWorker call: {0}", ex);
                if (Globals.SendWatsonReports)
                {
                    ExTraceGlobals.CoreTracer.TraceError((long)this.GetHashCode(), "Sending watson report.");
                    ExWatson.AddExtraData(this.GetExtraWatsonData(mailTipsState));
                    ExWatson.SendReport(ex, ReportOptions.None, null);
                }
            }
            finally
            {
                Interlocked.Decrement(ref this.concurrentRequestCount);
                ExTraceGlobals.CoreCallTracer.TraceError <string, int>((long)this.GetHashCode(), "MailTipsNotificationHandler.GetMailTipsWorker, {0} concurrent requests count decremented to {1}", this.primarySmtpAddress, this.concurrentRequestCount);
            }
        }
        private string GetExtraWatsonData(MailTipsState mailTipsState)
        {
            int num = 0;

            if (this.userContext.Breadcrumbs != null)
            {
                num = this.userContext.Breadcrumbs.Count * 128;
            }
            int num2 = 0;

            if (mailTipsState != null)
            {
                num2 = mailTipsState.GetEstimatedStringLength();
            }
            StringBuilder stringBuilder = new StringBuilder(40 + num + num2);

            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "OWAVersion: {0}, ", new object[]
            {
                Globals.ApplicationVersion
            });
            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "MailTipsState: {0}, ", new object[]
            {
                mailTipsState
            });
            stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "BreadCrumbs: {0}", new object[]
            {
                this.userContext.DumpBreadcrumbs()
            });
            return(stringBuilder.ToString());
        }
Example #4
0
 // Token: 0x06000BED RID: 3053 RVA: 0x00052DC4 File Offset: 0x00050FC4
 internal static void SerializeMailTips(MailTips mailTips, MailTipsState mailTipsState, StringBuilder stringBuilder)
 {
     stringBuilder.Append("'");
     stringBuilder.Append(Utilities.JavascriptEncode(mailTips.EmailAddress.Address));
     stringBuilder.Append("' : ");
     stringBuilder.Append("{");
     stringBuilder.Append("'iSize' : ");
     stringBuilder.Append(mailTips.TotalMemberCount);
     stringBuilder.Append(", ");
     stringBuilder.Append("'iExternalSize' : ");
     stringBuilder.Append(mailTips.ExternalMemberCount);
     if (!string.IsNullOrEmpty(mailTips.CustomMailTip))
     {
         stringBuilder.Append(", ");
         stringBuilder.Append("'sCustomTip' : '");
         stringBuilder.Append(Utilities.JavascriptEncode(Utilities.RemoveHtmlComments(mailTips.CustomMailTip)));
         stringBuilder.Append("'");
     }
     if (!string.IsNullOrEmpty(mailTips.OutOfOfficeMessage))
     {
         stringBuilder.Append(", ");
         stringBuilder.Append("'sAutoReplyMessage' : '");
         stringBuilder.Append(Utilities.JavascriptEncode(Utilities.RemoveHtmlComments(mailTips.OutOfOfficeMessage)));
         stringBuilder.Append("'");
     }
     if (mailTips.OutOfOfficeDuration != null && DateTime.MinValue != mailTips.OutOfOfficeDuration.EndTime)
     {
         stringBuilder.Append(", ");
         stringBuilder.Append("'sAutoReplyEndDate' : '");
         ExDateTime exDateTime = new ExDateTime(mailTipsState.LogonUserTimeZone, mailTips.OutOfOfficeDuration.EndTime);
         stringBuilder.Append(Utilities.JavascriptEncode(exDateTime.ToString(mailTipsState.WeekdayDateTimeFormat, mailTipsState.LogonUserCulture)));
         stringBuilder.Append("'");
     }
     if (mailTips.IsModerated)
     {
         stringBuilder.Append(", ");
         stringBuilder.Append("'fModerated' : 1");
     }
     if (mailTips.MailboxFull)
     {
         stringBuilder.Append(", ");
         stringBuilder.Append("'fFull' : 1");
     }
     if (null != mailTipsState.SendingAs && !string.IsNullOrEmpty(mailTipsState.SendingAs.AddressString))
     {
         stringBuilder.Append(", ");
         stringBuilder.Append("'oRestricted' : {'");
         stringBuilder.Append(Utilities.JavascriptEncode(mailTipsState.SendingAs.AddressString));
         stringBuilder.Append("' : ");
         stringBuilder.Append(mailTips.DeliveryRestricted ? "1}" : "0}");
     }
     if (mailTips.Exception != null)
     {
         stringBuilder.Append(", ");
         stringBuilder.Append("'fErrored' : 1");
     }
     stringBuilder.Append("}");
 }
Example #5
0
 // Token: 0x06000BEA RID: 3050 RVA: 0x00052CA8 File Offset: 0x00050EA8
 public void AddToPayload(MailTipsState mailTipsState)
 {
     lock (this.payload)
     {
         if (256 == this.payload.Count)
         {
             this.payload.Dequeue();
         }
         this.payload.Enqueue(mailTipsState);
     }
 }
        private static void PopulateException(MailTipsState mailTipsState, Exception exception, int hashCode)
        {
            ExTraceGlobals.CoreCallTracer.TraceError <Exception>((long)hashCode, "MailTipsNotificationHandler.PopulateException: {0}", exception);
            List <MailTips> mailTipsResult = mailTipsState.MailTipsResult;

            RecipientInfo[] recipientsInfo = mailTipsState.RecipientsInfo;
            for (int i = mailTipsResult.Count; i < recipientsInfo.Length; i++)
            {
                mailTipsResult.Add(new MailTips(new EmailAddress(recipientsInfo[i].DisplayName, recipientsInfo[i].RoutingAddress, recipientsInfo[i].RoutingType), exception));
            }
            if (mailTipsState.RequestLogger == null)
            {
                mailTipsState.RequestLogger = new RequestLogger();
            }
            mailTipsState.RequestLogger.AppendToLog <Type>("MailTipsException", exception.GetType());
        }
        private ProxyAddress GetSendingAsProxyAddress(MailTipsState mailTipsState)
        {
            ProxyAddress proxyAddress;

            if (mailTipsState.SenderInfo == null)
            {
                if (string.IsNullOrEmpty(mailTipsState.LogonUserLegDn))
                {
                    proxyAddress = ProxyAddress.Parse(ProxyAddressPrefix.Smtp.PrimaryPrefix, mailTipsState.LogonUserPrimarySmtpAddress ?? string.Empty);
                }
                else
                {
                    proxyAddress = ProxyAddress.Parse(ProxyAddressPrefix.LegacyDN.PrimaryPrefix, mailTipsState.LogonUserLegDn);
                }
            }
            else
            {
                proxyAddress = mailTipsState.SenderInfo.ToProxyAddress();
            }
            mailTipsState.SendingAs = proxyAddress;
            return(proxyAddress);
        }
        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);
        }
Example #9
0
        // Token: 0x06000BE9 RID: 3049 RVA: 0x000529CC File Offset: 0x00050BCC
        public string ReadDataAndResetState()
        {
            string result;

            lock (this.payload)
            {
                if (0 < this.payload.Count)
                {
                    ExTraceGlobals.CoreCallTracer.TraceDebug <int>((long)this.GetHashCode(), "MailTipsPendingRequestNotifier.ReadDataAndResetState. Processing {0} requests.", this.payload.Count);
                    int           capacity      = 512 * this.payload.Count;
                    StringBuilder stringBuilder = new StringBuilder(capacity);
                    for (int i = 1; i <= this.payload.Count; i++)
                    {
                        MailTipsState mailTipsState = this.payload.Dequeue();
                        ExTraceGlobals.CoreCallTracer.TraceDebug <int, string, ProxyAddress>((long)this.GetHashCode(), "MailTipsPendingRequestNotifier.ReadDataAndResetState. Request: {0}, Requester: {1}, Sending as: {2}.", i, mailTipsState.LogonUserPrimarySmtpAddress, mailTipsState.SendingAs);
                        stringBuilder.Append("processMailTipsResponse({");
                        bool flag2 = true;
                        foreach (MailTips mailTips in mailTipsState.MailTipsResult)
                        {
                            if (!flag2)
                            {
                                stringBuilder.Append(",");
                            }
                            flag2 = false;
                            MailTipsPendingRequestNotifier.SerializeMailTips(mailTips, mailTipsState, stringBuilder);
                        }
                        if (mailTipsState.Budget != null)
                        {
                            mailTipsState.Budget.Dispose();
                        }
                        stringBuilder.Append("}");
                        stringBuilder.Append(",{");
                        stringBuilder.Append("'fHideByDefault' : ");
                        stringBuilder.Append(mailTipsState.ShouldHideByDefault ? 1 : 0);
                        if (mailTipsState.DoesNeedConfig)
                        {
                            Organization configuration = mailTipsState.CachedOrganizationConfiguration.OrganizationConfiguration.Configuration;
                            stringBuilder.Append(", 'fEnabled' : ");
                            stringBuilder.Append(configuration.MailTipsAllTipsEnabled ? 1 : 0);
                            stringBuilder.Append(", 'fMailboxEnabled' : ");
                            stringBuilder.Append(configuration.MailTipsMailboxSourcedTipsEnabled ? 1 : 0);
                            stringBuilder.Append(", 'fGroupMetricsEnabled' : ");
                            stringBuilder.Append(configuration.MailTipsGroupMetricsEnabled ? 1 : 0);
                            stringBuilder.Append(", 'fExternalEnabled' : ");
                            stringBuilder.Append(configuration.MailTipsExternalRecipientsTipsEnabled ? 1 : 0);
                            stringBuilder.Append(", 'iLargeAudienceThreshold' : ");
                            stringBuilder.Append(configuration.MailTipsLargeAudienceThreshold);
                        }
                        stringBuilder.Append("}");
                        stringBuilder.Append(");");
                        if (mailTipsState.GetMailTipsQuery != null)
                        {
                            if (mailTipsState.RequestLogger == null)
                            {
                                mailTipsState.RequestLogger = new RequestLogger();
                            }
                        }
                        else
                        {
                            ExTraceGlobals.CoreCallTracer.TraceDebug((long)this.GetHashCode(), "MailTipsPendingRequestNotifier.ReadDataAndResetState: GetMailTipsQuery was null.");
                        }
                        if (mailTipsState.PendingRequestManager.ChunkedHttpResponse != null)
                        {
                            mailTipsState.PendingRequestManager.ChunkedHttpResponse.Log(mailTipsState.RequestLogger);
                        }
                    }
                    this.isPickupInProgress = false;
                    result = stringBuilder.ToString();
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }