From 1ea7a151076baa9893a68d9faa615982ad76037c Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 18 Mar 2021 08:46:44 -0700 Subject: [PATCH] IO-766 Import Jobs from Disk Scan --- BodyshopUploader/Utils/DiskScan.cs | 1 + BodyshopUploader/Utils/HTTPServer.cs | 23 ++++++++++++++++---- BodyshopUploader/Utils/JobProcessingQueue.cs | 14 ++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/BodyshopUploader/Utils/DiskScan.cs b/BodyshopUploader/Utils/DiskScan.cs index 0f19fdb..5db4fa7 100644 --- a/BodyshopUploader/Utils/DiskScan.cs +++ b/BodyshopUploader/Utils/DiskScan.cs @@ -35,6 +35,7 @@ namespace BodyshopPartner.Utils EstimatesOnDisk.Add(new ScanResponseItem() { + Id = job.ciecaid, Filepath = envfp, Cieca_Id = job.ciecaid, Clm_No = job.clm_no, diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs index 7952a13..f20c35a 100644 --- a/BodyshopUploader/Utils/HTTPServer.cs +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -183,19 +183,22 @@ namespace BodyshopPartner.Utils { logger.Trace("/import/ - POST"); //Input will be an array of objects containing XMLs. - logger.Info(req); - List HttpResponse = new List(); + + var requestBody = ParseBody(req); + JObject HttpResponse = new JObject(); try { //Do the scan //Add the items to the response list. - HttpResponse = await Utils.DiskScan.ScanDiskForEstimates(); + await JobProcessingQueue.UploadJob(new DTO_QueueItem() { FilePath = requestBody.filepath }); + HttpResponse.Add("success", true); } 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 }); + HttpResponse.Add("success" , false); + HttpResponse.Add("error", Ex.ToString()); } res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse)); } @@ -211,6 +214,18 @@ namespace BodyshopPartner.Utils res.WithCORS().AsText((string)t.ToString()); } + public static dynamic ParseBody(System.Net.HttpListenerRequest req) + { + System.IO.Stream body = req.InputStream; + System.Text.Encoding encoding = req.ContentEncoding; + System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); + string s = reader.ReadToEnd(); + body.Close(); + reader.Close(); + + return JsonConvert.DeserializeObject(s); + } + public static List ParseRequest(System.Net.HttpListenerRequest req) { System.IO.Stream body = req.InputStream; diff --git a/BodyshopUploader/Utils/JobProcessingQueue.cs b/BodyshopUploader/Utils/JobProcessingQueue.cs index de00940..15dba30 100644 --- a/BodyshopUploader/Utils/JobProcessingQueue.cs +++ b/BodyshopUploader/Utils/JobProcessingQueue.cs @@ -67,10 +67,8 @@ namespace BodyshopPartner.Utils try { - Thread.Sleep(1000);//Allow a small amount of time to pass before processing the queue item so that any writes can finish. - await GetOpCodes(); - DecodeQueueItemJob(item); - await UpsertQueueItem(item); + await UploadJob(item); + } catch (Exception ex) { @@ -84,6 +82,14 @@ namespace BodyshopPartner.Utils } } + public static async Task UploadJob(DTO_QueueItem item) + { + Thread.Sleep(1000);//Allow a small amount of time to pass before processing the queue item so that any writes can finish. + await GetOpCodes(); + DecodeQueueItemJob(item); + await UpsertQueueItem(item); + } + public static async Task GetOpCodes() { var r = new GraphQLRequest