-
Notifications
You must be signed in to change notification settings - Fork 8
/
Global.asax.cs
93 lines (81 loc) · 3.58 KB
/
Global.asax.cs
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
85
86
87
88
89
90
91
92
93
using System;
using System.IO;
using BenchmarksAnalyzer.ServiceInterface;
using BenchmarksAnalyzer.ServiceModel.Types;
using Funq;
using ServiceStack;
using ServiceStack.Api.OpenApi;
using ServiceStack.Auth;
using ServiceStack.Authentication.OAuth2;
using ServiceStack.Caching;
using ServiceStack.Configuration;
using ServiceStack.Data;
using ServiceStack.OrmLite;
using ServiceStack.Razor;
namespace BenchmarksAnalyzer
{
public class AppHost : AppHostBase
{
public AppHost() : base("HTTP Benchmarks Analyzer", typeof(WebServices).Assembly) { }
public override void Configure(Container container)
{
Plugins.Add(new RazorFormat());
Plugins.Add(new RequestLogsFeature());
Plugins.Add(new PostmanFeature());
Plugins.Add(new OpenApiFeature());
Plugins.Add(new CorsFeature(
allowOriginWhitelist: new[] { "http://localhost", "http://localhost:8080", "http://test.servicestack.net", "http://null.jsbin.com" },
allowCredentials: true,
allowedHeaders: "Content-Type, Allow, Authorization"));
//Load environment config from text file if exists
var liveSettings = "~/appsettings.txt".MapHostAbsolutePath();
var appSettings = File.Exists(liveSettings)
? (IAppSettings)new TextFileSettings(liveSettings)
: new AppSettings();
SetConfig(new HostConfig {
DebugMode = appSettings.Get("DebugMode", false),
StripApplicationVirtualPath = appSettings.Get("StripApplicationVirtualPath", false),
AdminAuthSecret = appSettings.GetString("AuthSecret"),
});
if (appSettings.GetString("DbProvider") == "PostgreSql")
{
container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(
appSettings.GetString("ConnectionString"), PostgreSqlDialect.Provider));
}
else
{
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory("~/db.sqlite".MapHostAbsolutePath(), SqliteDialect.Provider));
}
container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
container.Resolve<ICacheClient>().InitSchema();
Plugins.Add(new AuthFeature(() => new UserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(),
new TwitterAuthProvider(appSettings),
new FacebookAuthProvider(appSettings),
new GoogleOAuth2Provider(appSettings),
new LinkedInOAuth2Provider(appSettings),
}) {
HtmlRedirect = "~/",
IncludeRegistrationService = true,
MaxLoginAttempts = appSettings.Get("MaxLoginAttempts", 5),
});
container.Register<IUserAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));
container.Resolve<IUserAuthRepository>().InitSchema();
using var db = container.Resolve<IDbConnectionFactory>().Open();
db.CreateTableIfNotExists<TestPlan>();
db.CreateTableIfNotExists<TestRun>();
db.CreateTableIfNotExists<TestResult>();
}
}
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
new AppHost().Init();
}
}
}