示例#1
0
        internal MapiTransactionOutcome TimedExecute(int timeOutMilliseconds)
        {
            Thread thread = new Thread(new ParameterizedThreadStart(this.Execute));
            MapiTransactionOutcome mapiTransactionOutcome = new MapiTransactionOutcome(this.targetServer, this.database, this.adRecipient);

            this.transactionTimeouted = false;
            try
            {
                thread.Start(mapiTransactionOutcome);
                if (!thread.Join(timeOutMilliseconds))
                {
                    lock (this.timeoutOperationLock)
                    {
                        this.transactionTimeouted = true;
                    }
                    if (!thread.Join(250))
                    {
                        thread.Abort();
                    }
                }
                if (mapiTransactionOutcome.Latency.TotalMilliseconds > (double)timeOutMilliseconds || this.transactionTimeouted)
                {
                    mapiTransactionOutcome.Update(MapiTransactionResultEnum.Failure, TimeSpan.Zero, Strings.MapiTransactionErrorMsgTimeout((double)timeOutMilliseconds / 1000.0), null, null, this.isDatabaseCopyActive);
                }
            }
            catch (ThreadAbortException)
            {
                mapiTransactionOutcome.Update(MapiTransactionResultEnum.Failure, TimeSpan.Zero, Strings.MapiTransactionAbortedMsg, null, null, this.isDatabaseCopyActive);
            }
            return(mapiTransactionOutcome);
        }
示例#2
0
        private void Execute(MapiTransactionOutcome transactionOutcome)
        {
            ExchangePrincipal         mailboxOwner = null;
            MapiTransactionResultEnum resultEnum   = MapiTransactionResultEnum.Failure;
            string           error            = string.Empty;
            TimeSpan         latency          = TimeSpan.Zero;
            Guid?            mailboxGuid      = null;
            MailboxMiscFlags?mailboxMiscFlags = null;

            try
            {
                if (this.adRecipient == null)
                {
                    try
                    {
                        string errorStringBasedOnDatabaseCopyState = this.GetErrorStringBasedOnDatabaseCopyState();
                        if (!string.IsNullOrWhiteSpace(errorStringBasedOnDatabaseCopyState))
                        {
                            error = errorStringBasedOnDatabaseCopyState;
                        }
                        else
                        {
                            error = Strings.MapiTransactionErrorMsgNoMailbox;
                        }
                    }
                    catch (MapiPermanentException ex)
                    {
                        error = Strings.MapiTransactionDiagnosticStoreStateCheckFailure(this.ShortErrorMsgFromException(ex));
                        this.diagnosticContext = ex.DiagCtx.ToCompactString();
                    }
                    catch (MapiRetryableException ex2)
                    {
                        error = Strings.MapiTransactionDiagnosticStoreStateCheckFailure(this.ShortErrorMsgFromException(ex2));
                        this.diagnosticContext = ex2.DiagCtx.ToCompactString();
                    }
                    transactionOutcome.Update(MapiTransactionResultEnum.Failure, TimeSpan.Zero, error, mailboxGuid, mailboxMiscFlags, this.isDatabaseCopyActive);
                }
                else
                {
                    try
                    {
                        if (this.adRecipient is ADSystemMailbox)
                        {
                            mailboxOwner = ExchangePrincipal.FromADSystemMailbox(ADSessionSettings.FromRootOrgScopeSet(), (ADSystemMailbox)this.adRecipient, this.targetServer);
                        }
                        else
                        {
                            ADSessionSettings adSessionSettings = this.adRecipient.OrganizationId.ToADSessionSettings();
                            mailboxOwner = ExchangePrincipal.FromMailboxData(adSessionSettings, this.adRecipient.DisplayName, this.targetServer.Fqdn, this.targetServer.ExchangeLegacyDN, this.adRecipient.LegacyExchangeDN, this.isArchiveMailbox ? ((ADUser)this.adRecipient).ArchiveGuid : ((ADUser)this.adRecipient).ExchangeGuid, this.database.Guid, this.adRecipient.PrimarySmtpAddress.ToString(), this.adRecipient.Id, new List <CultureInfo>(), Array <Guid> .Empty, RecipientType.Invalid, RemotingOptions.AllowCrossSite);
                        }
                    }
                    catch (ObjectNotFoundException ex3)
                    {
                        transactionOutcome.Update(MapiTransactionResultEnum.Failure, TimeSpan.Zero, this.ShortErrorMsgFromException(ex3), mailboxGuid, mailboxMiscFlags, this.isDatabaseCopyActive);
                        this.diagnosticContext = this.GetDiagnosticContext(ex3);
                        return;
                    }
                    MailboxSession mailboxSession = null;
                    Stopwatch      stopwatch      = Stopwatch.StartNew();
                    try
                    {
                        if (!this.transactionTimeouted)
                        {
                            try
                            {
                                mailboxSession = MailboxSession.OpenAsAdmin(mailboxOwner, CultureInfo.InvariantCulture, "Client=StoreActiveMonitoring;Action=Test-MapiConnectivity", false, false, !this.isDatabaseCopyActive);
                            }
                            catch (StorageTransientException exception)
                            {
                                error = this.DiagnoseMapiOperationException(exception, out resultEnum);
                                return;
                            }
                            catch (StoragePermanentException exception2)
                            {
                                error = this.DiagnoseMapiOperationException(exception2, out resultEnum);
                                return;
                            }
                            if (!this.transactionTimeouted)
                            {
                                using (Folder.Bind(mailboxSession, DefaultFolderType.Inbox, new PropertyDefinition[]
                                {
                                    FolderSchema.ItemCount
                                }))
                                {
                                    resultEnum = MapiTransactionResultEnum.Success;
                                    error      = string.Empty;
                                }
                                mailboxSession.Mailbox.Load(new PropertyDefinition[]
                                {
                                    MailboxSchema.MailboxGuid,
                                    MailboxSchema.MailboxMiscFlags
                                });
                                byte[] array = mailboxSession.Mailbox.TryGetProperty(MailboxSchema.MailboxGuid) as byte[];
                                object obj   = mailboxSession.Mailbox.TryGetProperty(MailboxSchema.MailboxMiscFlags);
                                if (array != null && array.Length == 16)
                                {
                                    mailboxGuid = new Guid?(new Guid(array));
                                }
                                if (obj is int)
                                {
                                    mailboxMiscFlags = new MailboxMiscFlags?((MailboxMiscFlags)obj);
                                }
                                latency = stopwatch.Elapsed;
                            }
                        }
                    }
                    finally
                    {
                        if (mailboxSession != null)
                        {
                            mailboxSession.Dispose();
                        }
                    }
                }
            }
            catch (Exception exception3)
            {
                error = this.ShortErrorMsgFromException(exception3);
            }
            finally
            {
                lock (this.timeoutOperationLock)
                {
                    if (!this.transactionTimeouted)
                    {
                        transactionOutcome.Update(resultEnum, latency, error, mailboxGuid, mailboxMiscFlags, this.isDatabaseCopyActive);
                    }
                }
            }
        }
