forked from Fr8org/Fr8Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelfHostFactory.cs
74 lines (70 loc) · 2.75 KB
/
SelfHostFactory.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using HubWeb.Controllers;
using HubWeb.Controllers.Api;
using Microsoft.Owin.Hosting;
using Owin;
using Microsoft.Owin.Security.DataProtection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System.Reflection;
namespace HubWeb
{
public class SelfHostFactory
{
public class SelfHostStartup
{
public void Configuration(IAppBuilder app)
{
Fr8.Infrastructure.Utilities.Server.ServerPhysicalPath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
app.SetDataProtectionProvider(new DpapiDataProtectionProvider());
var startup = new Startup();
startup.Configuration(app, true);
app.UseWebApi(config);
ConfigureFormatters(config);
new MvcApplication().Init(true);
startup.ConfigureControllerActivator(config);
}
private void ConfigureFormatters(HttpConfiguration config)
{
// Configure formatters
// Enable camelCasing in JSON responses
var formatters = config.Formatters;
var jsonFormatter = formatters.JsonFormatter;
var settings = jsonFormatter.SerializerSettings;
settings.Formatting = Formatting.Indented;
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
}
public static IDisposable CreateServer(string url)
{
return WebApp.Start<SelfHostStartup>(url: url);
}
public ICollection<Type> GetControllerTypes(IAssembliesResolver assembliesResolver)
{
return new Type[] {
typeof(ActivitiesController),
typeof(AlarmsController),
typeof(AuthenticationController),
typeof(ConfigurationController),
typeof(ContainersController),
typeof(DocumentationController),
typeof(EventsController),
typeof(FilesController),
typeof(ManifestsController),
typeof(ReportsController),
typeof(PlanNodesController),
typeof(PlansController),
typeof(TerminalsController),
typeof(UsersController),
typeof(WarehousesController),
typeof(WebServicesController)
};
}
}
}