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

@@ -3,15 +3,17 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BodyshopPartner" xmlns:local="clr-namespace:BodyshopPartner"
ShutdownMode="OnExplicitShutdown" ShutdownMode="OnExplicitShutdown"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
Exit="Application_Exit" Exit="Application_Exit"
StartupUri="Views\Login.xaml"> StartupUri="Views\Login.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" /> <ResourceDictionary Source="pack://application:,,,/ToastNotifications.Messages;component/Themes/Default.xaml" />
<materialDesign:BundledTheme BaseTheme="Light"
PrimaryColor="Grey"
SecondaryColor="LightBlue" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Indigo.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>

View File

@@ -314,6 +314,12 @@
<Private>True</Private> <Private>True</Private>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="ToastNotifications, Version=2.5.1.0, Culture=neutral, PublicKeyToken=e89d9d7314a7c797, processorArchitecture=MSIL">
<HintPath>..\packages\ToastNotifications.2.5.1\lib\net40\ToastNotifications.dll</HintPath>
</Reference>
<Reference Include="ToastNotifications.Messages, Version=2.5.1.0, Culture=neutral, PublicKeyToken=e89d9d7314a7c797, processorArchitecture=MSIL">
<HintPath>..\packages\ToastNotifications.Messages.2.5.1\lib\net40\ToastNotifications.Messages.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
@@ -359,6 +365,7 @@
<Compile Include="Utils\JsonConverter.cs" /> <Compile Include="Utils\JsonConverter.cs" />
<Compile Include="Utils\JsonExtensions.cs" /> <Compile Include="Utils\JsonExtensions.cs" />
<Compile Include="Utils\LoginHelpers.cs" /> <Compile Include="Utils\LoginHelpers.cs" />
<Compile Include="Utils\Notifications.cs" />
<Compile Include="Utils\Queries\JobsQueries.cs" /> <Compile Include="Utils\Queries\JobsQueries.cs" />
<Compile Include="Utils\Queries\VehicleQueries.cs" /> <Compile Include="Utils\Queries\VehicleQueries.cs" />
<Compile Include="Utils\QuickBooksInterop.cs" /> <Compile Include="Utils\QuickBooksInterop.cs" />

View File

@@ -34,8 +34,18 @@ namespace BodyshopPartner.Utils
else else
{ {
string exceptionString = ""; string exceptionString = "";
bool jwtExpired = false;
logger.Error("Error executing query."); 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("---------------------"); logger.Error("---------------------");
throw new Exception(exceptionString); throw new Exception(exceptionString);
} }

View File

