// Token: 0x06000004 RID: 4 RVA: 0x0000211C File Offset: 0x0000031C
 protected override void RunMain(DateTime utcNow)
 {
     if (utcNow - this.lastHangDetection > BackgroundProcessingThread.hangDetectionInterval)
     {
         MailboxTransportSubmissionService.DetectSubmissionHang();
         this.lastHangDetection = utcNow;
     }
     if (utcNow - this.lastScan > BackgroundProcessingThread.SlowScanInterval)
     {
         IStoreDriverSubmission storeDriverSubmission;
         bool flag = Components.TryGetStoreDriverSubmission(out storeDriverSubmission);
         if (flag)
         {
             Components.StoreDriverSubmission.ExpireOldSubmissionConnections();
         }
         this.lastScan = utcNow;
     }
     if (utcNow - this.lastTimeThrottlingManagerSwept > BackgroundProcessingThread.FiveMinuteInterval)
     {
         Components.MessageThrottlingComponent.MessageThrottlingManager.CleanupIdleEntries();
         Components.UnhealthyTargetFilterComponent.CleanupExpiredEntries();
         this.lastTimeThrottlingManagerSwept = utcNow;
     }
     if (Components.ResourceManager.IsMonitoringEnabled && utcNow - Components.ResourceManager.LastTimeResourceMonitored > Components.ResourceManager.MonitorInterval)
     {
         Components.ResourceManager.OnMonitorResource(null);
     }
 }
        // Token: 0x06000019 RID: 25 RVA: 0x00002A5C File Offset: 0x00000C5C
        private void OnStopInternalHelper()
        {
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StopService);
            ADNotificationListener.Stop();
            MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TracePass <DateTime>(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, 0L, "Stopping MailboxTransportSubmissionService ({0})", DateTime.UtcNow);
            bool flag = false;

            try
            {
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StopBackgroundThread);
                if (MailboxTransportSubmissionService.backgroundThread != null)
                {
                    MailboxTransportSubmissionService.backgroundThread.Stop();
                }
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StopDatabaseManager);
                if (this.databaseManager != null)
                {
                    this.databaseManager.Stop();
                    this.databaseManager.Dispose();
                }
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StopMessageTracking);
                MessageTrackingLog.Stop();
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StopConfiguration);
                SubmissionConfiguration.Instance.Unload();
                MailboxTransportSubmissionEventLogger.LogEvent(MSExchangeSubmissionEventLogConstants.Tuple_SubmissionServiceStopSuccess, null, new object[0]);
                MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TracePass(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, 0L, "Stopped MailboxTransportSubmissionService");
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.UngregisterPamComponent);
                ProcessAccessManager.UnregisterComponent(this);
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.ServiceStopped);
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    MailboxTransportSubmissionEventLogger.LogEvent(MSExchangeSubmissionEventLogConstants.Tuple_SubmissionServiceStopFailure, null, new object[0]);
                    MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TraceFail(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, 0L, "Failed to stop MailboxTransportSubmissionService");
                }
            }
        }
        // Token: 0x06000018 RID: 24 RVA: 0x0000283C File Offset: 0x00000A3C
        private void OnStartInternalHelper()
        {
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StartService);
            MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TracePfdPass <int, DateTime>(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, 0L, "PFD EMS {0} Starting MailboxTransportSubmissionService ({1})", 24475, DateTime.UtcNow);
            bool   flag  = false;
            bool   flag2 = false;
            string text  = null;

            try
            {
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.RegisterPamComponent);
                ProcessAccessManager.RegisterComponent(this);
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.InitializePerformanceMonitoring);
                MailboxTransportSubmissionService.InitializePerfMon();
                MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TracePfdPass <int, DateTime>(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, 0L, "PFD EMS {0} Finished Loading Perfmon ({1})", 32667, DateTime.UtcNow);
                TransportADNotificationAdapter.Instance.RegisterForSubmissionServiceEvents();
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.LoadConfiguration);
                StorageExceptionHandler.Init();
                this.ConstructComponentLoadTree();
                SubmissionConfiguration.Instance.Load();
                int num;
                ThreadPool.GetMaxThreads(out this.maxThreads, out num);
                ITimeBasedAssistantType[]  timeBasedAssistantTypeArray  = null;
                IEventBasedAssistantType[] eventBasedAssistantTypeArray = new IEventBasedAssistantType[]
                {
                    new MailboxTransportSubmissionAssistantType()
                };
                this.databaseManager = new DatabaseManager("Microsoft Exchange Mailbox Transport Submission", MailboxTransportSubmissionAssistant.MaxConcurrentSubmissions, eventBasedAssistantTypeArray, timeBasedAssistantTypeArray, false);
                MailboxTransportSubmissionEventLogger.LogEvent(MSExchangeSubmissionEventLogConstants.Tuple_SubmissionServiceStartSuccess, null, new object[0]);
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.CreateBackgroundThread);
                MailboxTransportSubmissionService.backgroundThread = new BackgroundProcessingThread();
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StartBackgroundThread);
                MailboxTransportSubmissionService.backgroundThread.Start(false, ServiceState.Active);
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StartDatabaseManager);
                this.databaseManager.Start();
                MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.ServiceStarted);
                MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TracePfdPass <int>(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, 0L, "PFD EMS {0} MailTransportSubmissionService Started", 26523);
                flag = true;
            }
            catch (ConfigurationErrorsException ex)
            {
                text  = ex.Message;
                flag2 = true;
            }
            catch (HandlerParseException ex2)
            {
                text  = ex2.Message;
                flag2 = true;
            }
            finally
            {
                if (!flag)
                {
                    MailboxTransportSubmissionEventLogger.LogEvent(MSExchangeSubmissionEventLogConstants.Tuple_SubmissionServiceStartFailure, null, new object[]
                    {
                        text
                    });
                    MailboxTransportSubmissionService.StoreDriverTracer.ServiceTracer.TracePfdPass(MailboxTransportSubmissionService.StoreDriverTracer.MessageProbeActivityId, 0L, "Failed to start MailboxTransportSubmissionService");
                    base.ExRequestAdditionalTime(60000);
                    if (flag2)
                    {
                        base.Stop();
                    }
                }
            }
        }
        // Token: 0x0600000E RID: 14 RVA: 0x000022C0 File Offset: 0x000004C0
        public static void Main(string[] args)
        {
            CommonDiagnosticsLog.Initialize(HostId.MailboxTransportSubmissionService);
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.StartProcess);
            int num = Privileges.RemoveAllExcept(new string[]
            {
                "SeAuditPrivilege",
                "SeChangeNotifyPrivilege",
                "SeCreateGlobalPrivilege"
            });

            if (num != 0)
            {
                Environment.Exit(num);
            }
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.RegisterWatson);
            ExWatson.Register();
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.RegisterWatsonAction);
            ExWatson.RegisterReportAction(new WatsonRegKeyReportAction(MailboxTransportSubmissionService.watsonRegKeyReportActionString), WatsonActionScope.Process);
            MailboxTransportSubmissionService.runningAsService = !Environment.UserInteractive;
            bool flag  = false;
            bool flag2 = false;

            foreach (string text in args)
            {
                if (text.StartsWith("-?", StringComparison.Ordinal))
                {
                    MailboxTransportSubmissionService.Usage();
                    Environment.Exit(0);
                }
                else if (text.StartsWith("-console"))
                {
                    flag = true;
                }
                else if (text.StartsWith("-wait"))
                {
                    flag2 = true;
                }
            }
            if (!MailboxTransportSubmissionService.runningAsService)
            {
                if (!flag)
                {
                    MailboxTransportSubmissionService.Usage();
                    Environment.Exit(0);
                }
                Console.WriteLine("Starting {0}, running in console mode.", Assembly.GetExecutingAssembly().GetName().Name);
                if (flag2)
                {
                    Console.WriteLine("Press ENTER to continue.");
                    Console.ReadLine();
                }
            }
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.InitializePerformanceCounterInstance);
            Globals.InitializeSinglePerfCounterInstance();
            SettingOverrideSync.Instance.Start(true);
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.LoadLatencyTrackerConfiguration);
            try
            {
                LatencyTracker.Configuration = TransportAppConfig.LatencyTrackerConfig.Load();
            }
            catch (ConfigurationErrorsException)
            {
            }
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.LoadTransportAppConfig);
            string text2;

            if (!Components.TryLoadTransportAppConfig(out text2))
            {
                MailboxTransportSubmissionEventLogger.LogEvent(MSExchangeSubmissionEventLogConstants.Tuple_SubmissionServiceStartFailure, null, new object[]
                {
                    text2
                });
                Environment.Exit(1);
            }
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.CreateService);
            MailboxTransportSubmissionService.mailboxTransportSubmissionService = new MailboxTransportSubmissionService();
            MailboxTransportSubmissionService.LogStage(MailboxTransportSubmissionService.Stage.RunService);
            if (!MailboxTransportSubmissionService.runningAsService)
            {
                ExServiceBase.RunAsConsole(MailboxTransportSubmissionService.mailboxTransportSubmissionService);
                return;
            }
            ServiceBase.Run(MailboxTransportSubmissionService.mailboxTransportSubmissionService);
        }