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

@@ -43,7 +43,7 @@ namespace BodyshopUploader.Utils
//Deleted += Watcher_Deleted;
//Renamed += Watcher_Renamed;
Error += Wathcer_Error;
logger.Debug("CIECA Folder watcher started for path: {0}", Path);
logger.Debug("CIECA Folder watcher initialized for path: {0}", Path);
}
private void Wathcer_Error(object sender, ErrorEventArgs e)

View File

@@ -23,11 +23,9 @@ namespace BodyshopUploader.Utils.Decoder
/// <returns></returns>
public static dynamic DecodeEstimate(string FilePath)
{
//Sleep the thread so that all files can finish writing.
Thread.Sleep(1000);
dynamic ret = new JObject();
ret.CiecaId = Path.GetFileNameWithoutExtension(FilePath);
ret.ciecaid = Path.GetFileNameWithoutExtension(FilePath);
string _dir = Path.GetDirectoryName(FilePath) + @"\";
@@ -42,18 +40,18 @@ namespace BodyshopUploader.Utils.Decoder
public static void ParseAd1File(ref dynamic j, string RootFilePath)
{
if (string.IsNullOrWhiteSpace(j.CiecaId.Value))
if (string.IsNullOrWhiteSpace(j.ciecaid.Value))
{
return;
}
logger.Trace(@"Parsing AD1 at: {0}{1}", RootFilePath, j.CiecaId.Value);
logger.Trace(@"Parsing AD1 at: {0}{1}", RootFilePath, j.ciecaid.Value);
int retryNumber = 0;
while (retryNumber < 11)
{
try
{
using (Stream fis = File.Open(RootFilePath + j.CiecaId.Value + "A.ad1", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + "A.ad1", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var reader = new DBFReader(fis);
reader.SetSelectFields(new string[] { "INS_CO_NM", "CLM_NO", "OWNR_LN", "OWNR_FN", "OWNR_EA", "OWNR_PH1" });
@@ -80,16 +78,16 @@ namespace BodyshopUploader.Utils.Decoder
public static void ParseVehFile(ref dynamic j, string RootFilePath)
{
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
logger.Trace(@"Parsing Veh at: {0}{1}", RootFilePath, j.CiecaId.Value);
logger.Trace(@"Parsing Veh at: {0}{1}", RootFilePath, j.ciecaid.Value);
int retryNumber = 0;
while (retryNumber < 11)
{
try
{
using (Stream fis = File.Open(RootFilePath + j.CiecaId.Value + "v.veh", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + "v.veh", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var reader = new DBFReader(fis);
reader.SetSelectFields(new string[] { "V_MODEL_YR", "V_MAKEDESC", "V_MODEL", "V_COLOR", "PLATE_NO", "V_VIN" });
@@ -115,9 +113,9 @@ namespace BodyshopUploader.Utils.Decoder
public static void ParseTtlFile(ref dynamic j, string RootFilePath)
{
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.CiecaId.Value);
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.ciecaid.Value);
@@ -126,7 +124,7 @@ namespace BodyshopUploader.Utils.Decoder
{
try
{
using (Stream fis = File.Open(RootFilePath + j.CiecaId.Value + ".ttl", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + ".ttl", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var reader = new DBFReader(fis);
reader.SetSelectFields(new string[] { "G_TTL_AMT" });
@@ -146,9 +144,9 @@ namespace BodyshopUploader.Utils.Decoder
public static void ParseStlFile(ref dynamic j, string RootFilePath)
{
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.CiecaId.Value);
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.ciecaid.Value);
@@ -157,7 +155,7 @@ namespace BodyshopUploader.Utils.Decoder
{
try
{
using (Stream fis = File.Open(RootFilePath + j.CiecaId.Value + ".stl", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + ".stl", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var reader = new DBFReader(fis);
reader.SetSelectFields(new string[] { "TTL_TYPECD", "T_HRS" });
@@ -192,9 +190,9 @@ namespace BodyshopUploader.Utils.Decoder
public static void ParseLinFile(ref dynamic j, string RootFilePath)
{
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
if (string.IsNullOrWhiteSpace(j.ciecaid.Value)) { return; }
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.CiecaId.Value);
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.ciecaid.Value);
//j.JobSublets = new List<JobSublet>();
string _maxSupp = "";
@@ -204,7 +202,7 @@ namespace BodyshopUploader.Utils.Decoder
{
try
{
using (Stream fis = File.Open(RootFilePath + j.CiecaId.Value + ".lin", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (Stream fis = File.Open(RootFilePath + j.ciecaid.Value + ".lin", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var reader = new DBFReader(fis);
reader.SetSelectFields(new string[] { "PART_TYPE", "LINE_DESC", "UNQ_SEQ", "LINE_IND" });

View File

@@ -6,13 +6,11 @@
xmlns:local="clr-namespace:BodyshopUploader.Utils.Growls"
mc:Ignorable="d"
SizeToContent="WidthAndHeight"
AllowsTransparency="True"
WindowStyle="None"
ShowInTaskbar="False"
Topmost="True"
UseLayoutRounding="True"
Title="BodyshopUploader Notification"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
@@ -37,9 +35,9 @@
Background="Transparent"
SizeChanged="NotificationWindowSizeChanged">
<Border Name="border"
Background="#2a3345"
Background="#808080"
BorderThickness="0"
CornerRadius="10"
CornerRadius="4"
Margin="10">
<Border.Effect>
<DropShadowEffect ShadowDepth="0"
@@ -128,8 +126,8 @@
From="1"
To="0"
Storyboard.TargetProperty="Opacity"
Duration="0:0:2"
BeginTime="0:0:3" />
Duration="0:0:1"
BeginTime="0:0:2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>

View File

@@ -36,19 +36,6 @@ namespace BodyshopUploader.Utils.Growls
}
}
private int threadid;
public int ThreadId
{
get { return threadid; }
set
{
if (threadid == value) return;
threadid = value;
OnPropertyChanged("ThreadId");
}
}
private string imageUrl;
public string ImageUrl
{

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();
}