コード例 #1
0
        private async Task Run(bool fastShutdown)
        {
            Console.WriteLine($"{(fastShutdown ? "Fast" : "Slow")} shutdown started");

            if (!fastShutdown)
            {
                // Shutdown the Scheduler
                await QuartzScheduler.Dispose();

                // Shutdown the DiscordBot
                await DiscordBot.Dispose();
            }
            else
            {
                // Create a backup of the current config.json just in case
                File.Copy(Boot.LOCAL_CONFIGURATION, Boot.LOCAL_CONFIGURATION_AUTOMATIC_BACKUP, true);
            }

            // Shutdown Twitter
            TwitterManager.Dispose();

            // Shutdown DigitalOcean
            DoApi.Dispose();

            // Shutdown S3
            S3Api.Dispose();

            // Shutdown BCAT
            BcatApi.Dispose();

            // Shutdown DAuth
            DAuthApi.Dispose();

            // Shutdown the HandlerMapper
            HandlerMapper.Dispose();

            // Shutdown the KeysetManager
            KeysetManager.Dispose();

            // Shutdown anything app-specific
            ShutdownAppSpecificItems();

            // Save the configuration
            Configuration.LoadedConfiguration.Write();

            if (!fastShutdown)
            {
                // Wait a little while
                await Task.Delay(1000 *ShutdownWaitTime);
            }

            Console.WriteLine("Shutdown complete");
        }
コード例 #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);
        }