-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.cs
More file actions
84 lines (69 loc) · 2.89 KB
/
Application.cs
File metadata and controls
84 lines (69 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.IO;
using System.Reflection;
using Gepard.Configuration.Server;
using Gepard.Configuration.VirtualHost;
using Gepard.Controllers;
using Gepard.Core;
using Gepard.Core.Main;
namespace Gepard
{
public class Application
{
private ErrorHandler ErrorHandler { get; set; }
public string ExecutionPath { get; set; }
public HttpServer HttpServer { get; set; }
public ServerConfig ServerConfig { get; set; }
public VirtualHostList VirtualHostList { get; set; }
public ServerConfigHandler ServerConfigHandler { get; set; }
public VirtualHostConfigHandler VirtualHostConfigHandler { get; set; }
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 void Start()
{
HttpServer.Start();
}
public void Stop()
{
try
{
HttpServer.Stop();
}
catch
{
// ignored
}
}
}
}