Added new notification nuget. Added auto regenerate JWT token on error.

This commit is contained in:
Patrick Fic
2020-07-24 11:14:51 -07:00
parent e8c58dab2f
commit 32ec745c77
8 changed files with 123 additions and 48 deletions

View File

@@ -34,8 +34,18 @@ namespace BodyshopPartner.Utils
else
{
string exceptionString = "";
bool jwtExpired = false;
logger.Error("Error executing query.");
Array.ForEach(graphQLResponse.Errors, x => { logger.Error(x.Message); exceptionString = exceptionString + x + ";"; });
Array.ForEach(graphQLResponse.Errors, x =>
{
logger.Error(x.Message);
if (x.Message.Contains("JWTExpired"))
{
jwtExpired = true;
};
exceptionString = exceptionString + x + ";";
});
if (jwtExpired) await Utils.Auth.Refresh(); ;
logger.Error("---------------------");
throw new Exception(exceptionString);
}

View File

@@ -10,6 +10,7 @@ using BodyshopPartner.Models;
using BodyshopPartner.Utils.Growls;
using GraphQL.Common.Request;
using Newtonsoft.Json.Linq;
using ToastNotifications.Messages;
namespace BodyshopPartner.Utils
{
@@ -159,12 +160,14 @@ namespace BodyshopPartner.Utils
logger.Trace("Job insert succesful. Show notification");
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Title = Properties.Resources.Msg_NewJobUploaded,
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
});
string msg = Properties.Resources.Msg_NewJobUploaded + " " + item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value + " | " + item.Job?.clm_no?.Value;
Utils.Notifications.notifier.ShowSuccess(msg);
//Growler.AddNotification(new Notification()
//{
// Title = Properties.Resources.Msg_NewJobUploaded,
// 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
//});
});
}
@@ -174,12 +177,14 @@ namespace BodyshopPartner.Utils
//Succesful upsert
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Title = Properties.Resources.Msg_NewJobUploadError,
Subtitle = item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value,
Message = Ex.Message
}); ;
string msg = Properties.Resources.Msg_NewJobUploadError + " " + item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value + Ex.Message;
Notifications.notifier.ShowError(msg);
//Growler.AddNotification(new Notification()
//{
// Title = Properties.Resources.Msg_NewJobUploadError,
// Subtitle = item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value,
// Message = Ex.Message
//}); ;
});
}
_jobs.Dequeue();

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ToastNotifications;
using ToastNotifications.Lifetime;
using ToastNotifications.Position;
using ToastNotifications.Messages;
using System.Windows;
namespace BodyshopPartner.Utils
{
public static class Notifications
{
public static Notifier notifier = new Notifier(cfg =>
{
cfg.PositionProvider = new PrimaryScreenPositionProvider(
corner: Corner.BottomRight,
offsetX: 10,
offsetY: 10);
/* * */
cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(
notificationLifetime: TimeSpan.FromSeconds(3),
maximumNotificationCount: MaximumNotificationCount.FromCount(5));
cfg.Dispatcher = Application.Current.Dispatcher;
});
}
}

View File

@@ -9,6 +9,7 @@ using System.Xml.Linq;
using BodyshopPartner.Utils.Growls;
using Interop.QBFC13;
using Interop.QBXMLRP2;
using ToastNotifications.Messages;
namespace BodyshopPartner.Utils
{
@@ -26,7 +27,7 @@ namespace BodyshopPartner.Utils
public static void ConnectToQuickBooks()
{
if(String.IsNullOrWhiteSpace(Properties.Settings.Default.QuickBooksFilePath) || !File.Exists(Properties.Settings.Default.QuickBooksFilePath))
if (String.IsNullOrWhiteSpace(Properties.Settings.Default.QuickBooksFilePath) || !File.Exists(Properties.Settings.Default.QuickBooksFilePath))
{
throw new Exception("The QuickBooks file specified does not exist.");
}
@@ -35,12 +36,15 @@ namespace BodyshopPartner.Utils
logger.Debug("Attempting to connect to QuickBooks...");
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Id = new Random().Next(),
Title = Properties.Resources.Msg_QbConnection_Title,
Message = Properties.Resources.Msg_QbConnection_Msg
});
string msg = Properties.Resources.Msg_QbConnection_Title + " " + Properties.Resources.Msg_QbConnection_Msg;
Notifications.notifier.ShowInformation(msg);
//Growler.AddNotification(new Notification()
//{
// Id = new Random().Next(),
// Title = Properties.Resources.Msg_QbConnection_Title,
// Message = Properties.Resources.Msg_QbConnection_Msg
//});
});
rp = new RequestProcessor2Class();
@@ -52,18 +56,21 @@ namespace BodyshopPartner.Utils
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Id = new Random().Next(),
Title = Properties.Resources.Msg_QbConnected_Title,
Message = Properties.Resources.Msg_QbConnected_Msg
});
string msg = Properties.Resources.Msg_QbConnected_Title + " " + Properties.Resources.Msg_QbConnected_Msg;
Notifications.notifier.ShowInformation(msg);
//Growler.AddNotification(new Notification()
//{
// Id = new Random().Next(),
// Title = Properties.Resources.Msg_QbConnected_Title,
// Message = Properties.Resources.Msg_QbConnected_Msg
//});
});
}
catch (Exception ex)
{
logger.Error(ex);
if(ex.Message.Contains("80040154 Class not registered"))
if (ex.Message.Contains("80040154 Class not registered"))
{
logger.Error("QuickBooks Request Processor not registered. Is QuickBooks installed on this computer?");
throw new Exception("QuickBooks Request Processor not registered. Is QuickBooks installed on this computer?");
@@ -83,12 +90,16 @@ namespace BodyshopPartner.Utils
rp.CloseConnection();
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Id = new Random().Next(),
Title = Properties.Resources.Msg_QbDisconnection_Title,
Message = Properties.Resources.Msg_QbDisconnection_Msg
});
string msg = Properties.Resources.Msg_QbDisconnection_Title + " " + Properties.Resources.Msg_QbDisconnection_Msg;
Notifications.notifier.ShowSuccess(msg);
//Growler.AddNotification(new Notification()
//{
// Id = new Random().Next(),
// Title = Properties.Resources.Msg_QbDisconnection_Title,
// Message = Properties.Resources.Msg_QbDisconnection_Msg
//});
});
logger.Debug("Disconnected from QuickBooks successfully.");
}