コード例 #1
0
        protected override async Task OnLoad()
        {
            PathExt.EnsureFolders();

            argsReader = new ArgsReader(Args);

            config = await LoadConfig(argsReader.GetOrDefault("config", Path.Combine(PathExt.GetConfigPath(), "config.yml")));

            LoggerManager.Dispose();
            LoggerManager.Init(config.Logging.GetAppender());

            Logger.LogInfo("Loading...");

            cliServer = new CliServer(argsReader.GetOrDefault("pipe", "htcsharp"));
            cliServer.AddCommand(new ReloadCommand(this));

            moduleManager = new ModuleManager(version, configureServices => {
                configureServices.AddSingleton(cliServer);
            });
            await moduleManager.LoadModules(Path.GetFullPath(config.ModulesPath));

            await moduleManager.InitModules();

            pluginManager = new PluginManager(version, moduleManager, configureServices => {
                configureServices.AddSingleton(cliServer);
            });
            await pluginManager.LoadPlugins(Path.GetFullPath(config.PluginsPath));

            await pluginManager.InitPlugins();
        }
コード例 #2
0
        public async Task OnReload()
        {
            Logger.LogInfo("Reloading...");

            await pluginManager.DisablePlugins();

            await moduleManager.DisableModules();

            await pluginManager.UnloadPlugins();

            await moduleManager.UnloadModules();

            LoggerManager.Dispose();
            config = await LoadConfig(argsReader.GetOrDefault("config", Path.Combine(PathExt.GetConfigPath(), "config.yml")));

            LoggerManager.Init(config.Logging.GetAppender());

            await moduleManager.LoadModules(Path.GetFullPath(config.ModulesPath));

            await moduleManager.InitModules();

            await pluginManager.LoadPlugins(Path.GetFullPath(config.PluginsPath));

            await pluginManager.InitPlugins();

            await moduleManager.EnableModules();

            await pluginManager.EnablePlugins();

            Logger.LogInfo("Reloaded!");
        }
コード例 #3
0
ファイル: HtcHttpModule.cs プロジェクト: jpdante/HtcSharp
        public async Task <HttpModuleConfig> LoadConfig()
        {
            string fileName = Path.Combine(PathExt.GetConfigPath(true, "http"), "config.json");

            if (File.Exists(fileName))
            {
                await using var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                return(await JsonSerializer.DeserializeAsync <HttpModuleConfig>(fileStream));
            }
            else
            {
                await using var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
                var config = new HttpModuleConfig();
                await JsonSerializer.SerializeAsync(fileStream, config, new JsonSerializerOptions {
                    WriteIndented = true
                });

                return(config);
            }
        }