// Token: 0x06000007 RID: 7 RVA: 0x0000254C File Offset: 0x0000074C
        protected override bool TryReadServerConfig()
        {
            ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
            {
                TransportADNotificationAdapter.Instance.RegisterForMsExchangeTransportServiceDeletedEvents();
            }, 0);

            if (!adoperationResult.Succeeded)
            {
                TransportService.logger.LogEvent(TransportEventLogConstants.Tuple_FailedToRegisterForDeletedObjectsNotification, null, new object[]
                {
                    adoperationResult.Exception
                });
                ExTraceGlobals.ServiceTracer.TraceError <Exception>(0L, "Failed to register for Deleted object notifications. Details {0}", adoperationResult.Exception);
                ProcessManagerService.StopService();
            }
            this.readingConfigOnStart = true;
            ADOperationResult adoperationResult2;
            bool flag = this.ReadServerConfig(out adoperationResult2);

            this.readingConfigOnStart = false;
            if (!flag)
            {
                this.GenerateConfigFailureEventLog(adoperationResult2.Exception);
                return(false);
            }
            return(true);
        }
        // Token: 0x06000005 RID: 5 RVA: 0x00002158 File Offset: 0x00000358
        internal static void Main(string[] args)
        {
            List <string> list = new List <string>();

            list.Add("SeAuditPrivilege");
            list.Add("SeChangeNotifyPrivilege");
            list.Add("SeCreateGlobalPrivilege");
            list.Add("SeImpersonatePrivilege");
            bool isSystem;

            using (WindowsIdentity current = WindowsIdentity.GetCurrent())
            {
                isSystem = current.IsSystem;
            }
            if (isSystem)
            {
                list.Add("SeIncreaseQuotaPrivilege");
                list.Add("SeAssignPrimaryTokenPrivilege");
            }
            int num = Privileges.RemoveAllExcept(list.ToArray());

            if (num != 0)
            {
                Environment.Exit(num);
            }
            Globals.InitializeSinglePerfCounterInstance();
            ExWatson.Register();
            bool flag  = !Environment.UserInteractive;
            bool flag2 = false;
            bool flag3 = false;

            foreach (string text in args)
            {
                if (text.StartsWith("-?", StringComparison.OrdinalIgnoreCase))
                {
                    TransportService.Usage();
                    Environment.Exit(0);
                }
                else if (text.StartsWith("-console", StringComparison.OrdinalIgnoreCase))
                {
                    flag2 = true;
                }
                else if (text.StartsWith("-wait", StringComparison.OrdinalIgnoreCase))
                {
                    flag3 = true;
                }
            }
            if (!flag)
            {
                if (!flag2)
                {
                    TransportService.Usage();
                    Environment.Exit(0);
                }
                Console.WriteLine("Starting {0}, running in console mode.", Assembly.GetExecutingAssembly().GetName().Name);
                if (flag3)
                {
                    Console.WriteLine("Press ENTER to continue.");
                    Console.ReadLine();
                }
            }
            SettingOverrideSync.Instance.Start(true);
            if (!VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).Transport.ADExceptionHandling.Enabled)
            {
                TransportService.adConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 324, "Main", "f:\\15.00.1497\\sources\\dev\\Transport\\src\\TransportService\\TransportService.cs");
            }
            else
            {
                ADOperationResult adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
                {
                    TransportService.adConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 334, "Main", "f:\\15.00.1497\\sources\\dev\\Transport\\src\\TransportService\\TransportService.cs");
                }, 0);
                if (!adoperationResult.Succeeded)
                {
                    ExTraceGlobals.ServiceTracer.TraceError <Exception>(0L, "Error when getting AD configuration session: {0}", adoperationResult.Exception);
                    TransportService.logger.LogEvent(TransportEventLogConstants.Tuple_MSExchangeTransportInitializationFailure, null, new object[]
                    {
                        adoperationResult.Exception.ToString()
                    });
                    Environment.Exit(1);
                }
            }
            TransportService.transportService = new TransportService(flag);
            if (!TransportService.transportService.Initialize())
            {
                ExTraceGlobals.ServiceTracer.TraceError(0L, "Failed to initialize the service. Exiting.");
                ProcessManagerService.StopService();
            }
            if (!flag)
            {
                TransportService.transportService.OnStartInternal(args);
                bool flag4 = false;
                while (!flag4)
                {
                    Console.WriteLine("Enter 'q' to shutdown.");
                    string text2 = Console.ReadLine();
                    if (string.IsNullOrEmpty(text2))
                    {
                        break;
                    }
                    switch (text2[0])
                    {
                    case 'q':
                        flag4 = true;
                        break;

                    case 'r':
                        TransportService.transportService.OnCustomCommandInternal(200);
                        break;

                    case 'u':
                        TransportService.transportService.OnCustomCommandInternal(201);
                        break;
                    }
                }
                Console.WriteLine("Shutting down ...");
                TransportService.transportService.OnStopInternal();
                Console.WriteLine("Done.");
                return;
            }
            ServiceBase.Run(TransportService.transportService);
        }
        // Token: 0x06000009 RID: 9 RVA: 0x00002644 File Offset: 0x00000844
        protected override void OnStartInternal(string[] args)
        {
            Process[] processesByName = Process.GetProcessesByName("EdgeTransport");
            if (processesByName.Length > 0)
            {
                int       pid = Process.GetCurrentProcess().Id;
                Process[] processesByName2 = Process.GetProcessesByName("MSExchangeTransport");
                if (processesByName2.Length == 1)
                {
                    foreach (Process process in processesByName)
                    {
                        TransportService.logger.LogEvent(TransportEventLogConstants.Tuple_KillOrphanedWorker, null, new object[]
                        {
                            pid,
                            process.Id
                        });
                        ExTraceGlobals.ServiceTracer.TraceDebug <int>(0L, "TransportService: Killing orphaned worker PID:{0}", process.Id);
                        try
                        {
                            process.Kill();
                        }
                        catch (Win32Exception ex)
                        {
                            this.LogFailedKill(process.Id, ex.Message);
                        }
                        catch (NotSupportedException ex2)
                        {
                            this.LogFailedKill(process.Id, ex2.Message);
                        }
                        catch (InvalidOperationException ex3)
                        {
                            this.LogFailedKill(process.Id, ex3.Message);
                        }
                        if (!process.WaitForExit(10000))
                        {
                            this.LogFailedKill(process.Id, "Timeout");
                            if (Environment.UserInteractive)
                            {
                                Console.WriteLine("Orphaned worker pid {0} did not exit.", process.Id);
                                Environment.Exit(1);
                            }
                            ProcessManagerService.instance.Stop();
                            return;
                        }
                    }
                }
                else
                {
                    IEnumerable <string> source = from i in processesByName2
                                                  where i.Id != pid
                                                  select i.Id.ToString();

                    string text = string.Join(",", source.ToArray <string>());
                    TransportService.logger.LogEvent(TransportEventLogConstants.Tuple_AnotherServiceRunning, null, new object[]
                    {
                        pid,
                        text
                    });
                    ExTraceGlobals.ServiceTracer.TraceDebug <string>(0L, "TransportService: another service instance is running ({0}). Exiting", text);
                    ProcessManagerService.StopService();
                }
            }
            base.OnStartInternal(args);
        }
        // Token: 0x06000005 RID: 5 RVA: 0x000021B4 File Offset: 0x000003B4
        internal static void Main(string[] args)
        {
            MonitoringService.LogDiagnosticInfo("Registering for Watson.", new object[0]);
            ExWatson.Register();
            bool flag  = !Environment.UserInteractive;
            bool flag2 = false;
            bool flag3 = false;

            MonitoringService.LogDiagnosticInfo("Parsing command line args.", new object[0]);
            foreach (string text in args)
            {
                if (text.StartsWith("-?", StringComparison.OrdinalIgnoreCase))
                {
                    MonitoringService.LogDiagnosticInfo("Printing usage and exiting.", new object[0]);
                    MonitoringService.PrintUsage();
                    Environment.Exit(0);
                }
                else if (text.StartsWith("-console", StringComparison.OrdinalIgnoreCase))
                {
                    MonitoringService.LogDiagnosticInfo("Running from console.", new object[0]);
                    flag2 = true;
                }
                else if (text.StartsWith("-wait", StringComparison.OrdinalIgnoreCase))
                {
                    flag3 = true;
                }
                else if (text.StartsWith("-ForceConsole", StringComparison.OrdinalIgnoreCase))
                {
                    MonitoringService.LogDiagnosticInfo("Force running from console.", new object[0]);
                    flag  = false;
                    flag2 = true;
                }
            }
            if (!flag)
            {
                if (!flag2)
                {
                    MonitoringService.LogDiagnosticInfo("Printing usage and exiting.", new object[0]);
                    MonitoringService.PrintUsage();
                    Environment.Exit(0);
                }
                Console.WriteLine("Starting {0}, running in console mode.", Assembly.GetExecutingAssembly().GetName().Name);
                if (flag3)
                {
                    MonitoringService.LogDiagnosticInfo("Waiting for user input before continuing.", new object[0]);
                    Console.WriteLine("Press ENTER to continue.");
                    Console.ReadLine();
                }
            }
            if (!ServiceTopologyProvider.IsAdTopologyServiceInstalled())
            {
                MonitoringService.LogDiagnosticInfo("Can't use AD Topology service; setting admin mode instead.", new object[0]);
                ADSession.SetAdminTopologyMode();
            }
            MonitoringService.LogDiagnosticInfo("Initializing perf counters.", new object[0]);
            Globals.InitializeMultiPerfCounterInstance("MSExchangeHM");
            MonitoringService monitoringService = new MonitoringService(flag);

            if (!monitoringService.Initialize())
            {
                ExTraceGlobals.ServiceTracer.TraceError(0L, "Failed to initialize the service. Exiting.");
                MonitoringService.LogDiagnosticInfo("Initialization of the service failed. Stopping service and exiting.", new object[0]);
                ProcessManagerService.StopService();
            }
            if (!flag)
            {
                monitoringService.OnStartInternal(args);
                bool flag4 = false;
                while (!flag4)
                {
                    Console.WriteLine("Enter 'q' to shutdown.");
                    string text2 = Console.ReadLine();
                    if (string.IsNullOrEmpty(text2))
                    {
                        break;
                    }
                    switch (text2[0])
                    {
                    case 'q':
                        flag4 = true;
                        break;

                    case 'r':
                        monitoringService.OnCustomCommandInternal(200);
                        break;

                    case 'u':
                        monitoringService.OnCustomCommandInternal(201);
                        break;
                    }
                }
                Console.WriteLine("Shutting down ...");
                monitoringService.OnStopInternal();
                Console.WriteLine("Done.");
                return;
            }
            ServiceBase.Run(monitoringService);
        }