IO-766 Disk Scan route
This commit is contained in:
@@ -25,11 +25,12 @@ namespace BodyshopPartner.Utils
|
||||
|
||||
public static void InitHttpServer(HttpLogger HttpLogger)
|
||||
{
|
||||
//Adding local routes.
|
||||
//QuickBooks Execution Routes.
|
||||
Route.Add("/qb/", (req, res, props) =>
|
||||
{
|
||||
hlog("Received a ping from ImEX.online");
|
||||
hlog("Received a QuickBooks request from ImEX.online");
|
||||
res.WithCORS();
|
||||
//res.AddHeader("Access-Control-Allow-Origin", "http://localhost:3000 https://localhost:3000 http://localhost:5000 https://localhost:5000 https://*.imex.online,imex.online");
|
||||
res.Close();
|
||||
}, "OPTIONS");
|
||||
|
||||
@@ -37,23 +38,40 @@ namespace BodyshopPartner.Utils
|
||||
(req, res, props) => { HandleQbPost(req, res); }
|
||||
, "POST");
|
||||
|
||||
//Pinging based routes.
|
||||
Route.Add("/ping/", (req, res, props) =>
|
||||
{
|
||||
hlog("Received a ping from ImEX.online");
|
||||
res.WithCORS();
|
||||
//res.AddHeader("Access-Control-Allow-Origin", "http://localhost:3000 https://localhost:3000 http://localhost:5000 https://localhost:5000 https://*.imex.online,imex.online");
|
||||
res.Close();
|
||||
}, "OPTIONS");
|
||||
|
||||
Route.Add("/ping/",
|
||||
(req, res, props) => { HandlePing(req, res); }
|
||||
, "POST");
|
||||
|
||||
//FileScanning Routes
|
||||
Route.Add("/scan/", (req, res, props) =>
|
||||
{
|
||||
hlog("Received a scan request from ImEX.online");
|
||||
res.WithCORS();
|
||||
res.Close();
|
||||
}, "OPTIONS");
|
||||
Route.Add("/scan/",
|
||||
(req, res, props) => { HandleScan(req, res); }
|
||||
, "POST");
|
||||
Route.Add("/import/", (req, res, props) =>
|
||||
{
|
||||
hlog("Received an import request from ImEX.online");
|
||||
res.WithCORS();
|
||||
res.Close();
|
||||
}, "OPTIONS");
|
||||
Route.Add("/import/",
|
||||
(req, res, props) => { HandleImport(req, res); }
|
||||
, "POST");
|
||||
|
||||
|
||||
logger.Trace("Starting HTTP server...");
|
||||
hlog = HttpLogger;
|
||||
|
||||
//TODO As a part of the installer, add netsh http add urlacl url=http://+:1337/ user="Everyone
|
||||
try
|
||||
{
|
||||
hlog("ImEX Online connection server starting...");
|
||||
@@ -67,7 +85,6 @@ namespace BodyshopPartner.Utils
|
||||
App.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
string msg = "Unable to connect to ImEX Online Web App. Please ensure your firewall allows the connection.";
|
||||
|
||||
Utils.Notifications.notifier.ShowError(msg);
|
||||
});
|
||||
Utils.SquirrelAwareHelper.AddHttpExcetion();
|
||||
@@ -139,20 +156,59 @@ namespace BodyshopPartner.Utils
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static async void HandleScan(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
|
||||
{
|
||||
logger.Trace("/scan/ - POST");
|
||||
//Input will be an array of objects containing XMLs.
|
||||
|
||||
List<ScanResponseItem> HttpResponse = new List<ScanResponseItem>();
|
||||
try
|
||||
{
|
||||
//Do the scan
|
||||
//Add the items to the response list.
|
||||
HttpResponse = await Utils.DiskScan.ScanDiskForEstimates();
|
||||
}
|
||||
catch (Exception Ex)
|
||||
{
|
||||
logger.Error(Ex, "Error encountered while processing QuickBooks requests.");
|
||||
hlog("Error encountered while processing QuickBooks requests.");
|
||||
HttpResponse.Add(new ScanResponseItem() { Id = "-1", Success = false, ErrorMessage = Ex.Message });
|
||||
}
|
||||
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
|
||||
}
|
||||
|
||||
|
||||
private static async void HandleImport(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
|
||||
{
|
||||
logger.Trace("/import/ - POST");
|
||||
//Input will be an array of objects containing XMLs.
|
||||
logger.Info(req);
|
||||
List<ScanResponseItem> HttpResponse = new List<ScanResponseItem>();
|
||||
try
|
||||
{
|
||||
//Do the scan
|
||||
//Add the items to the response list.
|
||||
HttpResponse = await Utils.DiskScan.ScanDiskForEstimates();
|
||||
}
|
||||
catch (Exception Ex)
|
||||
{
|
||||
logger.Error(Ex, "Error encountered while processing QuickBooks requests.");
|
||||
hlog("Error encountered while processing QuickBooks requests.");
|
||||
HttpResponse.Add(new ScanResponseItem() { Id = "-1", Success = false, ErrorMessage = Ex.Message });
|
||||
}
|
||||
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
|
||||
}
|
||||
|
||||
|
||||
private static void HandlePing(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res)
|
||||
{
|
||||
logger.Trace("/ping/ - POST");
|
||||
hlog("Received QuickBooks Receivable request.");
|
||||
//Input will be an array of objects containing XMLs.
|
||||
|
||||
dynamic response = new JObject();
|
||||
response.appver = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
response.qbpath = Properties.Settings.Default.QuickBooksFilePath;
|
||||
|
||||
var t = JsonConvert.SerializeObject(response);
|
||||
|
||||
res.WithCORS().AsText((string)t.ToString());
|
||||
|
||||
}
|
||||
|
||||
public static List<QbRequestItem> ParseRequest(System.Net.HttpListenerRequest req)
|
||||
|
||||
Reference in New Issue
Block a user