// Token: 0x06000004 RID: 4 RVA: 0x0000223C File Offset: 0x0000043C
        protected override void OnStartInternal(string[] args)
        {
            if (AssistantsService.debugBreakOnStart)
            {
                Debugger.Break();
            }
            using (Process currentProcess = Process.GetCurrentProcess())
            {
                Globals.Logger.LogEvent(InfoWorkerEventLogConstants.Tuple_ServiceStarting, null, new object[]
                {
                    currentProcess.Id,
                    "Microsoft Exchange",
                    "15.00.1497.010"
                });
            }
            AssistantsService.TracerPfd.TracePfd <int, DateTime>((long)this.GetHashCode(), "PFD IWS {0} Starting the Mailbox Assistants Service {1} ", 28055, DateTime.UtcNow);
            AssistantsLog.LogServiceStartEvent(this.activityId);
            bool flag = false;

            try
            {
                ADSession.DisableAdminTopologyMode();
                SettingOverrideSync.Instance.Start(true);
                ProcessAccessManager.RegisterComponent(SettingOverrideSync.Instance);
                AssistantsService.TracerPfd.TracePfd <int>((long)this.GetHashCode(), "PFD IWS {0} Initializing the Assistant Infrastructure", 27479);
                this.databaseManager = new DatabaseManager("MSExchangeMailboxAssistants", 50, InfoworkerAssistants.CreateEventBasedAssistantTypes(), InfoworkerAssistants.CreateTimeBasedAssistantTypes(), true);
                this.databaseManager.Start();
                MailboxSearchServer.StartServer();
                Globals.Logger.LogEvent(InfoWorkerEventLogConstants.Tuple_ServiceStarted, null, new object[0]);
                AssistantsService.TracerPfd.TracePfd <int>((long)this.GetHashCode(), "PFD IWS {0} Mailbox Assistants Service is started successfully ", 23959);
                if (Configuration.MemoryMonitorEnabled)
                {
                    this.memoryMonitor = new MemoryMonitor();
                    this.memoryMonitor.Start((ulong)Configuration.MemoryBarrierPrivateBytesUsageLimit, (uint)Configuration.MemoryBarrierNumberOfSamples, Configuration.MemoryBarrierSamplingDelay, Configuration.MemoryBarrierSamplingInterval, delegate(ulong memoryInUse)
                    {
                        Globals.Logger.LogEvent(InfoWorkerEventLogConstants.Tuple_ServiceOutOfMemory, null, new object[]
                        {
                            memoryInUse
                        });
                        throw new ServiceOutOfMemoryException();
                    });
                }
                this.watermarkCleanupTimer = new Timer(new TimerCallback(InfoworkerAssistants.DeleteWatermarksForDisabledAndDeprecatedAssistants), null, Configuration.WatermarkCleanupInterval, Configuration.WatermarkCleanupInterval);
                ProcessAccessManager.RegisterComponent(this);
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    Globals.Logger.LogEvent(InfoWorkerEventLogConstants.Tuple_ServiceFailedToStart, null, new object[0]);
                }
            }
        }
 // Token: 0x06000005 RID: 5 RVA: 0x00002438 File Offset: 0x00000638
 protected override void OnStopInternal()
 {
     Globals.Logger.LogEvent(InfoWorkerEventLogConstants.Tuple_ServiceStopping, null, new object[0]);
     AssistantsService.TracerPfd.TracePfd <int>((long)this.GetHashCode(), "PFD IWS {0} Stopping the Mailbox Assistants Service", 32151);
     if (this.memoryMonitor != null)
     {
         this.memoryMonitor.Stop();
     }
     if (this.watermarkCleanupTimer != null)
     {
         this.watermarkCleanupTimer.Dispose();
     }
     if (this.databaseManager != null)
     {
         try
         {
             GrayException.MapAndReportGrayExceptions(delegate()
             {
                 this.databaseManager.Stop();
             });
         }
         catch (GrayException arg)
         {
             AssistantsService.Tracer.TraceDebug <AssistantsService, GrayException>((long)this.GetHashCode(), "{0}: Gray Exception reported during shutdown: {1}", this, arg);
         }
         finally
         {
             this.databaseManager.Dispose();
         }
         AssistantsService.TracerPfd.TracePfd <int>((long)this.GetHashCode(), "PFD IWS {0} Stopping the Assistant Infrastructure", 17815);
     }
     MailboxSearchServer.StopServer();
     AssistantsLog.LogServiceStopEvent(this.activityId);
     AssistantsLog.Stop();
     MailboxAssistantsSlaReportLogFactory.StopAll();
     using (Process currentProcess = Process.GetCurrentProcess())
     {
         Globals.Logger.LogEvent(InfoWorkerEventLogConstants.Tuple_ServiceStopped, null, new object[]
         {
             currentProcess.Id,
             "Microsoft Exchange",
             "15.00.1497.010"
         });
     }
     ProcessAccessManager.UnregisterComponent(this);
     ProcessAccessManager.UnregisterComponent(SettingOverrideSync.Instance);
     SettingOverrideSync.Instance.Stop();
     AssistantsService.TracerPfd.TracePfd <int>((long)this.GetHashCode(), "PFD IWS {0} The Mailbox Assistants Service Stopped successfully", 21911);
 }
        // Token: 0x06001396 RID: 5014 RVA: 0x00072DFC File Offset: 0x00070FFC
        private static void RpcCallWithRetry(Action rpcDelegate, int maxRetry)
        {
            bool flag = false;

            if (maxRetry <= 0)
            {
                throw new ArgumentException("maxRetry should be greater than 0");
            }
            for (int i = 0; i < maxRetry - 1; i++)
            {
                try
                {
                    rpcDelegate();
                    return;
                }
                catch (RpcException ex)
                {
                    DiscoverySearchEventBasedAssistant.Tracer.TraceError <RpcException, int>((long)rpcDelegate.GetHashCode(), "RPC call to mailbox search failed (retry times: {1}): {0}", ex, i);
                    if (!flag)
                    {
                        flag = true;
                        MailboxSearchServer.RestartServer();
                        SearchEventLogger.Instance.LogDiscoverySearchRpcServerRestartedEvent(ex);
                    }
                    else if (!(ex is RpcConnectionException))
                    {
                        EventNotificationItem.Publish(ExchangeComponent.EdiscoveryProtocol.Name, "MailboxSearch.RPCFailureEvents.Monitor", null, ex.ToString(), ResultSeverityLevel.Error, false);
                        throw;
                    }
                }
            }
            try
            {
                rpcDelegate();
            }
            catch (RpcException ex2)
            {
                DiscoverySearchEventBasedAssistant.Tracer.TraceError <RpcException>((long)rpcDelegate.GetHashCode(), "RPC call to mailbox search failed: {0}", ex2);
                EventNotificationItem.Publish(ExchangeComponent.EdiscoveryProtocol.Name, "MailboxSearch.RPCFailureEvents.Monitor", null, ex2.ToString(), ResultSeverityLevel.Error, false);
                throw;
            }
        }