예제 #1
0
 public void Start()
 {
     _availableEngines = new Dictionary <string, Type>();
     UrlMapper.RegisterIndexFile("index.html");
     UrlMapper.RegisterIndexFile("index.htm");
     RegisterEngine("http", typeof(HttpEngine));
     _engines = new List <Engine>();
     Logger.Info("Starting HtcSharp...");
     Logger.Info("Loading Configuration...");
     AspNetConfigPath = Path.Combine(Path.GetDirectoryName(_configPath), "aspnet-appsettings.json");
     try {
         if (!File.Exists(_configPath))
         {
             IoUtils.CreateHtcConfig(_configPath);
         }
         _config = IoUtils.GetJsonFile(_configPath);
         if (!File.Exists(AspNetConfigPath))
         {
             IoUtils.CreateAspConfig(AspNetConfigPath);
         }
         PluginsPath     = _config.GetValue("PluginsPath", StringComparison.CurrentCultureIgnoreCase)?.Value <string>() ?? Path.Combine(Directory.GetCurrentDirectory(), @"plugins/");
         PluginsPath     = IoUtils.ReplacePathTags(PluginsPath);
         _errorPagesPath = _config.GetValue("ErrorPagesPath", StringComparison.CurrentCultureIgnoreCase)?.Value <string>() ?? Path.Combine(Directory.GetCurrentDirectory(), @"error-pages/");
         _errorPagesPath = IoUtils.ReplacePathTags(_errorPagesPath);
         IsDebug         = _config.GetValue("Debug", StringComparison.CurrentCultureIgnoreCase)?.Value <bool>() == true;
         if (!Directory.Exists(PluginsPath))
         {
             Directory.CreateDirectory(PluginsPath);
         }
         if (!Directory.Exists(_errorPagesPath))
         {
             Directory.CreateDirectory(_errorPagesPath);
         }
     } catch (Exception ex) {
         Logger.Error("Failed to load configuration!", ex);
         return;
     }
     RegisterErrorPages();
     PluginsManager = new PluginManager();
     PluginsManager.LoadPlugins(PluginsPath);
     PluginsManager.Call_OnLoad();
     LoadEngines();
     foreach (var engine in _engines)
     {
         try {
             Logger.Info($"Starting Engine: '{engine.GetType().Name}'");
             engine.Start();
         } catch (Exception ex) {
             Logger.Error($"Failed to start Engine: '{engine.GetType().Name}'", ex);
         }
     }
     IsStopped = true;
     PluginsManager.Call_OnEnable();
     Logger.Info("HTCServer is now running!");
 }