Ejemplo n.º 1
0
        private static int ShutdownWaitTime = 5; // in seconds

        public static async Task CreateAndRun(bool fastShutdown)
        {
            if (IsShutdown)
            {
                return;
            }

            // Get the Shutdown subclass
            Type shutdownType = TypeUtils.GetSubclassOfType <Shutdown>();

            // Create a new instance of it
            Shutdown shutdownInstance = (Shutdown)Activator.CreateInstance(shutdownType);

            // Call the Run method
            await shutdownInstance.Run(fastShutdown);

            IsShutdown = true;
        }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            // Wait for the debugger to attach if requested
            if (args.Length > 0 && args[0].ToLower() == "--waitfordebugger")
            {
                Console.WriteLine("Waiting for debugger...");

                while (!Debugger.IsAttached)
                {
                    await Task.Delay(1000);
                }

                Console.WriteLine("Debugger attached!");
            }

            // Get the type of the Configuration
            Type configType = TypeUtils.GetSubclassOfType <Configuration>();

            // Declare variable to hold the configuration
            Configuration configuration;

            // Check if the config file exists
            if (!File.Exists(LOCAL_CONFIGURATION))
            {
                // Create a new dummy Configuration
                configuration = (Configuration)Activator.CreateInstance(TypeUtils.GetSubclassOfType <Configuration>());
                configuration.SetDefaults();

                // Write out the default config
                configuration.Write(LOCAL_CONFIGURATION);

                Console.WriteLine("Wrote default configuration to " + LOCAL_CONFIGURATION);

                return;
            }

            // Create the Exception logs directory
            System.IO.Directory.CreateDirectory(LOCAL_EXCEPTION_LOGS_DIRECTORY);

            // Load the Configuration
            Configuration.Load(configType, LOCAL_CONFIGURATION);

            // Initialize the Localizer
            Localizer.Initialize();

            // Initialize the HandlerMapper
            HandlerMapper.Initialize();

            // Initialize the KeysetManager
            KeysetManager.Initialize();

            // Initialize DAuth
            DAuthApi.Initialize();

            // Initialize BCAT
            BcatApi.Initialize();

            // Initialize S3
            S3Api.Initialize();

            // Initialize DigitalOcean
            DoApi.Initialize();

            // Initialize Twitter
            TwitterManager.Initialize();

            // Initialize the DiscordBot
            await DiscordBot.Initialize();

            // Initialize the Scheduler
            await QuartzScheduler.Initialize();

            // Wait for the bot to fully initialize
            while (!DiscordBot.IsReady)
            {
                await Task.Delay(1000);
            }

            // Print out to the logging channel that we're initialized
            await DiscordBot.LoggingChannel.SendMessageAsync("\\*\\*\\* **Initialized**");

            // Schedule the BootHousekeepingJob
            await QuartzScheduler.ScheduleJob(TypeUtils.GetSubclassOfType <BootHousekeepingJob>(), "Immediate");

            // Register the SIGTERM handler
            AssemblyLoadContext.Default.Unloading += async x =>
            {
                // Run Shutdown in fast mode
                await Shutdown.CreateAndRun(true);
            };

            await Task.Delay(-1);
        }