@@ -10,6 +10,7 @@ using BodyshopPartner.Models;
using BodyshopPartner.Utils.Growls; using BodyshopPartner.Utils.Growls;
using GraphQL.Common.Request; using GraphQL.Common.Request;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using ToastNotifications.Messages;
namespace BodyshopPartner.Utils namespace BodyshopPartner.Utils
{ {
@@ -159,12 +160,14 @@ namespace BodyshopPartner.Utils
logger.Trace("Job insert succesful. Show notification"); logger.Trace("Job insert succesful. Show notification");
App.Current.Dispatcher.Invoke(() => App.Current.Dispatcher.Invoke(() =>
{ {
Growler.AddNotification(new Notification() 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);
Title = Properties.Resources.Msg_NewJobUploaded, //Growler.AddNotification(new Notification()
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 // 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 //Succesful upsert
App.Current.Dispatcher.Invoke(() => App.Current.Dispatcher.Invoke(() =>
{ {
Growler.AddNotification(new Notification() string msg = Properties.Resources.Msg_NewJobUploadError + " " + item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value + Ex.Message;
{ Notifications.notifier.ShowError(msg);
Title = Properties.Resources.Msg_NewJobUploadError, //Growler.AddNotification(new Notification()
Subtitle = item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value, //{
Message = Ex.Message // Title = Properties.Resources.Msg_NewJobUploadError,
}); ; // Subtitle = item.Job?.ownr_fn?.Value + " " + item.Job?.ownr_ln?.Value,
// Message = Ex.Message
//}); ;
}); });
} }
_jobs.Dequeue(); _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 BodyshopPartner.Utils.Growls;
using Interop.QBFC13; using Interop.QBFC13;
using Interop.QBXMLRP2; using Interop.QBXMLRP2;
using ToastNotifications.Messages;
namespace BodyshopPartner.Utils namespace BodyshopPartner.Utils
{ {
@@ -26,7 +27,7 @@ namespace BodyshopPartner.Utils
public static void ConnectToQuickBooks() 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."); throw new Exception("The QuickBooks file specified does not exist.");
} }
@@ -35,12 +36,15 @@ namespace BodyshopPartner.Utils
logger.Debug("Attempting to connect to QuickBooks..."); logger.Debug("Attempting to connect to QuickBooks...");
App.Current.Dispatcher.Invoke(() => App.Current.Dispatcher.Invoke(() =>
{ {
Growler.AddNotification(new Notification() string msg = Properties.Resources.Msg_QbConnection_Title + " " + Properties.Resources.Msg_QbConnection_Msg;
{
Id = new Random().Next(), Notifications.notifier.ShowInformation(msg);
Title = Properties.Resources.Msg_QbConnection_Title, //Growler.AddNotification(new Notification()
Message = Properties.Resources.Msg_QbConnection_Msg //{
}); // Id = new Random().Next(),
// Title = Properties.Resources.Msg_QbConnection_Title,
// Message = Properties.Resources.Msg_QbConnection_Msg
//});
}); });
rp = new RequestProcessor2Class(); rp = new RequestProcessor2Class();
@@ -52,18 +56,21 @@ namespace BodyshopPartner.Utils
App.Current.Dispatcher.Invoke(() => App.Current.Dispatcher.Invoke(() =>
{ {
Growler.AddNotification(new Notification() string msg = Properties.Resources.Msg_QbConnected_Title + " " + Properties.Resources.Msg_QbConnected_Msg;
{
Id = new Random().Next(), Notifications.notifier.ShowInformation(msg);
Title = Properties.Resources.Msg_QbConnected_Title, //Growler.AddNotification(new Notification()
Message = Properties.Resources.Msg_QbConnected_Msg //{
}); // Id = new Random().Next(),
// Title = Properties.Resources.Msg_QbConnected_Title,
// Message = Properties.Resources.Msg_QbConnected_Msg
//});
}); });
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Error(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?"); 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?"); throw new Exception("QuickBooks Request Processor not registered. Is QuickBooks installed on this computer?");
@@ -83,12 +90,16 @@ namespace BodyshopPartner.Utils
rp.CloseConnection(); rp.CloseConnection();
App.Current.Dispatcher.Invoke(() => App.Current.Dispatcher.Invoke(() =>
{ {
Growler.AddNotification(new Notification() string msg = Properties.Resources.Msg_QbDisconnection_Title + " " + Properties.Resources.Msg_QbDisconnection_Msg;
{
Id = new Random().Next(), Notifications.notifier.ShowSuccess(msg);
Title = Properties.Resources.Msg_QbDisconnection_Title,
Message = Properties.Resources.Msg_QbDisconnection_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."); logger.Debug("Disconnected from QuickBooks successfully.");
} }

View File

@@ -13,6 +13,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Firebase.Auth; using Firebase.Auth;
using ToastNotifications.Messages;
namespace BodyshopPartner.ViewModels namespace BodyshopPartner.ViewModels
{ {
@@ -20,6 +21,9 @@ namespace BodyshopPartner.ViewModels
{ {
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
/* * */
public MainViewModel() public MainViewModel()
{ {
logger.Trace("Main VM constructed."); logger.Trace("Main VM constructed.");
@@ -76,10 +80,8 @@ namespace BodyshopPartner.ViewModels
LoadBodyshopData().Wait(); ; LoadBodyshopData().Wait(); ;
_callingThread.ReportProgress(80); _callingThread.ReportProgress(80);
Utils.HTTPServer.InitHttpServer(AddHttpStatus);
logger.Debug("VM Init Complete"); logger.Debug("VM Init Complete");
Task.Run(() => Utils.HTTPServer.InitHttpServer(AddHttpStatus));
_callingThread.ReportProgress(100); _callingThread.ReportProgress(100);
} }
@@ -106,7 +108,7 @@ namespace BodyshopPartner.ViewModels
{ {
logger.Debug("Adding folder {0} to monitoring paths.", dialog.SelectedPath); logger.Debug("Adding folder {0} to monitoring paths.", dialog.SelectedPath);
MonitoringPaths.Add(new Models.Monitor() { FilePath = dialog.SelectedPath }); MonitoringPaths.Add(new Models.Monitor() { FilePath = dialog.SelectedPath });
Properties.Settings.Default.MonitoringPaths = MonitoringPaths.Select(x => x.FilePath).ToList(); ; Properties.Settings.Default.MonitoringPaths = MonitoringPaths.Select(x => x.FilePath).ToList();
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }
} }
@@ -226,14 +228,18 @@ namespace BodyshopPartner.ViewModels
private FirebaseAuthLink al = BodyshopPartner.Utils.Auth.authlink; private FirebaseAuthLink al = BodyshopPartner.Utils.Auth.authlink;
public async Task TestGql() public async Task TestGql()
{ {
Notification _n = new Notification()
{ Utils.Notifications.notifier.ShowInformation("The message");
Id = new Random().Next(),
Title = "This is a title",
Subtitle = "Subtitle", //Notification _n = new Notification()
Message = "Somethin" //{
}; // Id = new Random().Next(),
Growler.AddNotification(_n); // Title = "This is a title",
// Subtitle = "Subtitle",
// Message = "Somethin"
//};
//Growler.AddNotification(_n);
Console.WriteLine(al.FirebaseToken); Console.WriteLine(al.FirebaseToken);
FirebaseAuthLink t = await al.GetFreshAuthAsync(); FirebaseAuthLink t = await al.GetFreshAuthAsync();

View File

@@ -70,4 +70,6 @@
<package id="System.Threading.Timer" version="4.3.0" targetFramework="net472" /> <package id="System.Threading.Timer" version="4.3.0" targetFramework="net472" />
<package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net472" /> <package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net472" />
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net472" /> <package id="System.Xml.XDocument" version="4.3.0" targetFramework="net472" />
<package id="ToastNotifications" version="2.5.1" targetFramework="net472" />
<package id="ToastNotifications.Messages" version="2.5.1" targetFramework="net472" />
</packages> </packages>