Added creation of owner object. Vehicle addition now dynamic based on presence of VIN.
This commit is contained in:
@@ -282,6 +282,7 @@
|
|||||||
<Compile Include="Utils\JobProcessingQueue.cs" />
|
<Compile Include="Utils\JobProcessingQueue.cs" />
|
||||||
<Compile Include="Utils\JsonConverter.cs" />
|
<Compile Include="Utils\JsonConverter.cs" />
|
||||||
<Compile Include="Utils\LoginHelpers.cs" />
|
<Compile Include="Utils\LoginHelpers.cs" />
|
||||||
|
<Compile Include="Utils\Queries\VehicleQueries.cs" />
|
||||||
<Compile Include="Utils\RelayCommand.cs" />
|
<Compile Include="Utils\RelayCommand.cs" />
|
||||||
<Compile Include="Utils\TrayIcon.cs" />
|
<Compile Include="Utils\TrayIcon.cs" />
|
||||||
<Compile Include="Utils\UiConverters.cs" />
|
<Compile Include="Utils\UiConverters.cs" />
|
||||||
|
|||||||
@@ -14,9 +14,13 @@ namespace BodyshopUploader.Utils
|
|||||||
public static FirebaseAuthLink authlink;
|
public static FirebaseAuthLink authlink;
|
||||||
static FirebaseAuthProvider ap = new FirebaseAuthProvider(new FirebaseConfig(Utils.AppMetaData.FirebaseAPIKey_DEV)); //TODO: Update this to be a dynamic key. Perhaps a function that fetches?
|
static FirebaseAuthProvider ap = new FirebaseAuthProvider(new FirebaseConfig(Utils.AppMetaData.FirebaseAPIKey_DEV)); //TODO: Update this to be a dynamic key. Perhaps a function that fetches?
|
||||||
private static Timer tokenTimer = new Timer();
|
private static Timer tokenTimer = new Timer();
|
||||||
|
private static string U;
|
||||||
|
private static string P;
|
||||||
|
|
||||||
public async static Task<(bool, string)> LoginAsync(string Username, string Password)
|
public async static Task<(bool, string)> LoginAsync(string Username, string Password)
|
||||||
{
|
{
|
||||||
|
U = Username;
|
||||||
|
P = Password;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
authlink = await ap.SignInWithEmailAndPasswordAsync(Username, Password);
|
authlink = await ap.SignInWithEmailAndPasswordAsync(Username, Password);
|
||||||
@@ -26,7 +30,6 @@ namespace BodyshopUploader.Utils
|
|||||||
logger.Trace("Firebase Refresh Token {0}.", authlink.RefreshToken);
|
logger.Trace("Firebase Refresh Token {0}.", authlink.RefreshToken);
|
||||||
logger.Trace("Firebase Auth Token expires in {0} seconds.", authlink.ExpiresIn);
|
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.
|
tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to.
|
||||||
//tokenTimer.Interval = 10000; //Set the token to refresh 10 minutes before it has to.
|
|
||||||
logger.Trace("Refresh timer interval set to {0}ms", (authlink.ExpiresIn - 600) * 1000);
|
logger.Trace("Refresh timer interval set to {0}ms", (authlink.ExpiresIn - 600) * 1000);
|
||||||
tokenTimer.Elapsed += TokenTimer_Tick;
|
tokenTimer.Elapsed += TokenTimer_Tick;
|
||||||
tokenTimer.Start();
|
tokenTimer.Start();
|
||||||
@@ -73,17 +76,21 @@ namespace BodyshopUploader.Utils
|
|||||||
logger.Debug("New token: {0}", e.FirebaseAuth.FirebaseToken);
|
logger.Debug("New token: {0}", e.FirebaseAuth.FirebaseToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TokenTimer_Tick(object sender, ElapsedEventArgs e)
|
private static async Task RefreshToken()
|
||||||
{
|
{
|
||||||
//Gotta do some stuff now that i got a new token!
|
//Gotta do some stuff now that i got a new token!
|
||||||
//Maybe the token auto refreshes?
|
//Maybe the token auto refreshes?
|
||||||
logger.Info("Timer Old Token {0}", authlink.FirebaseToken);
|
logger.Info("Timer Old Token {0}", authlink.FirebaseToken);
|
||||||
//await authlink.RefreshUserDetails();
|
authlink = await ap.SignInWithEmailAndPasswordAsync(U, P);
|
||||||
//logger.Info("new Token {0}", authlink.FirebaseToken);
|
logger.Info("new Token {0}", authlink.FirebaseToken);
|
||||||
//tokenTimer.Stop();
|
tokenTimer.Stop();
|
||||||
//tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to.
|
tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to.
|
||||||
//tokenTimer.Interval = 10000;
|
tokenTimer.Start();
|
||||||
//tokenTimer.Start();
|
}
|
||||||
|
|
||||||
|
private static async void TokenTimer_Tick(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
await RefreshToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ namespace BodyshopUploader.Utils.Decoder
|
|||||||
});
|
});
|
||||||
var readValues = reader.NextRecord();
|
var readValues = reader.NextRecord();
|
||||||
|
|
||||||
|
dynamic o = new JObject();
|
||||||
|
|
||||||
|
|
||||||
j.ins_co_id = readValues[0]?.ToString();
|
j.ins_co_id = readValues[0]?.ToString();
|
||||||
j.ins_co_nm = readValues[1]?.ToString();
|
j.ins_co_nm = readValues[1]?.ToString();
|
||||||
j.ins_addr1 = readValues[2]?.ToString();
|
j.ins_addr1 = readValues[2]?.ToString();
|
||||||
@@ -166,11 +169,11 @@ namespace BodyshopUploader.Utils.Decoder
|
|||||||
j.ownr_zip = readValues[93]?.ToString();
|
j.ownr_zip = readValues[93]?.ToString();
|
||||||
j.ownr_ctry = readValues[94]?.ToString();
|
j.ownr_ctry = readValues[94]?.ToString();
|
||||||
j.ownr_ph1 = readValues[95]?.ToString();
|
j.ownr_ph1 = readValues[95]?.ToString();
|
||||||
j.ownr_ph1x = readValues[96]?.ToString();
|
//j.ownr_ph1x = readValues[96]?.ToString();
|
||||||
j.ownr_ph2 = readValues[97]?.ToString();
|
j.ownr_ph2 = readValues[97]?.ToString();
|
||||||
j.ownr_ph2x = readValues[98]?.ToString();
|
// j.ownr_ph2x = readValues[98]?.ToString();
|
||||||
j.ownr_fax = readValues[99]?.ToString();
|
//j.ownr_fax = readValues[99]?.ToString();
|
||||||
j.ownr_faxx = readValues[100]?.ToString();
|
//j.ownr_faxx = readValues[100]?.ToString();
|
||||||
j.ownr_ea = readValues[101]?.ToString();
|
j.ownr_ea = readValues[101]?.ToString();
|
||||||
j.ins_ph1 = readValues[102]?.ToString();
|
j.ins_ph1 = readValues[102]?.ToString();
|
||||||
j.ins_ph1x = readValues[103]?.ToString();
|
j.ins_ph1x = readValues[103]?.ToString();
|
||||||
@@ -186,6 +189,24 @@ namespace BodyshopUploader.Utils.Decoder
|
|||||||
j.loss_cat = readValues[113]?.ToString();
|
j.loss_cat = readValues[113]?.ToString();
|
||||||
j.shopid = AppMetaData.ActiveShopId;
|
j.shopid = AppMetaData.ActiveShopId;
|
||||||
|
|
||||||
|
//Set Owner Record
|
||||||
|
o.ownr_ln = readValues[85]?.ToString();
|
||||||
|
o.ownr_fn = readValues[86]?.ToString();
|
||||||
|
o.ownr_title = readValues[87]?.ToString();
|
||||||
|
o.ownr_co_nm = readValues[88]?.ToString();
|
||||||
|
o.ownr_addr1 = readValues[89]?.ToString();
|
||||||
|
o.ownr_addr2 = readValues[90]?.ToString();
|
||||||
|
o.ownr_city = readValues[91]?.ToString();
|
||||||
|
o.ownr_st = readValues[92]?.ToString();
|
||||||
|
o.ownr_zip = readValues[93]?.ToString();
|
||||||
|
o.ownr_ctry = readValues[94]?.ToString();
|
||||||
|
o.ownr_ph1 = readValues[95]?.ToString();
|
||||||
|
o.ownr_ph2 = readValues[97]?.ToString();
|
||||||
|
o.ownr_ea = readValues[101]?.ToString();
|
||||||
|
o.shopid = AppMetaData.ActiveShopId;
|
||||||
|
|
||||||
|
j.owner = new JObject();
|
||||||
|
j.owner.data = o;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,7 +411,7 @@ namespace BodyshopUploader.Utils.Decoder
|
|||||||
"V_MAKECODE",
|
"V_MAKECODE",
|
||||||
"V_MAKEDESC",
|
"V_MAKEDESC",
|
||||||
"V_MODEL",
|
"V_MODEL",
|
||||||
"V_TYPE", //
|
"V_TYPE",
|
||||||
"V_BSTYLE",
|
"V_BSTYLE",
|
||||||
"V_TRIMCODE",
|
"V_TRIMCODE",
|
||||||
"TRIM_COLOR",
|
"TRIM_COLOR",
|
||||||
|
|||||||
@@ -103,15 +103,23 @@ namespace BodyshopUploader.Utils
|
|||||||
//};
|
//};
|
||||||
|
|
||||||
//Add to Holding Queue
|
//Add to Holding Queue
|
||||||
|
|
||||||
dynamic newJob = new JObject();
|
dynamic newJob = new JObject();
|
||||||
newJob.uploaded_by = Auth.authlink.User.Email;
|
newJob.uploaded_by = Auth.authlink.User.Email;
|
||||||
newJob.bodyshopid = AppMetaData.ActiveShopId;
|
newJob.bodyshopid = AppMetaData.ActiveShopId;
|
||||||
newJob.cieca_id = item.Job.ciecaid;
|
newJob.cieca_id = item.Job.ciecaid;
|
||||||
newJob.est_data = item.Job;
|
newJob.est_data = item.Job;
|
||||||
newJob.ownr_name = item.Job.ownr_fn + " " + item.Job.ownr_ln;
|
newJob.ownr_name = item.Job.ownr_fn.Value + " " + item.Job.ownr_ln.Value;
|
||||||
newJob.vehicle_info = item.Job.vehicle.v_model_yr + " " + item.Job.vehicle.v_make_desc + " " + item.Job.vehicle.v_model_desc;
|
newJob.vehicle_info = item.Job.vehicle.data.v_model_yr.Value + " " + item.Job.vehicle.data.v_make_desc.Value + " " + item.Job.vehicle.data.v_model_desc.Value;
|
||||||
newJob.clm_no = item.Job.clm_no;
|
newJob.clm_no = item.Job.clm_no.Value;
|
||||||
|
var vv = item.Job.vehicle.data.v_vin.Value;
|
||||||
|
|
||||||
|
//TODO: This should perform some sort of upsert to update the vehicle with more up to date information.
|
||||||
|
var vehuuid = await Utils.Queries.VehicleQueries.GetVehicleUuidByVin(vv) ;
|
||||||
|
if (!string.IsNullOrEmpty(vehuuid))
|
||||||
|
{
|
||||||
|
newJob.est_data.vehicle = null;
|
||||||
|
newJob.est_data.vehicleid = vehuuid;
|
||||||
|
}
|
||||||
|
|
||||||
var r = new GraphQLRequest
|
var r = new GraphQLRequest
|
||||||
{
|
{
|
||||||
@@ -139,7 +147,7 @@ namespace BodyshopUploader.Utils
|
|||||||
{
|
{
|
||||||
Title = Properties.Resources.Msg_NewJobUploaded,
|
Title = Properties.Resources.Msg_NewJobUploaded,
|
||||||
Subtitle = item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value + " | " + item.Job?.clm_no?.Value,
|
Subtitle = item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value + " | " + item.Job?.clm_no?.Value,
|
||||||
Message = item.Job?.vehicle?.data.v_model_yr?.Value + " " + item.Job?.vehicle?.data.v_make_desc?.Value + " " + item.Job?.vehicle?.data.v_model_desc?.Value
|
//Message = item.Job?.vehicle?.data?.v_model_yr?.Value + " " + item.Job?.vehicle?.data?.v_make_desc?.Value + " " + item.Job?.vehicle?.data?.v_model_desc?.Value
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
45
BodyshopUploader/Utils/Queries/VehicleQueries.cs
Normal file
45
BodyshopUploader/Utils/Queries/VehicleQueries.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using GraphQL.Common.Request;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BodyshopUploader.Utils.Queries
|
||||||
|
{
|
||||||
|
public static class VehicleQueries
|
||||||
|
{
|
||||||
|
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public static async Task<string> GetVehicleUuidByVin(string vin)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(vin))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var r = new GraphQLRequest
|
||||||
|
{
|
||||||
|
Query = @"query QUERY_VEHICLE_BY_VIN($vin: String!) {
|
||||||
|
vehicles(where: {v_vin: {_eq: $vin}}) {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}",
|
||||||
|
Variables = new
|
||||||
|
{
|
||||||
|
vin = vin
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var d = await Utils.GraphQL.ExecuteQuery(r);
|
||||||
|
return d.vehicles?[0].id?.Value;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception Ex)
|
||||||
|
{
|
||||||
|
logger.Error(Ex, "Querying for vehicle by VIN failed.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user