コード例 #1
0
        public async Task Start()
        {
            try {
                if (Running)
                {
                    return;
                }
                Running = true;
                Logger.LogInfo("Loading HtcServer", null);
                Logger.LogInfo("Loading Modules", null);
                _moduleManager.LoadModules(HtcIOUtils.ReplacePathTags(Config.GetValue("ModulesPath", StringComparison.CurrentCultureIgnoreCase)?.Value <string>()));
                await _moduleManager.CallLoad();

                Logger.LogInfo("Loading Engines", null);
                var enginesConfigs = (JObject)Config.GetValue("Engines", StringComparison.CurrentCultureIgnoreCase);
                foreach (string engineName in EngineManager.GetEnginesNames())
                {
                    if (!enginesConfigs.ContainsKey(engineName))
                    {
                        continue;
                    }
                    var engineConfig = (JObject)enginesConfigs.GetValue(engineName, StringComparison.CurrentCultureIgnoreCase);
                    var engine       = EngineManager.InstantiateEngine(engineName);
                    EngineManager.AddEngine(engine);
                    Logger.LogInfo($"Loading Engine {engineName}", null);
                    await EngineManager.Load(engine, engineConfig);
                }
                Logger.LogInfo("Loading Plugins", null);
                _pluginManager.LoadPlugins(HtcIOUtils.ReplacePathTags(Config.GetValue("PluginsPath", StringComparison.CurrentCultureIgnoreCase)?.Value <string>()));
                await _pluginManager.CallLoad();

                Logger.LogInfo("Starting HtcServer", null);
                Logger.LogInfo("Enabling Modules", null);
                await _moduleManager.CallEnable();

                Logger.LogInfo("Starting Engines", null);
                await EngineManager.Start();

                Logger.LogInfo("Enabling Plugins", null);
                await _pluginManager.CallEnable();
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
                throw ex;
            }
        }