private void LogEvent(EmailAddress emailAddress, Stopwatch stopwatch, MailTipsQuery mailTipsQuery, Exception exception) { StringBuilder stringBuilder = new StringBuilder(mailTipsQuery.LatencyTracker.Count * 20 + 20); foreach (string text in mailTipsQuery.LatencyTracker.Keys) { stringBuilder.Append(text); stringBuilder.Append(":"); stringBuilder.Append(mailTipsQuery.LatencyTracker[text]); stringBuilder.Append(","); } stringBuilder.Append(" total:"); stringBuilder.Append(stopwatch.ElapsedMilliseconds); MailTips.Logger.LogEvent(InfoWorkerEventLogConstants.Tuple_MailTipsMailboxQueryFailed, exception.GetType().FullName, new object[] { Globals.ProcessId, emailAddress, stringBuilder, exception }); }
private MailTipsQueryResult HandleException(EmailAddress emailAddress, Stopwatch stopwatch, MailTipsQuery mailTipsQuery, LocalizedException exception) { MailTipsLocalQuery.GetMailTipsTracer.TraceError <object, EmailAddress, LocalizedException>((long)this.GetHashCode(), "{0} / {1}: Exception getting MailTips: {2}", TraceContext.Get(), emailAddress, exception); this.LogEvent(emailAddress, stopwatch, mailTipsQuery, exception); MailTipsPerfCounters.IntraSiteMailTipsFailuresPerSecond.Increment(); return(new MailTipsQueryResult(exception)); }
private MailTipsQueryResult HandleConnectionException(EmailAddress emailAddress, Stopwatch stopwatch, MailTipsQuery mailTipsQuery, Exception exception) { MailTipsLocalQuery.GetMailTipsTracer.TraceError <object, EmailAddress, Exception>((long)this.GetHashCode(), "{0} / {1}: Database connection failed for mailbox, with exception {2}.", TraceContext.Get(), emailAddress, exception); this.LogEvent(emailAddress, stopwatch, mailTipsQuery, exception); MailTipsPerfCounters.IntraSiteMailTipsFailuresPerSecond.Increment(); return(new MailTipsQueryResult(new MailboxLogonFailedException(exception))); }
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); }
private MailTipsQueryResult RunUnderExceptionHandler(EmailAddress emailAddress, Stopwatch stopwatch, MailTipsQuery mailTipsQuery, MailTipsLocalQuery.MailTipsLocalQueryDelegate method) { MailTipsQueryResult result; try { method(); result = null; } catch (ConnectionFailedPermanentException exception) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception); } catch (ObjectNotFoundException exception2) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception2); } catch (ConnectionFailedTransientException exception3) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception3); } catch (AccountDisabledException exception4) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception4); } catch (VirusScanInProgressException innerException) { LocalizedString localizedString = Strings.descVirusScanInProgress(emailAddress.ToString()); LocalizedException exception5 = new LocalizedException(localizedString, innerException); result = this.HandleException(emailAddress, stopwatch, mailTipsQuery, exception5); } catch (VirusDetectedException innerException2) { LocalizedString localizedString2 = Strings.descVirusDetected(emailAddress.ToString()); LocalizedException exception6 = new LocalizedException(localizedString2, innerException2); result = this.HandleException(emailAddress, stopwatch, mailTipsQuery, exception6); } catch (AuthzException innerException3) { result = this.HandleException(emailAddress, stopwatch, mailTipsQuery, new Win32InteropException(innerException3)); } catch (StoragePermanentException exception7) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception7); } catch (StorageTransientException exception8) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception8); } catch (ADTransientException exception9) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception9); } catch (ADExternalException exception10) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception10); } catch (TransientException exception11) { result = this.HandleConnectionException(emailAddress, stopwatch, mailTipsQuery, exception11); } return(result); }
public override BaseQuery CreateFromIndividual(RecipientData recipientData, LocalizedException exception) { return(MailTipsQuery.CreateFromIndividual(recipientData, exception)); }
public override BaseQuery CreateFromIndividual(RecipientData recipientData) { return(MailTipsQuery.CreateFromIndividual(recipientData)); }