IO-233 2 Way Paint Scale.
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.IO;
|
||||
|
||||
using RestSharp;
|
||||
namespace BodyshopPartner.Utils
|
||||
{
|
||||
public static class AppMetaData
|
||||
@@ -23,6 +23,9 @@ namespace BodyshopPartner.Utils
|
||||
private static string workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
|
||||
public static string globalScriptsPath = @"C:\ImEX\PartnerScripts";
|
||||
public static RestClient RestClient;
|
||||
|
||||
|
||||
public static void CreateEndpoints()
|
||||
{
|
||||
logger.Debug("Creating endpoints for graphql.");
|
||||
@@ -31,14 +34,18 @@ namespace BodyshopPartner.Utils
|
||||
{
|
||||
#if DEBUG
|
||||
graphQlEndpoint = "https://bodyshop-dev-db.herokuapp.com/v1/graphql";
|
||||
RestClient = new RestClient("http://localhost:4000");
|
||||
FirebaseAPIKey = "AIzaSyDPLT8GiDHDR1R4nI66Qi0BY1aYviDPioc";
|
||||
|
||||
#elif TEST
|
||||
graphQlEndpoint = "https://db.test.bodyshop.app/v1/graphql";
|
||||
RestClient = new RestClient("https://api.test.imex.online");
|
||||
|
||||
FirebaseAPIKey = "AIzaSyBw7_GTy7GtQyfkIRPVrWHEGKfcqeyXw0c";
|
||||
|
||||
#else
|
||||
graphQlEndpoint = "https://db.imex.online/v1/graphql";
|
||||
RestClient = new RestClient("https://api.imex.online");
|
||||
FirebaseAPIKey = "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU";
|
||||
#endif
|
||||
}
|
||||
@@ -49,16 +56,20 @@ namespace BodyshopPartner.Utils
|
||||
IsTest = true;
|
||||
|
||||
graphQlEndpoint = "https://db.test.bodyshop.app/v1/graphql";
|
||||
RestClient = new RestClient("https://api.test.imex.online");
|
||||
FirebaseAPIKey = "AIzaSyBw7_GTy7GtQyfkIRPVrWHEGKfcqeyXw0c";
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
graphQlEndpoint = "https://bodyshop-dev-db.herokuapp.com/v1/graphql";
|
||||
RestClient = new RestClient("http://localhost:4000");
|
||||
FirebaseAPIKey = "AIzaSyDPLT8GiDHDR1R4nI66Qi0BY1aYviDPioc";
|
||||
#else
|
||||
graphQlEndpoint = "https://db.imex.online/v1/graphql";
|
||||
RestClient = new RestClient("https://api.imex.online");
|
||||
FirebaseAPIKey = "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU";
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace BodyshopPartner.Utils
|
||||
await authlink.RefreshUserDetails();
|
||||
authlink.FirebaseAuthRefreshed += Authlink_FirebaseAuthRefreshed;
|
||||
|
||||
logger.Trace("Firebase Auth Token {0}.", authlink.FirebaseToken);
|
||||
logger.Trace("Firebase Auth Token expires in {0} seconds.", authlink.ExpiresIn);
|
||||
//logger.Trace("Firebase Auth Token {0}.", authlink.FirebaseToken);
|
||||
// logger.Trace("Firebase Auth Token expires in {0} seconds.", authlink.ExpiresIn);
|
||||
tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to.
|
||||
logger.Trace("Refresh timer interval set to {0}ms", (authlink.ExpiresIn - 600) * 1000);
|
||||
tokenTimer.Elapsed += TokenTimer_Tick;
|
||||
@@ -81,8 +81,8 @@ namespace BodyshopPartner.Utils
|
||||
|
||||
|
||||
|
||||
logger.Trace("Firebase Auth Token {0}.", authlink.FirebaseToken);
|
||||
logger.Trace("Firebase Auth Token expires in {0} seconds.", authlink.ExpiresIn);
|
||||
// logger.Trace("Firebase Auth Token {0}.", authlink.FirebaseToken);
|
||||
// logger.Trace("Firebase Auth Token expires in {0} seconds.", authlink.ExpiresIn);
|
||||
tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to.
|
||||
logger.Trace("Refresh timer interval set to {0}ms", (authlink.ExpiresIn - 600) * 1000);
|
||||
tokenTimer.Elapsed += TokenTimer_Tick;
|
||||
@@ -119,26 +119,26 @@ namespace BodyshopPartner.Utils
|
||||
|
||||
public static async Task Refresh()
|
||||
{
|
||||
logger.Trace("Old Token {0}", authlink.RefreshToken);
|
||||
//logger.Trace("Old Token {0}", authlink.RefreshToken);
|
||||
await authlink.GetFreshAuthAsync();
|
||||
|
||||
authlink = await ap.RefreshAuthAsync(authlink);
|
||||
logger.Trace("new Token {0}", authlink.FirebaseToken);
|
||||
// logger.Trace("new Token {0}", authlink.FirebaseToken);
|
||||
}
|
||||
|
||||
private static void Authlink_FirebaseAuthRefreshed(object sender, FirebaseAuthEventArgs e)
|
||||
{
|
||||
logger.Debug("Auth token refreshed!");
|
||||
logger.Debug("New token: {0}", e.FirebaseAuth.FirebaseToken);
|
||||
// logger.Debug("Auth token refreshed!");
|
||||
// logger.Debug("New token: {0}", e.FirebaseAuth.FirebaseToken);
|
||||
}
|
||||
|
||||
private static async Task RefreshToken()
|
||||
{
|
||||
//Gotta do some stuff now that i got a new token!
|
||||
//Maybe the token auto refreshes?
|
||||
logger.Info("Timer Old Token {0}", authlink.FirebaseToken);
|
||||
// logger.Info("Timer Old Token {0}", authlink.FirebaseToken);
|
||||
authlink = await authlink.GetFreshAuthAsync();
|
||||
logger.Info("new Token {0}", authlink.FirebaseToken);
|
||||
// logger.Info("new Token {0}", authlink.FirebaseToken);
|
||||
tokenTimer.Stop();
|
||||
tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to.
|
||||
tokenTimer.Start();
|
||||
|
||||
@@ -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