Esempio n. 1
0
 private void ProcessResponseMessages(int traceId, QueryList queryList, GetMailTipsResponseMessageType response)
 {
     if (response.ResponseMessages == null)
     {
         Application.ProxyWebRequestTracer.TraceError((long)traceId, "{0}: Proxy web request returned NULL GetMailTipsResponseMessageType.ResponseMessages", new object[]
         {
             TraceContext.Get()
         });
         queryList.SetResultInAllQueries(new MailTipsQueryResult(new NoEwsResponseException()));
         return;
     }
     for (int i = 0; i < response.ResponseMessages.Length; i++)
     {
         MailTipsResponseMessageType mailTipsResponseMessageType = response.ResponseMessages[i];
         BaseQuery[] array = queryList.FindByEmailAddress(queryList[i].Email.Address);
         foreach (MailTipsQuery mailTipsQuery in array)
         {
             if (mailTipsResponseMessageType == null)
             {
                 Application.ProxyWebRequestTracer.TraceError <object, Microsoft.Exchange.InfoWorker.Common.Availability.EmailAddress>((long)traceId, "{0}: Proxy web request returned NULL MailTipsResponseMessageType for mailbox {1}.", TraceContext.Get(), queryList[i].Email);
                 mailTipsQuery.SetResultOnFirstCall(new MailTipsQueryResult(new NoEwsResponseException()));
             }
             else if (mailTipsResponseMessageType.ResponseCode != ResponseCodeType.NoError)
             {
                 Application.ProxyWebRequestTracer.TraceError <object, Microsoft.Exchange.InfoWorker.Common.Availability.EmailAddress, ResponseCodeType>((long)traceId, "{0}: Proxy web request returned error MailTipsResponseMessageType for mailbox {1}. Error coee is {2}.", TraceContext.Get(), queryList[i].Email, mailTipsResponseMessageType.ResponseCode);
                 mailTipsQuery.SetResultOnFirstCall(new MailTipsQueryResult(new ErrorEwsResponseException(mailTipsResponseMessageType.ResponseCode)));
             }
             else
             {
                 MailTips mailTips = mailTipsResponseMessageType.MailTips;
                 if (mailTips == null)
                 {
                     Application.ProxyWebRequestTracer.TraceDebug <object, Microsoft.Exchange.InfoWorker.Common.Availability.EmailAddress>((long)traceId, "{0}: Proxy web request returned NULL MailTips for mailbox {1}.", TraceContext.Get(), queryList[i].Email);
                     mailTipsQuery.SetResultOnFirstCall(new MailTipsQueryResult(new NoMailTipsInEwsResponseMessageException()));
                 }
                 else
                 {
                     MailTips            mailTips2         = MailTipsApplication.ParseWebServiceMailTips(mailTips);
                     MailTipsQueryResult resultOnFirstCall = new MailTipsQueryResult(mailTips2);
                     mailTipsQuery.SetResultOnFirstCall(resultOnFirstCall);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        internal override BaseQueryResult GetData(BaseQuery query)
        {
            Stopwatch     stopwatch     = Stopwatch.StartNew();
            MailTipsQuery mailTipsQuery = (MailTipsQuery)query;

            mailTipsQuery.LatencyTracker = new Dictionary <string, long>(4);
            EmailAddress email    = query.Email;
            MailTips     mailTips = new MailTips(query.RecipientData);

            mailTips.Permission = mailTipsQuery.Permission;
            mailTips.MarkAsPending(MailTipTypes.OutOfOfficeMessage | MailTipTypes.MailboxFullStatus);
            int traceId = this.clientContext.GetHashCode();

            MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: Getting mailbox MailTips...", TraceContext.Get(), mailTips.EmailAddress);
            MailTipsQueryResult mailTipsQueryResult = null;
            DateTime            utcNow = DateTime.UtcNow;

            if (utcNow > this.deadline)
            {
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, TimeSpan>((long)traceId, "{0} / {1}: Timeout expired before opening mailbox session {2}", TraceContext.Get(), mailTips.EmailAddress, utcNow - this.deadline);
                return(this.HandleException(email, stopwatch, mailTipsQuery, new TimeoutExpiredException("Opening-Mailbox-Session")));
            }
            MailboxSession session            = null;
            bool           outOfOfficeSuccess = false;
            bool           mailboxFullSuccess = false;

            try
            {
                mailTipsQueryResult = this.RunUnderExceptionHandler(email, stopwatch, mailTipsQuery, delegate
                {
                    Stopwatch stopwatch = Stopwatch.StartNew();
                    ExchangePrincipal exchangePrincipal = mailTipsQuery.ExchangePrincipal;
                    MailboxAccessInfo accessInfo        = new MailboxAccessInfo(new WindowsPrincipal(WindowsIdentity.GetCurrent()));
                    session = MailboxSession.ConfigurableOpen(exchangePrincipal, accessInfo, CultureInfo.InvariantCulture, "Client=MSExchangeRPC;Action=MailTips", LogonType.Admin, MailTipsLocalQuery.MailboxPropertyDefinitions, MailboxSession.InitializationFlags.DefaultFolders | MailboxSession.InitializationFlags.SuppressFolderIdPrefetch | MailboxSession.InitializationFlags.DeferDefaultFolderIdInitialization | MailboxSession.InitializationFlags.IgnoreForcedFolderInit, MailTipsLocalQuery.MailboxDefaultFolderTypes);
                    session.AccountingObject = this.callerBudget;
                    mailTipsQuery.LatencyTracker["OpenSession"] = stopwatch.ElapsedMilliseconds;
                    stopwatch.Stop();
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, long>((long)traceId, "{0} / {1}: MailboxSession opened in {2} milliseconds", TraceContext.Get(), mailTips.EmailAddress, stopwatch.ElapsedMilliseconds);
                    return(null);
                });
                if (mailTipsQueryResult != null)
                {
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: Unable to open mailbox session", TraceContext.Get(), mailTips.EmailAddress);
                    return(mailTipsQueryResult);
                }
                utcNow = DateTime.UtcNow;
                if (utcNow > this.deadline)
                {
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, TimeSpan>((long)traceId, "{0} / {1}: Timeout expired before getting mailbox-full {2}", TraceContext.Get(), mailTips.EmailAddress, utcNow - this.deadline);
                    return(this.HandleException(email, stopwatch, mailTipsQuery, new TimeoutExpiredException("Getting-MailboxFull")));
                }
                mailTipsQueryResult = this.RunUnderExceptionHandler(email, stopwatch, mailTipsQuery, delegate
                {
                    mailboxFullSuccess = this.GetMailboxFullStatus(traceId, session, mailTips);
                    mailTipsQuery.LatencyTracker["GetMailboxFull"] = stopwatch.ElapsedMilliseconds;
                    return(null);
                });
                if (mailTipsQueryResult != null)
                {
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: Unable to get mailbox-full, but will try to get OOF.", TraceContext.Get(), mailTips.EmailAddress);
                }
                utcNow = DateTime.UtcNow;
                if (utcNow > this.deadline)
                {
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, TimeSpan>((long)traceId, "{0} / {1}: Timeout expired before getting out-of-office message {2}", TraceContext.Get(), mailTips.EmailAddress, utcNow - this.deadline);
                    return(this.HandleException(email, stopwatch, mailTipsQuery, new TimeoutExpiredException("Getting-OutOfOffice")));
                }
                mailTipsQueryResult = this.RunUnderExceptionHandler(email, stopwatch, mailTipsQuery, delegate
                {
                    outOfOfficeSuccess = this.GetOutOfOfficeMessage(traceId, session, mailTips);
                    mailTipsQuery.LatencyTracker["GetOOF"] = stopwatch.ElapsedMilliseconds;
                    return(null);
                });
                if (mailTipsQueryResult != null)
                {
                    MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: Unable to get OOF, returning an error.", TraceContext.Get(), mailTips.EmailAddress);
                    return(mailTipsQueryResult);
                }
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
                mailTipsQuery.LatencyTracker["DisposeSession"] = stopwatch.ElapsedMilliseconds;
                if (mailTipsQueryResult != null)
                {
                    mailTips.Exception = mailTipsQueryResult.ExceptionInfo;
                }
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, bool>((long)traceId, "{0} / {1}: OutOfOffice message success: {2}", TraceContext.Get(), mailTips.EmailAddress, outOfOfficeSuccess);
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, bool>((long)traceId, "{0} / {1}: MailboxFull success: {2}", TraceContext.Get(), mailTips.EmailAddress, mailboxFullSuccess);
                if (!outOfOfficeSuccess)
                {
                    mailTips.MarkAsUnavailable(MailTipTypes.OutOfOfficeMessage);
                }
                if (!mailboxFullSuccess)
                {
                    mailTips.MarkAsUnavailable(MailTipTypes.MailboxFullStatus);
                }
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress>((long)traceId, "{0} / {1}: Returning MailTipsQueryResult", TraceContext.Get(), mailTips.EmailAddress);
                mailTipsQueryResult = new MailTipsQueryResult(mailTips);
                stopwatch.Stop();
                MailTipsLocalQuery.GetMailTipsTracer.TraceDebug <object, EmailAddress, long>((long)traceId, "{0} / {1}: LocalQuery took {2} milliseconds", TraceContext.Get(), mailTips.EmailAddress, stopwatch.ElapsedMilliseconds);
            }
            return(mailTipsQueryResult);
        }
Esempio n. 3
0
 private MailTipsQuery(RecipientData recipientData, MailTipsQueryResult result) : base(recipientData, result)
 {
 }