From 3324f4c3b46df6011b3db5f50adfbb51facb761b Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 3 Dec 2020 16:59:10 -0800 Subject: [PATCH] Cleaned up Job Queue, Gql Logs, and fixed issue for audatex Lin Files with PART_DES_J --- .../Utils/Decoder/EstimateDecoder.cs | 50 +++++++++++++++++-- BodyshopUploader/Utils/GraphQL.cs | 3 +- BodyshopUploader/Utils/HTTPServer.cs | 12 ++--- BodyshopUploader/Utils/JobProcessingQueue.cs | 28 ++++++----- BodyshopUploader/Utils/SquirrelAwareHelper.cs | 11 ---- BodyshopUploader/ViewModels/MainViewModel.cs | 10 ++-- BodyshopUploader/Views/Main.xaml | 6 +-- 7 files changed, 74 insertions(+), 46 deletions(-) diff --git a/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs b/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs index 3e58b03..ee257b2 100644 --- a/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs +++ b/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs @@ -29,6 +29,8 @@ namespace BodyshopPartner.Utils.Decoder string _dir = Path.GetDirectoryName(FilePath) + @"\"; + string system = ParseEnvFile(ref ret, _dir); + ParseAd1File(ref ret, _dir); ParseAd2File(ref ret, _dir); ParseVehFile(ref ret, _dir); @@ -37,11 +39,51 @@ namespace BodyshopPartner.Utils.Decoder ParsePfmFile(ref ret, _dir); ParseStlFile(ref ret, _dir); ParseTtlFile(ref ret, _dir); - ParseLinFile(ref ret, _dir); + ParseLinFile(ref ret, _dir, system); ParsePfpFile(ref ret, _dir); return ret; } + + public static string ParseEnvFile(ref dynamic j, string RootFilePath) + { + if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) + { + return "M"; + } + logger.Trace(@"Parsing Env at: {0}{1}", RootFilePath, j.ciecaid.Value); + + int retryNumber = 0; + while (retryNumber < 11) + { + try + { + using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + ".env", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + var reader = new DBFReader(fis); + + reader.SetSelectFields(new string[] { "EST_SYSTEM" + }); + var readValues = reader.NextRecord(); + + + reader.Dispose(); + + return readValues[0].ToString(); + } + } + catch (IOException ex) + { + logger.Trace(ex, "Unable to open AD1 file. Retrying. "); + retryNumber++; + Thread.Sleep(3000); + + } + } + + return "M"; + } + public static void ParseAd1File(ref dynamic j, string RootFilePath) { if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) @@ -792,7 +834,7 @@ namespace BodyshopPartner.Utils.Decoder } } - public static void ParseLinFile(ref dynamic j, string RootFilePath) + public static void ParseLinFile(ref dynamic j, string RootFilePath, string system) { if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { @@ -818,7 +860,7 @@ namespace BodyshopPartner.Utils.Decoder "WHO_PAYS", "LINE_DESC", "PART_TYPE", - "PART_DESCJ", + system == "M"? "PART_DESCJ" : "PART_DES_J", "GLASS_FLAG", "OEM_PARTNO", "PRICE_INC", @@ -921,7 +963,7 @@ namespace BodyshopPartner.Utils.Decoder dynamic lin = new JObject(); //Mising est_seq - + lin.line_no = readValues[0];//LINE_NO lin.line_ind = readValues[1];//LINE_IND lin.line_ref = readValues[2];//LINE_REF diff --git a/BodyshopUploader/Utils/GraphQL.cs b/BodyshopUploader/Utils/GraphQL.cs index 4bf1f9a..29a6e77 100644 --- a/BodyshopUploader/Utils/GraphQL.cs +++ b/BodyshopUploader/Utils/GraphQL.cs @@ -26,7 +26,8 @@ namespace BodyshopPartner.Utils { using (var g = Utils.GraphQL.CreateGQLClient()) { - logger.Trace("Firing GQL Query: {0} {1}", r.Query.ToString(), r.Variables); + logger.Trace("Firing a GQL Query!"); + // logger.Trace("Firing GQL Query: {0} {1}", r.Query.ToString(), r.Variables); var graphQLResponse = await g.SendQueryAsync(r); if (graphQLResponse.Errors == null) { diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs index 2e90c51..1579b9c 100644 --- a/BodyshopUploader/Utils/HTTPServer.cs +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -49,21 +49,15 @@ namespace BodyshopPartner.Utils catch (Exception Ex) { logger.Fatal("Unable to start HTTP server. " + Ex.ToString()); + hlog("ImEX Online connection server could not start. Please restart the partner to try again."); App.Current.Dispatcher.Invoke(() => { string msg = "Unable to connect to ImEX Online Web App. Please ensure your firewall allows the connection."; - hlog("ImEX Online connection server could not start. Please restart the partner to try again."); - Utils.Notifications.notifier.ShowError(msg); - bool AddedException = Utils.SquirrelAwareHelper.AddHttpExcetion(); - //Growler.AddNotification(new Notification() - //{ - // Title = Properties.Resources.Msg_NewJobUploaded, - // Subtitle = item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value + " | " + item.Job?.clm_no?.Value, - // //Message = item.Job?.vehicle?.data?.v_model_yr?.Value + " " + item.Job?.vehicle?.data?.v_make_desc?.Value + " " + item.Job?.vehicle?.data?.v_model_desc?.Value - //}); + Utils.Notifications.notifier.ShowError(msg); }); Utils.SquirrelAwareHelper.AddHttpExcetion(); + HttpServer.ListenAsync(1337, token, Route.OnHttpRequestAsync).Wait(); } } diff --git a/BodyshopUploader/Utils/JobProcessingQueue.cs b/BodyshopUploader/Utils/JobProcessingQueue.cs index 50327b1..a5ecb79 100644 --- a/BodyshopUploader/Utils/JobProcessingQueue.cs +++ b/BodyshopUploader/Utils/JobProcessingQueue.cs @@ -61,7 +61,8 @@ namespace BodyshopPartner.Utils break; } //Only peek at the first item in the queue so that it does not get added again while it is still getting processed. - item = _jobs.Peek(); + // item = _jobs.Peek(); + item = _jobs.Dequeue(); } try @@ -74,8 +75,11 @@ namespace BodyshopPartner.Utils catch (Exception ex) { ThreadPool.UnsafeQueueUserWorkItem(ProcessQueuedItems, null); - logger.Error(ex, "Error processing job queue item. "); - //throw; + logger.Error("Error processing job queue item. " + ex.ToString()); + } + finally + { + // _jobs.Dequeue(); } } } @@ -146,15 +150,15 @@ namespace BodyshopPartner.Utils var r = new GraphQLRequest { Query = @" -mutation INSERT_AVAILABLE_JOB($jobInput: [available_jobs_insert_input!]!) { - insert_available_jobs(objects: $jobInput, on_conflict: {constraint: available_jobs_clm_no_bodyshopid_key, update_columns: [clm_amt, cieca_id, est_data, issupplement, ownr_name, source_system, supplement_number, vehicle_info]}) { - returning { - id - } - } -} + mutation INSERT_AVAILABLE_JOB($jobInput: [available_jobs_insert_input!]!) { + insert_available_jobs(objects: $jobInput, on_conflict: {constraint: available_jobs_clm_no_bodyshopid_key, update_columns: [clm_amt, cieca_id, est_data, issupplement, ownr_name, source_system, supplement_number, vehicle_info]}) { + returning { + id + } + } + } -", + ", Variables = new { jobInput = newJob, @@ -194,7 +198,7 @@ mutation INSERT_AVAILABLE_JOB($jobInput: [available_jobs_insert_input!]!) { //}); ; }); } - _jobs.Dequeue(); + } } } diff --git a/BodyshopUploader/Utils/SquirrelAwareHelper.cs b/BodyshopUploader/Utils/SquirrelAwareHelper.cs index aaecd53..02d3baf 100644 --- a/BodyshopUploader/Utils/SquirrelAwareHelper.cs +++ b/BodyshopUploader/Utils/SquirrelAwareHelper.cs @@ -33,16 +33,6 @@ namespace BodyshopPartner.Utils logger.Error("Unable to register exception " + Ex.ToString()); return false; } - - - // System.Diagnostics.Process process = new System.Diagnostics.Process(); - // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - // startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - // startInfo.FileName = "cmd.exe"; - // startInfo.Arguments = "netsh http add urlacl url=http://+:1337/ user=\"Everyone\""; - // startInfo.Verb = "runas"; - // process.StartInfo = startInfo; - //return process.Start(); } public static void InitializeSquirrelAware() @@ -59,7 +49,6 @@ namespace BodyshopPartner.Utils { bool successful = AddHttpExcetion(); - if (successful) { logger.Debug("Successfully added exception."); diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs index 5623bc3..5015524 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.cs @@ -49,12 +49,7 @@ namespace BodyshopPartner.ViewModels private void Bw_ProgressChanged(object sender, ProgressChangedEventArgs e) { - Progress = e.ProgressPercentage; - - logger.Trace("Starting monitors if able to."); - if (StartFolderMonitorsCommand.CanExecute(null)) - StartFolderMonitorsCommand.Execute(null); - MonitoringPaths.CollectionChanged += MonitoringPathsChanged; + Progress = e.ProgressPercentage; } private void bw_InitVm(object sender, DoWorkEventArgs e) @@ -70,6 +65,8 @@ namespace BodyshopPartner.ViewModels MonitoringPaths.Add(new Models.Monitor() { FilePath = p }); } + MonitoringPaths.CollectionChanged += MonitoringPathsChanged; + _callingThread.ReportProgress(30); _updateCheckTimer.Elapsed += _updateTimer_Elapsed; @@ -84,6 +81,7 @@ namespace BodyshopPartner.ViewModels logger.Debug("VM Init Complete"); Task.Run(() => Utils.HTTPServer.InitHttpServer(AddHttpStatus)); Task.Run(() => updateCheck()); + StartAllFolderMonitors(); _callingThread.ReportProgress(100); } diff --git a/BodyshopUploader/Views/Main.xaml b/BodyshopUploader/Views/Main.xaml index d9bdb7d..956639a 100644 --- a/BodyshopUploader/Views/Main.xaml +++ b/BodyshopUploader/Views/Main.xaml @@ -148,12 +148,12 @@