Created monitoring object and refactored code accordingly.

This commit is contained in:
Patrick Fic
2020-01-17 14:19:49 -08:00
parent 3357a8a564
commit b7218b6771
16 changed files with 217 additions and 76 deletions

View File

@@ -7,6 +7,7 @@ using System.Threading;
using System.Threading.Tasks;
using BodyshopUploader.Utils;
using BodyshopUploader.Models;
using BodyshopUploader.Utils.Growls;
namespace BodyshopUploader.Utils
{
@@ -15,6 +16,12 @@ namespace BodyshopUploader.Utils
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static Queue<DTO_QueueItem> _jobs = new Queue<DTO_QueueItem>();
private static bool _delegateQueuedOrRunning = false;
private static GrowlNotification Growler;
public static void SetGrowler(GrowlNotification g)
{
Growler = g;
}
public static void Enqueue(DTO_QueueItem item)
{
@@ -60,9 +67,10 @@ namespace BodyshopUploader.Utils
DecodeQueueItemJob(item);
UpsertQueueItem(item);
}
catch
catch (Exception ex)
{
ThreadPool.UnsafeQueueUserWorkItem(ProcessQueuedItems, null);
logger.Error(ex, "Error processing job queue item. ");
throw;
}
}
@@ -79,7 +87,17 @@ namespace BodyshopUploader.Utils
{
//Save the job to the DB.
logger.Info("Should upsert the job graphqlly here. {0}", item.Job);
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Title = Properties.Resources.Msg_NewJobUploaded,
Subtitle = item.Job?.owner?.first_name?.Value + " " + item.Job?.owner?.last_name?.Value,
Message = item.Job?.vehicle?.v_model_yr?.Value + " " + item.Job?.vehicle?.v_make_desc?.Value + " " + item.Job?.vehicle?.v_model_desc?.Value
});
});
_jobs.Dequeue();
}