IO-766 Disk Scan route
This commit is contained in:
@@ -368,6 +368,7 @@
|
||||
<Compile Include="Models\QbRequestItem.cs" />
|
||||
<Compile Include="Models\QbResponseItem.cs" />
|
||||
<Compile Include="Models\QbXmlResponse.cs" />
|
||||
<Compile Include="Models\ScanResponseItem.cs" />
|
||||
<Compile Include="Properties\Resources.es-MX.Designer.cs">
|
||||
<DependentUpon>Resources.es-MX.resx</DependentUpon>
|
||||
<AutoGen>True</AutoGen>
|
||||
@@ -387,6 +388,7 @@
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Utils\Decoder\EstimateDecoder.cs" />
|
||||
<Compile Include="Utils\DiskScan.cs" />
|
||||
<Compile Include="Utils\GraphQL.cs" />
|
||||
<Compile Include="Utils\Growls\GrowlNotification.xaml.cs">
|
||||
<DependentUpon>GrowlNotification.xaml</DependentUpon>
|
||||
|
||||
87
BodyshopUploader/Models/ScanResponseItem.cs
Normal file
87
BodyshopUploader/Models/ScanResponseItem.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BodyshopPartner.Models
|
||||
{
|
||||
public class ScanResponseItem : DTO_Base
|
||||
{
|
||||
public ScanResponseItem()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private string _id;
|
||||
[JsonProperty("id")]
|
||||
public string Id
|
||||
{
|
||||
get { return _id; }
|
||||
set { SetProperty(ref _id, value); }
|
||||
}
|
||||
private string _cieca_id;
|
||||
[JsonProperty("cieca_id")]
|
||||
public string Cieca_Id
|
||||
{
|
||||
get { return _cieca_id; }
|
||||
set { SetProperty(ref _cieca_id, value); }
|
||||
}
|
||||
|
||||
private string _filepath;
|
||||
[JsonProperty("filepath")]
|
||||
public string Filepath
|
||||
{
|
||||
get { return _filepath; }
|
||||
set { SetProperty(ref _filepath, value); }
|
||||
}
|
||||
|
||||
private string _owner;
|
||||
[JsonProperty("owner")]
|
||||
public string Owner
|
||||
{
|
||||
get { return _owner; }
|
||||
set { SetProperty(ref _owner, value); }
|
||||
}
|
||||
private string _vehicle;
|
||||
[JsonProperty("vehicle")]
|
||||
public string Vehicle
|
||||
{
|
||||
get { return _vehicle; }
|
||||
set { SetProperty(ref _vehicle, value); }
|
||||
}
|
||||
private string _clm_no;
|
||||
[JsonProperty("clm_no")]
|
||||
public string Clm_No
|
||||
{
|
||||
get { return _clm_no; }
|
||||
set { SetProperty(ref _clm_no, value); }
|
||||
}
|
||||
|
||||
private string _ins_co_nm;
|
||||
[JsonProperty("ins_co_nm")]
|
||||
public string Ins_Co_Nm
|
||||
{
|
||||
get { return _ins_co_nm; }
|
||||
set { SetProperty(ref _ins_co_nm, value); }
|
||||
}
|
||||
|
||||
|
||||
private bool _success;
|
||||
[JsonProperty("success")]
|
||||
public bool Success
|
||||
{
|
||||
get { return _success; }
|
||||
set { SetProperty(ref _success, value); }
|
||||
}
|
||||
|
||||
private string _errorMessage;
|
||||
[JsonProperty("errorMessage")]
|
||||
public string ErrorMessage
|
||||
{
|
||||
get { return _errorMessage; }
|
||||
set { SetProperty(ref _errorMessage, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
51
BodyshopUploader/Utils/DiskScan.cs
Normal file
51
BodyshopUploader/Utils/DiskScan.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using BodyshopPartner.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BodyshopPartner.Utils
|
||||
{
|
||||
public static class DiskScan
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public static async Task<List<ScanResponseItem>> ScanDiskForEstimates()
|
||||
{
|
||||
List<ScanResponseItem> EstimatesOnDisk = new List<ScanResponseItem>();
|
||||
List<string> ad1FilePaths = new List<string>();
|
||||
|
||||
Properties.Settings.Default.MonitoringPaths.ForEach(mp => ad1FilePaths.AddRange(Directory.GetFiles(mp, "*.env").ToList()));
|
||||
|
||||
await JobProcessingQueue.GetOpCodes();
|
||||
|
||||
ad1FilePaths.ForEach(envfp =>
|
||||
{
|
||||
//Create a DTO_Queue Item to re-use the decoder.
|
||||
logger.Info(envfp);
|
||||
|
||||
DTO_QueueItem item = new DTO_QueueItem()
|
||||
{
|
||||
FilePath = envfp
|
||||
};
|
||||
|
||||
dynamic job = Utils.Decoder.EstimateDecoder.CIECAEstimateImport.DecodeEstimate(envfp);
|
||||
|
||||
EstimatesOnDisk.Add(new ScanResponseItem()
|
||||
{
|
||||
Filepath = envfp,
|
||||
Cieca_Id = job.ciecaid,
|
||||
Clm_No = job.clm_no,
|
||||
Owner = job.ownr_fn?.Value + " " + job.ownr_ln?.Value,
|
||||
Ins_Co_Nm = job.ins_co_nm?.Value,
|
||||
Vehicle = job.vehicle.data.v_model_yr.Value + " " + job.vehicle.data.v_make_desc.Value + " " + job.vehicle.data.v_model_desc.Value,
|
||||
|
||||
});
|
||||
});
|
||||
logger.Info("Estimates found: " + ad1FilePaths.Count);
|
||||
return EstimatesOnDisk;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace BodyshopPartner.Utils
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task GetOpCodes()
|
||||
public static async Task GetOpCodes()
|
||||
{
|
||||
var r = new GraphQLRequest
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user