Exemplo n.º 1
0
        public async Task Run(ParameterData setup)
        {
            scheduler.VerifyOwnThread();

            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            TaskScheduler.UnobservedTaskException      += UnobservedTaskExceptionHandler;
            Console.CancelKeyPress += ConsoleInterruptHandler;

            var config = ConfRoot.OpenOrCreate(configFilePath);

            if (config is null)
            {
                throw new Exception("Could not create config");
            }
            ConfigUpgrade2.Upgrade(config.Configs.BotsPath.Value);
            config.Save();

            var builder = new DependencyBuilder(injector);

            injector.AddModule(this);
            injector.AddModule(scheduler);
            injector.AddModule(injector);
            injector.AddModule(config);
            injector.AddModule(config.Db);
            injector.AddModule(config.Plugins);
            injector.AddModule(config.Web);
            injector.AddModule(config.Web.Interface);
            injector.AddModule(config.Web.Api);
            injector.AddModule(config.Rights);
            injector.AddModule(config.Factories);
            builder.RequestModule <SystemMonitor>();
            builder.RequestModule <DbStore>();
            builder.RequestModule <PluginManager>();
            builder.RequestModule <WebServer>();
            builder.RequestModule <RightsManager>();
            builder.RequestModule <BotManager>();
            builder.RequestModule <TokenManager>();
            builder.RequestModule <CommandManager>();
            builder.RequestModule <ResourceResolver>();
            builder.RequestModule <Stats>();

            if (!builder.Build())
            {
                throw new Exception("Could not load all core modules");
            }

            Upgrader.PerformUpgrades(injector);
            YoutubeDlHelper.DataObj = config.Tools.YoutubeDl;

            injector.GetModuleOrThrow <CommandManager>().RegisterCollection(MainCommands.Bag);
            injector.GetModuleOrThrow <RightsManager>().CreateConfigIfNotExists(setup.Interactive);
            injector.GetModuleOrThrow <WebServer>().StartWebServer();
            injector.GetModuleOrThrow <Stats>().StartTimer(setup.SendStats);
            await injector.GetModuleOrThrow <BotManager>().RunBots(setup.Interactive);
        }
Exemplo n.º 2
0
        public static void PerformUpgrades(CoreInjector injector)
        {
            var database = injector.GetModuleOrThrow <DbStore>();
            var meta     = database.GetMetaData(CoreTable);

            void Advance(int version, string?explanation)
            {
                meta.Version = version;
                database.UpdateMetaData(meta);
                if (explanation != null)
                {
                    Log.Info("Upgrading data to ver {0}. {1}", version, explanation);
                }
            }

            switch (meta.Version)
            {
            case 0:
                // Case 0 should always jump to the lastest version, since it gets created on first start.
                Advance(CurrentVersion, null);
                goto case CurrentVersion;

            case CurrentVersion:
                break;

            default:
                Log.Warn("It seems that you downgraded your TS3AB version. " +
                         "Due to automatic upgrades some stuff might not work anymore, be advised. " +
                         "It is recommended to backup data before upgrading to unstable/beta builds if you intend to downgrade again.");
                break;
            }
        }