ln.skyscanner/http/SkyScannerHttpApplication.cs

54 lines
1.6 KiB
C#
Raw Normal View History

2019-03-13 14:18:05 +01:00
using System;
using ln.http.resources;
using System.IO;
2019-04-08 08:47:12 +02:00
using ln.skyscanner.entities;
using ln.skyscanner.checks;
2019-04-11 08:30:13 +02:00
using ln.types.net;
2019-04-16 18:23:05 +02:00
using System.Linq;
2019-08-29 13:14:52 +02:00
using ln.skyscanner.perfvalue;
2019-03-13 14:18:05 +01:00
namespace ln.skyscanner.http
{
public class SkyScannerHttpApplication : ResourceApplication
{
public SkyScanner SkyScanner { get; }
public String BasePath { get; private set; }
2019-04-17 22:56:31 +02:00
public String TemplatesBasePath { get; private set; }
2019-03-13 14:18:05 +01:00
2019-04-05 00:59:04 +02:00
ReflectiveResource refChecker;
ReflectiveResource refEntities;
2019-03-13 14:18:05 +01:00
public SkyScannerHttpApplication(SkyScanner skyScanner)
{
SkyScanner = skyScanner;
BasePath = Path.GetFullPath(".");
2019-04-17 22:56:31 +02:00
TemplatesBasePath = Path.Combine(BasePath, "templates", "static");
/* Development hint */
if (Directory.Exists("../../templates/static"))
TemplatesBasePath = Path.Combine(BasePath, "..", "..", "templates", "static");
2019-03-13 14:18:05 +01:00
DirectoryResource staticTemplates = new DirectoryResource(RootResource, TemplatesBasePath);
staticTemplates.ResourceTypeHook = ResourceTypeHook;
staticTemplates.DefaultResource = staticTemplates.GetResource("index.html");
RootResource.DefaultResource = staticTemplates;
SkyScannerHttpApi api = new SkyScannerHttpApi(this);
}
private Resource ResourceTypeHook(DirectoryResource directoryResource, FileInfo fileInfo)
{
if (fileInfo.Extension.Equals(".html"))
return new TemplateResource(directoryResource, fileInfo.FullName);
return null;
}
}
}