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;
|
|
|
|
|
|
2019-04-05 00:59:04 +02:00
|
|
|
|
refEntities = new ReflectiveResource(RootResource, "entities", SkyScanner.Entities);
|
|
|
|
|
refChecker = new ReflectiveResource(RootResource, "checker", SkyScanner.Checker);
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
|
|
|
|
SkyScannerHttpApi api = new SkyScannerHttpApi(this);
|
2019-04-08 08:47:12 +02:00
|
|
|
|
|
|
|
|
|
BaseResource collections = new BaseResource(RootResource, "collections");
|
2019-04-11 08:30:13 +02:00
|
|
|
|
|
|
|
|
|
new CollectionResource<Node>(collections, skyScanner.Entities.NodeCollection);
|
|
|
|
|
new CollectionResource<Subnet>(collections, skyScanner.Entities.SubnetCollection);
|
|
|
|
|
new CollectionResource<PointOfPresence>(collections, skyScanner.Entities.PointOfPresenceCollection);
|
|
|
|
|
|
|
|
|
|
new CollectionResource<CrawledHost>(collections, skyScanner.Entities.CrawledHosts);
|
|
|
|
|
new CollectionResource<CrawledSubnet>(collections, skyScanner.Entities.CrawledSubnets);
|
|
|
|
|
|
|
|
|
|
new CollectionResource<SkyCheckState>(collections, skyScanner.Entities.SkyCheckStates);
|
|
|
|
|
|
|
|
|
|
new CollectionResource<Network4>(collections, skyScanner.Entities.BlockedNetworks);
|
2019-04-16 18:23:05 +02:00
|
|
|
|
|
|
|
|
|
ObjectContainerResource<PerformanceValue> resPerformanceValues = new ObjectContainerResource<PerformanceValue>(collections);
|
|
|
|
|
resPerformanceValues.GetResourceName = (pv) => pv.PerfName;
|
|
|
|
|
resPerformanceValues.Enumeration = () => skyScanner.Entities.SkyCheckStates.SelectMany((checkState) => checkState.PerformanceValues);
|
|
|
|
|
resPerformanceValues.Lookup = skyScanner.Entities.LookupPerformanceValue;
|
|
|
|
|
|
2019-03-13 14:18:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Resource ResourceTypeHook(DirectoryResource directoryResource, FileInfo fileInfo)
|
|
|
|
|
{
|
|
|
|
|
if (fileInfo.Extension.Equals(".html"))
|
|
|
|
|
return new TemplateResource(directoryResource, fileInfo.FullName);
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|