public Application(string configDirectory, ServerConfigSerializer serverConfigSerializer, VirtualHostConfigSerializer virtualHostConfigSerializer) { ExecutionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (ExecutionPath == null) { throw new ApplicationException("Can' get execution path."); } try { ServerConfigHandler = new ServerConfigHandler(serverConfigSerializer); ServerConfig = ServerConfigHandler.LoadFromFile(Path.Combine(ExecutionPath, configDirectory, "server.xml")); } catch { Console.WriteLine("Error parsing server.xml configuration file."); return; } ErrorHandler = new ErrorHandler(Path.Combine(ExecutionPath, "logs", ServerConfig.ErrorLog)); try { VirtualHostConfigHandler = new VirtualHostConfigHandler(virtualHostConfigSerializer); VirtualHostList = VirtualHostConfigHandler.LoadFromFile(Path.Combine(ExecutionPath, configDirectory, "vhosts.xml")); } catch { ErrorHandler.WriteCriticalError("Error parsing vhosts.xml configuration file."); } var chainControllerHandler = new ChainControllerHandler(); chainControllerHandler.Reg(new DigestAuthHandler()); chainControllerHandler.Reg(new BasicAuthHandler()); chainControllerHandler.Reg(new OptionsMethodHandler()); chainControllerHandler.Reg(new PostMethodHandler()); chainControllerHandler.Reg(new GetHeadMethodHandler(ServerConfig.DirectoryRoot)); var controllerHandler = new ControllerHandler(VirtualHostList, chainControllerHandler, ServerConfig.ServerName, ServerConfig.DirectoryRoot); HttpServer = new HttpServer(ServerConfig, controllerHandler); }
public static void Main(string[] args) { ServerConfigHandler.loadConfig(); CreateWebHostBuilder(args).Build().Run(); }