Added base decoding logic + notification logic.
This commit is contained in:
249
BodyshopUploader/Utils/Decoder/EstimateDecoder.cs
Normal file
249
BodyshopUploader/Utils/Decoder/EstimateDecoder.cs
Normal file
@@ -0,0 +1,249 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DotNetDBF;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BodyshopUploader.Utils.Decoder
|
||||
{
|
||||
class EstimateDecoder
|
||||
{
|
||||
public static class CIECAEstimateImport
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
/// Decode the set of estimate files based on the creation of an envelope file.
|
||||
/// </summary>
|
||||
/// <param name="FilePath">Full path to the envelope file that was created/updated.</param>
|
||||
/// <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);
|
||||
|
||||
string _dir = Path.GetDirectoryName(FilePath) + @"\";
|
||||
|
||||
ParseAd1File(ref ret, _dir);
|
||||
ParseVehFile(ref ret, _dir);
|
||||
ParseStlFile(ref ret, _dir);
|
||||
ParseTtlFile(ref ret, _dir);
|
||||
ParseLinFile(ref ret, _dir);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void ParseAd1File(ref dynamic j, string RootFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(j.CiecaId.Value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
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))
|
||||
{
|
||||
var reader = new DBFReader(fis);
|
||||
reader.SetSelectFields(new string[] { "INS_CO_NM", "CLM_NO", "OWNR_LN", "OWNR_FN", "OWNR_EA", "OWNR_PH1" });
|
||||
var readValues = reader.NextRecord();
|
||||
j.Claim_Source = readValues[0].ToString();
|
||||
j.Claim_Number = readValues[1].ToString();
|
||||
j.Owner_Ln = readValues[2].ToString();
|
||||
j.Owner_Fn = readValues[3].ToString();
|
||||
j.Owner_Email = readValues[4].ToString();
|
||||
j.Owner_Phone = readValues[5].ToString();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.Trace(ex, "Unable to open AD1 file. Retrying. ");
|
||||
retryNumber++;
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void ParseVehFile(ref dynamic j, string RootFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
|
||||
|
||||
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))
|
||||
{
|
||||
var reader = new DBFReader(fis);
|
||||
reader.SetSelectFields(new string[] { "V_MODEL_YR", "V_MAKEDESC", "V_MODEL", "V_COLOR", "PLATE_NO", "V_VIN" });
|
||||
var readValues = reader.NextRecord();
|
||||
j.V_Model_Yr = readValues[0].ToString();
|
||||
j.V_Make_Desc = readValues[1].ToString();
|
||||
j.V_Model = readValues[2].ToString();
|
||||
j.V_Color = readValues[3].ToString();
|
||||
j.Lic_Plate = readValues[4].ToString();
|
||||
j.V_Vin = readValues[5].ToString();
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.Trace(ex, "Unable to open VEH file. Retrying. ");
|
||||
retryNumber++;
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ParseTtlFile(ref dynamic j, string RootFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
|
||||
|
||||
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.CiecaId.Value);
|
||||
|
||||
|
||||
|
||||
int retryNumber = 0;
|
||||
while (retryNumber < 11)
|
||||
{
|
||||
try
|
||||
{
|
||||
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" });
|
||||
var readValues = reader.NextRecord();
|
||||
j.Claim_Total = Convert.ToDecimal(readValues[0].ToString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.Trace(ex, "Unable to open TTL file. Retrying. ");
|
||||
retryNumber++;
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ParseStlFile(ref dynamic j, string RootFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
|
||||
|
||||
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.CiecaId.Value);
|
||||
|
||||
|
||||
|
||||
int retryNumber = 0;
|
||||
while (retryNumber < 11)
|
||||
{
|
||||
try
|
||||
{
|
||||
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" });
|
||||
var _rc = reader.RecordCount;
|
||||
for (var i = 0; i < _rc; i++)
|
||||
{
|
||||
var readValues = reader.NextRecord();
|
||||
switch (readValues[0])
|
||||
{
|
||||
|
||||
//Labor Code
|
||||
case "LAB":
|
||||
j.BodyHrs = Convert.ToDecimal(readValues[1]);
|
||||
break;
|
||||
case "LAR":
|
||||
j.RefHrs = Convert.ToDecimal(readValues[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.Trace(ex, "Unable to open STL file. Retrying. ");
|
||||
retryNumber++;
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void ParseLinFile(ref dynamic j, string RootFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(j.CiecaId.Value)) { return; }
|
||||
|
||||
logger.Trace(@"Parsing Ttl at: {0}{1}", RootFilePath, j.CiecaId.Value);
|
||||
//j.JobSublets = new List<JobSublet>();
|
||||
|
||||
string _maxSupp = "";
|
||||
|
||||
int retryNumber = 0;
|
||||
while (retryNumber < 11)
|
||||
{
|
||||
try
|
||||
{
|
||||
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" });
|
||||
var _rc = reader.RecordCount;
|
||||
for (var i = 0; i < _rc; i++)
|
||||
{
|
||||
var readValues = reader.NextRecord();
|
||||
//Find Max Supplement Number
|
||||
if (string.Compare(_maxSupp, readValues[3].ToString()) < 0)
|
||||
{
|
||||
_maxSupp = readValues[3].ToString();
|
||||
}
|
||||
|
||||
switch (readValues[3])
|
||||
{
|
||||
|
||||
//Labor Code
|
||||
case "PAS":
|
||||
case "PASL":
|
||||
//j.JobSublets.Add(new JobSublet()
|
||||
//{
|
||||
// SubletDesc = readValues[1].ToString(),
|
||||
// Unq_Seq = Convert.ToInt32(readValues[2])
|
||||
//});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
j.MaxSupplement = _maxSupp;
|
||||
return;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.Trace(ex, "Unable to open LIN file. Retrying. ");
|
||||
retryNumber++;
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user