IO-233 2 Way Paint Scale.
This commit is contained in:
@@ -7,6 +7,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using System.IO;
|
||||
using System.Timers;
|
||||
using RestSharp;
|
||||
|
||||
namespace BodyshopPartner.Utils
|
||||
{
|
||||
@@ -59,6 +61,106 @@ v_paint_codes
|
||||
}
|
||||
|
||||
";
|
||||
private static Timer MixDataImportTimer = new Timer();
|
||||
|
||||
|
||||
public static void StartMixTimer()
|
||||
{
|
||||
|
||||
MixDataImportTimer.Stop();
|
||||
double Interval =0;
|
||||
|
||||
bool parseSuccesful = double.TryParse(Properties.Settings.Default.PaintScaleImportTimer, out Interval);
|
||||
|
||||
if (parseSuccesful && Interval > 0)
|
||||
{
|
||||
logger.Debug("Starting Mix Data Import timer. ", Interval * 1000 * 60);
|
||||
MixDataImportTimer.Interval = Interval * 1000*60;
|
||||
MixDataImportTimer.Elapsed += MixDataImportTimer_Tick;
|
||||
MixDataImportTimer.Start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static async Task test()
|
||||
{
|
||||
logger.Info("Starting MixData import.");
|
||||
//Check to make sure that the directory exists.
|
||||
Directory.CreateDirectory(Properties.Settings.Default.PaintScaleImportPath);
|
||||
Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.PaintScaleImportPath, "archive"));
|
||||
|
||||
//Check to see if there is a file that exists.
|
||||
string[] fileEntries = Directory.GetFiles(Properties.Settings.Default.PaintScaleImportPath);
|
||||
foreach (string fileName in fileEntries)
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Debug("Reading file in directory: " + fileName);
|
||||
|
||||
RestRequest request = new RestRequest("/mixdata/upload", Method.Post);
|
||||
request.AddHeader("Authorization", "Bearer " + Utils.Auth.authlink.FirebaseToken);
|
||||
request.AddFile("file", fileName);
|
||||
|
||||
request.AddJsonBody(new { bodyshopid = AppMetaData.ActiveShopId });
|
||||
RestResponse _ = await AppMetaData.RestClient.ExecuteAsync(request);
|
||||
|
||||
if (_.IsSuccessful)
|
||||
{
|
||||
logger.Info("Successful upload");
|
||||
string newPath = Path.Combine(Properties.Settings.Default.PaintScaleImportPath, "archive") + @"\\" + DateTime.Now.Ticks + ".xml";
|
||||
File.Move(fileName, newPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Unable to process file " + fileName + ". " + _.ErrorMessage);
|
||||
}
|
||||
}catch (Exception ex)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.PaintScaleImportPath, "errored"));
|
||||
string newPath = Path.Combine(Properties.Settings.Default.PaintScaleImportPath, "errored") + @"\\" + DateTime.Now.Ticks + ".xml";
|
||||
File.Move(fileName, newPath);
|
||||
logger.Error(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async void MixDataImportTimer_Tick(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
logger.Info("Starting MixData import ");
|
||||
//Check to make sure that the directory exists.
|
||||
Directory.CreateDirectory(Properties.Settings.Default.PaintScaleImportPath);
|
||||
Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.PaintScaleImportPath, "archive"));
|
||||
|
||||
//Check to see if there is a file that exists.
|
||||
string[] fileEntries = Directory.GetFiles(Properties.Settings.Default.PaintScaleImportPath);
|
||||
foreach (string fileName in fileEntries)
|
||||
{
|
||||
logger.Debug("Reading file in directory: " + fileName);
|
||||
|
||||
|
||||
|
||||
RestRequest request = new RestRequest("/mixdata/upload",Method.Post);
|
||||
request.AddHeader("Authorization", "Bearer " + Utils.Auth.authlink.FirebaseToken);
|
||||
request.AddFile("file", Path.Combine(Properties.Settings.Default.PaintScaleImportPath, fileName));
|
||||
|
||||
RestResponse _ = await AppMetaData.RestClient.ExecuteAsync(request);
|
||||
|
||||
if (_.IsSuccessful)
|
||||
{
|
||||
logger.Info("Successful upload");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//If a file does exist, read it, and send it up to the API with the Active Shop ID & job.
|
||||
|
||||
//On succesful send, archive the file
|
||||
|
||||
//Make sure the archive directory exists
|
||||
|
||||
//Rename and move the file to the archive directory.
|
||||
}
|
||||
|
||||
public static async Task PushDataToPPG()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user