示例#3
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     try
     {
         List <MapiTransactionOutcome> list  = new List <MapiTransactionOutcome>();
         List <MapiTransactionOutcome> list2 = new List <MapiTransactionOutcome>();
         List <MapiTransactionOutcome> list3 = new List <MapiTransactionOutcome>();
         List <MapiTransactionOutcome> list4 = new List <MapiTransactionOutcome>();
         int num = this.PerConnectionTimeout * 1000;
         if (this.transactionTargets.Count > 0 && TestMapiConnectivity.needExtraTransaction)
         {
             this.transactionTargets[0].TimedExecute((num < 10000) ? 10000 : num);
             TestMapiConnectivity.needExtraTransaction = false;
         }
         Stopwatch stopwatch = Stopwatch.StartNew();
         foreach (MapiTransaction mapiTransaction in this.transactionTargets)
         {
             MapiTransactionOutcome mapiTransactionOutcome;
             if (stopwatch.Elapsed.TotalSeconds < (double)this.AllConnectionsTimeout)
             {
                 mapiTransactionOutcome = mapiTransaction.TimedExecute(num);
             }
             else
             {
                 mapiTransactionOutcome = new MapiTransactionOutcome(mapiTransaction.TargetServer, mapiTransaction.Database, mapiTransaction.ADRecipient);
                 mapiTransactionOutcome.Update(MapiTransactionResultEnum.Failure, TimeSpan.Zero, Strings.MapiTranscationErrorMsgNoTimeLeft(this.AllConnectionsTimeout), null, null, mapiTransaction.Database.Server.ObjectGuid == mapiTransaction.TargetServer.Guid);
             }
             base.WriteObject(mapiTransactionOutcome);
             string performanceInstance = this.wasTargetMailboxSpecified ? mapiTransactionOutcome.LongTargetString() : mapiTransactionOutcome.ShortTargetString();
             double performanceValue;
             if (mapiTransactionOutcome.Result.Value == MapiTransactionResultEnum.Success)
             {
                 performanceValue = mapiTransactionOutcome.Latency.TotalMilliseconds;
             }
             else if (mapiTransactionOutcome.Result.Value == MapiTransactionResultEnum.MdbMoved)
             {
                 list3.Add(mapiTransactionOutcome);
                 performanceValue = 0.0;
             }
             else if (mapiTransactionOutcome.Result.Value == MapiTransactionResultEnum.StoreNotRunning)
             {
                 list2.Add(mapiTransactionOutcome);
                 performanceValue = -1.0;
             }
             else
             {
                 if (this.onlyPassives)
                 {
                     list4.Add(mapiTransactionOutcome);
                 }
                 else
                 {
                     list.Add(mapiTransactionOutcome);
                 }
                 performanceValue = -1.0;
             }
             this.monitoringData.PerformanceCounters.Add(new MonitoringPerformanceCounter("MSExchange Monitoring MAPIConnectivity", "Logon Latency", performanceInstance, performanceValue));
         }
         this.EventForNonSuccessTransactionResultList(list4, 1011, EventTypeEnumeration.Information, Strings.AllMapiTransactionsSucceeded, 1009, EventTypeEnumeration.Error, Strings.MapiTransactionFailedAgainstServerPrefix);
         this.EventForNonSuccessTransactionResultList(list2, 1008, EventTypeEnumeration.Information, Strings.AllMapiTransactionsSucceeded, 1004, EventTypeEnumeration.Error, Strings.SomeMapiTransactionsFailedPrefix);
         this.EventForNonSuccessTransactionResultList(list, 1000, EventTypeEnumeration.Information, Strings.AllMapiTransactionsSucceeded, 1001, EventTypeEnumeration.Error, Strings.SomeMapiTransactionsFailedPrefix);
         this.EventForNonSuccessTransactionResultList(list3, 1002, EventTypeEnumeration.Information, Strings.NoMdbWasMovedWhileRunning, 1003, EventTypeEnumeration.Warning, Strings.SomeMdbsWereMovedWhileRunningPrefix);
     }
     finally
     {
         if (this.MonitoringContext)
         {
             base.WriteObject(this.monitoringData);
         }
         TaskLogger.LogExit();
     }
 }