2019-03-13 14:18:05 +01:00
|
|
|
|
using System;
|
|
|
|
|
using ln.logging;
|
|
|
|
|
using ln.http;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using ln.skyscanner.http;
|
|
|
|
|
using System.IO;
|
2019-03-14 08:36:02 +01:00
|
|
|
|
using ln.skyscanner.crawl;
|
2019-03-13 14:18:05 +01:00
|
|
|
|
namespace ln.skyscanner
|
|
|
|
|
{
|
|
|
|
|
public enum ComponentState { STOPPED, INITIALIZED, STARTED, FAILED }
|
|
|
|
|
|
|
|
|
|
public class SkyScanner
|
|
|
|
|
{
|
|
|
|
|
public String[] Arguments { get; }
|
|
|
|
|
public String BasePath { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public HTTPServer HTTPServer { get; private set; }
|
2019-03-14 08:36:02 +01:00
|
|
|
|
public Crawler Crawler { get; private set; }
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
|
|
|
|
public SkyScanner(String[] args)
|
|
|
|
|
{
|
|
|
|
|
Logging.Log(LogLevel.INFO, "SkyScanner: Constructor");
|
|
|
|
|
|
|
|
|
|
BasePath = Path.GetFullPath(".");
|
|
|
|
|
|
|
|
|
|
Logging.Log(LogLevel.INFO, "SkyScanner: BasePath={0}", BasePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Arguments = args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
Logging.Log(LogLevel.INFO, "SkyScanner: Start()");
|
|
|
|
|
|
|
|
|
|
StartHttpServer();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
Logging.Log(LogLevel.INFO, "SkyScanner: Stop()");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StopHttpServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** HTTP Server **/
|
|
|
|
|
|
|
|
|
|
public ComponentState HttpStatus
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (HTTPServer != null)
|
|
|
|
|
{
|
|
|
|
|
if (HTTPServer.IsRunning)
|
|
|
|
|
return ComponentState.STARTED;
|
|
|
|
|
|
|
|
|
|
return ComponentState.INITIALIZED;
|
|
|
|
|
}
|
|
|
|
|
return ComponentState.STOPPED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartHttpServer()
|
|
|
|
|
{
|
|
|
|
|
HTTPServer = new HTTPServer();
|
|
|
|
|
HTTPServer.AddEndpoint(new System.Net.IPEndPoint(IPAddress.Any,8080));
|
|
|
|
|
|
|
|
|
|
HTTPServer.DefaultApplication = new SkyScannerHttpApplication(this);
|
|
|
|
|
|
|
|
|
|
HTTPServer.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopHttpServer()
|
|
|
|
|
{
|
|
|
|
|
if (HTTPServer != null)
|
|
|
|
|
{
|
|
|
|
|
if (HTTPServer.IsRunning)
|
|
|
|
|
{
|
|
|
|
|
HTTPServer.Stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-03-14 08:36:02 +01:00
|
|
|
|
/** Crawler **/
|
|
|
|
|
|
|
|
|
|
public ComponentState CrawlerStatus
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Crawler != null)
|
|
|
|
|
{
|
|
|
|
|
if (Crawler.ThreadStates.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return ComponentState.STARTED;
|
|
|
|
|
}
|
|
|
|
|
return ComponentState.INITIALIZED;
|
|
|
|
|
}
|
|
|
|
|
return ComponentState.STOPPED;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-13 14:18:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|