public int ProceedToNextIteration(int defaultDelay)
        {
            AuditLogSearchHealth auditLogSearchHealth = AuditLogSearchHealthHandler.GetInstance().AuditLogSearchHealth;
            bool flag = !this.RetryTenants.IsEmpty && this.RetryIteration < AuditLogSearchRetryPolicy.retryLimit;
            int  num;

            if (flag)
            {
                num = Math.Min(AuditLogSearchRetryPolicy.retryDelays[this.RetryIteration], defaultDelay);
                this.retryIteration = this.RetryIteration + 1;
                auditLogSearchHealth.ClearRetry();
                using (IEnumerator <ADUser> enumerator = this.RetryTenants.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ADUser tenant = enumerator.Current;
                        auditLogSearchHealth.AddRetryTenant(tenant);
                    }
                    goto IL_90;
                }
            }
            num = defaultDelay;
            this.Reset();
            IL_90:
            Random random = new Random();
            int num2 = (int)TimeSpan.FromMinutes(2.0).TotalMilliseconds;

            num += random.Next(-num2, num2);
            auditLogSearchHealth.RetryIteration = this.RetryIteration;
            auditLogSearchHealth.NextSearchTime = new DateTime?(DateTime.UtcNow + TimeSpan.FromMilliseconds((double)num));
            return(num);
        }
        // Token: 0x06000067 RID: 103 RVA: 0x000030DC File Offset: 0x000012DC
        public override void Work()
        {
            AuditLogSearchHealthHandler instance             = AuditLogSearchHealthHandler.GetInstance();
            AuditLogSearchHealth        auditLogSearchHealth = instance.AuditLogSearchHealth;

            WaitHandle[] waitHandles = new WaitHandle[]
            {
                base.StopEvent,
                instance.RunSearchNowEvent
            };
            AuditLogSearchContext.EventLogger.LogEvent(MSExchangeAuditLogSearchEventLogConstants.Tuple_AuditLogSearchServiceletStarted, string.Empty, new object[]
            {
                this.pid
            });
            ExTraceGlobals.ServiceletTracer.TraceInformation(42415, (long)this.GetHashCode(), "AuditLogSearch servicelet starting");
            this.PublishNotification("AsyncSearchServiceletStarting", this.pid.ToString(), ResultSeverityLevel.Informational);
            AuditLogSearchServicelet.hbTimer.Elapsed += this.Callback;
            AuditLogSearchServicelet.hbTimer.Enabled  = true;
            for (;;)
            {
                int defaultDelay = this.ReadPollInterval();
                try
                {
                    GrayException.MapAndReportGrayExceptions(delegate()
                    {
                        this.WorkInternal();
                    });
                }
                catch (GrayException ex)
                {
                    ExTraceGlobals.ServiceletTracer.TraceError(21863L, ex.ToString());
                    AuditLogSearchContext.EventLogger.LogEvent(MSExchangeAuditLogSearchEventLogConstants.Tuple_ServiceletException, string.Empty, new object[]
                    {
                        ex.ToString()
                    });
                    this.PublishNotification("AuditLogSearchCompletedWithErrors", ex.ToString(), ResultSeverityLevel.Error);
                    auditLogSearchHealth.AddException(ex);
                }
                int  millisecondsTimeout = this.retryPolicy.ProceedToNextIteration(defaultDelay);
                int  num  = WaitHandle.WaitAny(waitHandles, millisecondsTimeout, false);
                bool flag = num == 0;
                if (flag)
                {
                    break;
                }
                bool flag2 = num == 1;
                if (flag2)
                {
                    this.retryPolicy.Reset();
                }
            }
            AuditLogSearchServicelet.hbTimer.Enabled = false;
            AuditLogSearchContext.EventLogger.LogEvent(MSExchangeAuditLogSearchEventLogConstants.Tuple_AuditLogSearchServiceletEnded, string.Empty, new object[]
            {
                this.pid
            });
            ExTraceGlobals.ServiceletTracer.TraceInformation(28310, (long)this.GetHashCode(), "AuditLogSearch servicelet stopped");
            AuditLogSearchServicelet.hbTimer.Enabled = false;
        }
        public void Reset()
        {
            this.retryIteration = 0;
            this.RetryTenants   = new ConcurrentQueue <ADUser>();
            AuditLogSearchHealth auditLogSearchHealth = AuditLogSearchHealthHandler.GetInstance().AuditLogSearchHealth;

            auditLogSearchHealth.RetryIteration = this.RetryIteration;
            auditLogSearchHealth.NextSearchTime = new DateTime?(DateTime.UtcNow);
        }
 // Token: 0x0600006C RID: 108 RVA: 0x000037A8 File Offset: 0x000019A8
 private void ThreadStart(object queue)
 {
     try
     {
         GrayException.MapAndReportGrayExceptions(delegate()
         {
             ConcurrentQueue <ADUser> tenants = (ConcurrentQueue <ADUser>)queue;
             this.ProcessTenants(tenants);
         });
     }
     catch (GrayException ex)
     {
         ExTraceGlobals.WorkerTracer.TraceError(11881L, ex.ToString());
         AuditLogSearchContext.EventLogger.LogEvent(MSExchangeAuditLogSearchEventLogConstants.Tuple_WorkerException, string.Empty, new object[]
         {
             ex.ToString()
         });
         AuditLogSearchHealthHandler.GetInstance().AuditLogSearchHealth.AddException(ex);
     }
 }
        // Token: 0x0600006A RID: 106 RVA: 0x000033F8 File Offset: 0x000015F8
        private void WorkInternal()
        {
            AuditLogSearchHealth auditLogSearchHealth = AuditLogSearchHealthHandler.GetInstance().AuditLogSearchHealth;

            auditLogSearchHealth.ProcessStartTime = DateTime.UtcNow;
            auditLogSearchHealth.ProcessEndTime   = null;
            int num = this.random.Next(100000, 999999);

            AuditLogSearchContext.EventLogger.LogEvent(MSExchangeAuditLogSearchEventLogConstants.Tuple_AuditLogSearchStarted, string.Empty, new object[]
            {
                this.pid,
                num
            });
            Exception ex = null;

            try
            {
                ConcurrentQueue <ADUser> concurrentQueue;
                if (this.retryPolicy.IsRetrying)
                {
                    concurrentQueue = this.retryPolicy.RetryTenants;
                    ExTraceGlobals.ServiceletTracer.TraceInformation <int>(25566, (long)this.GetHashCode(), "Retrying search for {0} tenant arbitration mailbox(es)", concurrentQueue.Count);
                }
                else
                {
                    auditLogSearchHealth.Clear();
                    ADUser[] array = AuditLogSearchServicelet.GlobalFindAllArbitrationMailboxes();
                    if (array == null || array.Length == 0)
                    {
                        ExTraceGlobals.ServiceletTracer.TraceInformation(36433, (long)this.GetHashCode(), "No tenant arbitration mailboxes found in this server");
                        return;
                    }
                    concurrentQueue = new ConcurrentQueue <ADUser>(array);
                    ExTraceGlobals.ServiceletTracer.TraceInformation <int>(25566, (long)this.GetHashCode(), "Found {0} tenant arbitration mailbox(es)", concurrentQueue.Count);
                    foreach (ADUser tenant in concurrentQueue)
                    {
                        auditLogSearchHealth.AddTenant(tenant);
                    }
                }
                this.retryPolicy.ClearRetryTenants();
                int num2 = Math.Min(concurrentQueue.Count, Environment.ProcessorCount);
                ExTraceGlobals.ServiceletTracer.TraceInformation <int>(19568, (long)this.GetHashCode(), "Starting {0} worker threads", num2);
                Thread[] array2 = new Thread[num2];
                for (int i = 0; i < num2; i++)
                {
                    Thread thread = array2[i] = new Thread(new ParameterizedThreadStart(this.ThreadStart));
                    thread.Start(concurrentQueue);
                }
                ExTraceGlobals.ServiceletTracer.TraceInformation(28049, (long)this.GetHashCode(), "Waiting for the threads to join");
                foreach (Thread thread2 in array2)
                {
                    thread2.Join();
                }
                AuditLogSearchContext.EventLogger.LogEvent(MSExchangeAuditLogSearchEventLogConstants.Tuple_AuditLogSearchEnded, string.Empty, new object[]
                {
                    this.pid,
                    num
                });
            }
            catch (ADTransientException ex2)
            {
                ex = ex2;
            }
            catch (LocalServerNotFoundException ex3)
            {
                ex = ex3;
            }
            finally
            {
                auditLogSearchHealth.ProcessEndTime = new DateTime?(DateTime.UtcNow);
            }
            if (ex != null)
            {
                string text = ex.ToString();
                ExTraceGlobals.ServiceletTracer.TraceInformation <string>(11881, (long)this.GetHashCode(), "Error: {0}", text);
                this.PublishNotification("AuditLogSearchCompletedWithErrors", text, ResultSeverityLevel.Error);
                AuditLogSearchContext.EventLogger.LogEvent(MSExchangeAuditLogSearchEventLogConstants.Tuple_TransientException, string.Empty, new object[]
                {
                    this.pid,
                    num,
                    text
                });
                auditLogSearchHealth.AddException(ex);
            }
        }