55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using System;
|
|
using ln.http;
|
|
using ln.http.resources;
|
|
using System.IO;
|
|
using ln.skyscanner.entities;
|
|
using ln.skyscanner.checks;
|
|
namespace ln.skyscanner.http
|
|
{
|
|
public class SkyScannerHttpApplication : ResourceApplication
|
|
{
|
|
public SkyScanner SkyScanner { get; }
|
|
|
|
public String BasePath { get; private set; }
|
|
public String TemplatesBasePath => Path.Combine(BasePath, "templates","static");
|
|
|
|
ReflectiveResource refChecker;
|
|
ReflectiveResource refEntities;
|
|
|
|
public SkyScannerHttpApplication(SkyScanner skyScanner)
|
|
{
|
|
SkyScanner = skyScanner;
|
|
|
|
BasePath = Path.GetFullPath(".");
|
|
|
|
DirectoryResource staticTemplates = new DirectoryResource(RootResource, TemplatesBasePath);
|
|
|
|
staticTemplates.ResourceTypeHook = ResourceTypeHook;
|
|
staticTemplates.DefaultResource = staticTemplates.GetResource("index.html");
|
|
|
|
RootResource.DefaultResource = staticTemplates;
|
|
|
|
refEntities = new ReflectiveResource(RootResource, "entities", SkyScanner.Entities);
|
|
refChecker = new ReflectiveResource(RootResource, "checker", SkyScanner.Checker);
|
|
|
|
SkyScannerHttpApi api = new SkyScannerHttpApi(this);
|
|
|
|
BaseResource collections = new BaseResource(RootResource, "collections");
|
|
new CollectionResource<PointOfPresence>(collections, skyScanner.Entities.popCollection);
|
|
new CollectionResource<Node>(collections, skyScanner.Entities.nodeCollection);
|
|
new CollectionResource<Subnet>(collections, skyScanner.Entities.subnetCollection);
|
|
new CollectionResource<SkyCheckState>(collections, skyScanner.Checker.checkStates);
|
|
}
|
|
|
|
private Resource ResourceTypeHook(DirectoryResource directoryResource, FileInfo fileInfo)
|
|
{
|
|
if (fileInfo.Extension.Equals(".html"))
|
|
return new TemplateResource(directoryResource, fileInfo.FullName);
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|
|
}
|