diff --git a/BodyshopUploader/ImEXOnlinePartner.csproj b/BodyshopUploader/ImEXOnlinePartner.csproj index 1df4eff..9fb04f6 100644 --- a/BodyshopUploader/ImEXOnlinePartner.csproj +++ b/BodyshopUploader/ImEXOnlinePartner.csproj @@ -368,6 +368,7 @@ + Resources.es-MX.resx True @@ -387,6 +388,7 @@ Component + GrowlNotification.xaml diff --git a/BodyshopUploader/Models/ScanResponseItem.cs b/BodyshopUploader/Models/ScanResponseItem.cs new file mode 100644 index 0000000..5c77d0e --- /dev/null +++ b/BodyshopUploader/Models/ScanResponseItem.cs @@ -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); } + } + } +} diff --git a/BodyshopUploader/Utils/DiskScan.cs b/BodyshopUploader/Utils/DiskScan.cs new file mode 100644 index 0000000..0f19fdb --- /dev/null +++ b/BodyshopUploader/Utils/DiskScan.cs @@ -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> ScanDiskForEstimates() + { + List EstimatesOnDisk = new List(); + List ad1FilePaths = new List(); + + 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; + } + } +} diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs index 9529bb4..7952a13 100644 --- a/BodyshopUploader/Utils/HTTPServer.cs +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -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 HttpResponse = new List(); + 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 HttpResponse = new List(); + 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 ParseRequest(System.Net.HttpListenerRequest req) diff --git a/BodyshopUploader/Utils/JobProcessingQueue.cs b/BodyshopUploader/Utils/JobProcessingQueue.cs index 0848fbe..de00940 100644 --- a/BodyshopUploader/Utils/JobProcessingQueue.cs +++ b/BodyshopUploader/Utils/JobProcessingQueue.cs @@ -84,7 +84,7 @@ namespace BodyshopPartner.Utils } } - private static async Task GetOpCodes() + public static async Task GetOpCodes() { var r = new GraphQLRequest {