From 2acc8faa5b0814e3604c36f86de9497d00ce55a6 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 3 Dec 2020 10:41:57 -0800 Subject: [PATCH] Updates to logging and v1.0.3 release. --- BodyshopUploader/Properties/AssemblyInfo.cs | 4 +-- BodyshopUploader/Releases/RELEASES | 4 +-- BodyshopUploader/Utils/HTTPServer.cs | 27 +++++++++++++++++-- BodyshopUploader/Utils/SquirrelAwareHelper.cs | 24 ++++++++++------- BodyshopUploader/Utils/UpdateHandler.cs | 25 +++++++++++++---- .../ViewModels/MainViewModel.commands.cs | 20 ++++++++++++++ BodyshopUploader/ViewModels/MainViewModel.cs | 13 ++++++--- .../ViewModels/MainViewModel.props.cs | 14 ++++++++++ BodyshopUploader/Views/Main.xaml | 8 ++++-- 9 files changed, 113 insertions(+), 26 deletions(-) diff --git a/BodyshopUploader/Properties/AssemblyInfo.cs b/BodyshopUploader/Properties/AssemblyInfo.cs index 8be93c2..ed5e0f3 100644 --- a/BodyshopUploader/Properties/AssemblyInfo.cs +++ b/BodyshopUploader/Properties/AssemblyInfo.cs @@ -51,7 +51,7 @@ using System.Windows; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.1")] -[assembly: AssemblyFileVersion("1.0.1")] +[assembly: AssemblyVersion("1.0.4")] +[assembly: AssemblyFileVersion("1.0.3")] //Setting Squirrel Aware Version. [assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] \ No newline at end of file diff --git a/BodyshopUploader/Releases/RELEASES b/BodyshopUploader/Releases/RELEASES index 3d14762..a0450cf 100644 --- a/BodyshopUploader/Releases/RELEASES +++ b/BodyshopUploader/Releases/RELEASES @@ -1,3 +1 @@ -2170C39D054590A1CEFFBB68922BB3FBFF82A625 ImEXOnlinePartner-1.0.0-full.nupkg 4987861 -6AC5040BEFF741735A2A6497D5BA5C0E1DB247C9 ImEXOnlinePartner-1.0.1-delta.nupkg 32948 -59F79A6A3C31AB03C297E40648B468F62424C03B ImEXOnlinePartner-1.0.1-full.nupkg 4988035 \ No newline at end of file +27267F96DE441041026E9EE4292798734572912A ImEXOnlinePartner-1.0.3-full.nupkg 4989160 \ No newline at end of file diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs index 5e14124..db17851 100644 --- a/BodyshopUploader/Utils/HTTPServer.cs +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -9,6 +9,7 @@ using Newtonsoft; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using BodyshopPartner.Models; +using ToastNotifications.Messages; namespace BodyshopPartner.Utils { @@ -33,9 +34,31 @@ namespace BodyshopPartner.Utils logger.Trace("Starting HTTP server..."); hlog = HttpLogger; - hlog("Starting HTTP server..."); + //TODO As a part of the installer, add netsh http add urlacl url=http://+:1337/ user="Everyone - HttpServer.ListenAsync(1337, System.Threading.CancellationToken.None, Route.OnHttpRequestAsync).Wait(); + try + { + HttpServer.ListenAsync(1337, System.Threading.CancellationToken.None, Route.OnHttpRequestAsync).Wait(); + hlog("ImEX Online connection server started..."); + } + catch (Exception Ex) + { + logger.Fatal("Unable to start HTTP server. " + Ex.ToString()); + App.Current.Dispatcher.Invoke(() => + { + string msg = "Unable to connect to ImEX Online Web App. Please ensure your firewall allows the connection."; + hlog("ImEX Online connection server could not start. Please restart the partner to try again."); + Utils.Notifications.notifier.ShowError(msg); + bool AddedException = Utils.SquirrelAwareHelper.AddHttpExcetion(); + + //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 + //}); + }); + } } private static void HandleQbPost(System.Net.HttpListenerRequest req, System.Net.HttpListenerResponse res) diff --git a/BodyshopUploader/Utils/SquirrelAwareHelper.cs b/BodyshopUploader/Utils/SquirrelAwareHelper.cs index 047ae15..14e9fcd 100644 --- a/BodyshopUploader/Utils/SquirrelAwareHelper.cs +++ b/BodyshopUploader/Utils/SquirrelAwareHelper.cs @@ -10,6 +10,19 @@ namespace BodyshopPartner.Utils { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + public static bool AddHttpExcetion() + { + logger.Debug("Attempting to add HTTP Exclusion for web-server"); + System.Diagnostics.Process process = new System.Diagnostics.Process(); + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; + startInfo.FileName = "cmd.exe"; + startInfo.Arguments = "netsh http add urlacl url=http://+:1337/ user=\"Everyone\""; + startInfo.Verb = "runas"; + process.StartInfo = startInfo; + return process.Start(); + } + public static void InitializeSquirrelAware() { using (var mgr = new UpdateManager(Utils.UpdateHandler.UpdatePath)) @@ -22,15 +35,8 @@ namespace BodyshopPartner.Utils logger.Debug("Installing via Squirrel Aware Helper. ", v); try { - logger.Debug("Attempting to add HTTP Exclusion for web-server"); - System.Diagnostics.Process process = new System.Diagnostics.Process(); - System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); - startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; - startInfo.FileName = "cmd.exe"; - startInfo.Arguments = "add netsh http add urlacl url=http://+:1337/ user=\"Everyone\""; - startInfo.Verb = "runas"; - process.StartInfo = startInfo; - bool successful = process.Start(); + + bool successful = AddHttpExcetion(); if (successful) { diff --git a/BodyshopUploader/Utils/UpdateHandler.cs b/BodyshopUploader/Utils/UpdateHandler.cs index 2e5a925..e2232ef 100644 --- a/BodyshopUploader/Utils/UpdateHandler.cs +++ b/BodyshopUploader/Utils/UpdateHandler.cs @@ -29,6 +29,9 @@ namespace BodyshopPartner.Utils logger.Debug("No releases to apply."); return false; } + + updateInfo.ReleasesToApply.ForEach(release => logger.Debug("Release to apply " + release.Version)); + return true; } } @@ -53,11 +56,23 @@ namespace BodyshopPartner.Utils using (var updateManager = new UpdateManager(UpdatePath)) { - var updateInfo = await updateManager.CheckForUpdate(); - var releases = updateInfo.ReleasesToApply; - logger.Debug("Applying releases", releases.ToString()); - await updateManager.DownloadReleases(releases, _ => { DownloadProgress = _; }); - await updateManager.ApplyReleases(updateInfo, _ => { InstallProgress = _; }); + try + { + var updateInfo = await updateManager.CheckForUpdate(); + var releases = updateInfo.ReleasesToApply; + logger.Debug("Applying releases", releases.ToString()); + await updateManager.DownloadReleases(releases, _ => { + logger.Debug("Download Release Progress " + _.ToString()); + DownloadProgress = _; }); + await updateManager.ApplyReleases(updateInfo, _ => { + logger.Debug("Install Progress " + _.ToString()); + InstallProgress = _; }); + } + catch (Exception Ex) + { + logger.Error("Error updating Partner App. " + Ex.ToString()); + } + } } diff --git a/BodyshopUploader/ViewModels/MainViewModel.commands.cs b/BodyshopUploader/ViewModels/MainViewModel.commands.cs index bb01414..2f3fb3a 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.commands.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.commands.cs @@ -135,6 +135,26 @@ namespace BodyshopPartner.ViewModels } } + + private ICommand _installUpdatesCommand; + public ICommand InstallUpdatesCommand + { + get + { + if (_installUpdatesCommand == null) + { + _installUpdatesCommand = new RelayCommand( + p => UpdateAvailable, + async p => + { + await InstallUpdates(); + }); + } + return _installUpdatesCommand; + } + } + + private ICommand _quitCommand; public ICommand QuitCommand { diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs index d42d688..8d9a173 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.cs @@ -91,13 +91,20 @@ namespace BodyshopPartner.ViewModels private async Task updateCheck() { logger.Debug("Checking if updates are available."); - if (await Utils.UpdateHandler.AreUpdatesAvailable()) + UpdateAvailable = await Utils.UpdateHandler.AreUpdatesAvailable(); + if (UpdateAvailable) { - logger.Debug("Updates are available! Installing."); - await Utils.UpdateHandler.ApplyUpdates(Progress, Progress); + string msg = "An update to ImEX Online Partner is Available"; + Utils.Notifications.notifier.ShowInformation(msg); } } + private async Task InstallUpdates() + { + logger.Debug("Updates are available! Installing."); + await Utils.UpdateHandler.ApplyUpdates(UpdateProgress, UpdateProgress); + } + private async void _updateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { await updateCheck(); diff --git a/BodyshopUploader/ViewModels/MainViewModel.props.cs b/BodyshopUploader/ViewModels/MainViewModel.props.cs index de84148..413c677 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.props.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.props.cs @@ -63,5 +63,19 @@ namespace BodyshopPartner.ViewModels get { return _appVersion; } set { SetProperty(ref _appVersion, value); } } + + private bool _updateAvailable = false; + public bool UpdateAvailable + { + get { return _updateAvailable; } + set { SetProperty(ref _updateAvailable, value); } + } + + private int _updateProgress; + public int UpdateProgress + { + get { return _updateProgress; } + set { SetProperty(ref _updateProgress, value); } + } } } diff --git a/BodyshopUploader/Views/Main.xaml b/BodyshopUploader/Views/Main.xaml index 4f29997..72a3e7f 100644 --- a/BodyshopUploader/Views/Main.xaml +++ b/BodyshopUploader/Views/Main.xaml @@ -11,7 +11,7 @@ xmlns:vm="clr-namespace:BodyshopPartner.ViewModels" mc:Ignorable="d" Title="{x:Static p:Resources.Title_Main}" - Height="489.819" + Height="600" Width="800" TextElement.Foreground="{DynamicResource MaterialDesignBody}" TextElement.FontWeight="Regular" @@ -28,6 +28,7 @@ +