From 10717f76497322a2c0483e90ee3dce751f8410ef Mon Sep 17 00:00:00 2001 From: rb111 Date: Wed, 15 Mar 2017 21:11:03 +0100 Subject: [PATCH] fix crash when no connection, added logging, show error toast --- BuildsAppReborn.Access/BuildMonitor.cs | 21 +++++++++--- .../BuildsAppReborn.Access.csproj | 8 +++++ BuildsAppReborn.Access/packages.config | 1 + BuildsAppReborn.Client/App.config | 33 ++++++++++++++++++- BuildsAppReborn.Client/App.xaml.cs | 3 ++ .../BuildsAppReborn.Client.csproj | 4 +++ BuildsAppReborn.Client/packages.config | 1 + 7 files changed, 66 insertions(+), 5 deletions(-) diff --git a/BuildsAppReborn.Access/BuildMonitor.cs b/BuildsAppReborn.Access/BuildMonitor.cs index 3a21bce..c5b4446 100644 --- a/BuildsAppReborn.Access/BuildMonitor.cs +++ b/BuildsAppReborn.Access/BuildMonitor.cs @@ -4,11 +4,12 @@ using System.Linq; using System.Threading.Tasks; using System.Timers; - using BuildsAppReborn.Contracts; using BuildsAppReborn.Contracts.Composition; using BuildsAppReborn.Contracts.Models; +using BuildsAppReborn.Contracts.UI.Notifications; using BuildsAppReborn.Infrastructure; +using log4net; namespace BuildsAppReborn.Access { @@ -20,9 +21,10 @@ internal sealed class BuildMonitor : IBuildMonitorAdvanced #region Constructors [ImportingConstructor] - public BuildMonitor(LazyContainer buildProviders) + public BuildMonitor(LazyContainer buildProviders, [ImportMany] IEnumerable notificationProviders) { this.buildProviders = buildProviders; + this.notificationProvider = notificationProviders.FirstOrDefault(); this.timer.Elapsed += (sender, args) => BeginPollingBuilds(); } @@ -110,8 +112,16 @@ private void OnMonitorStopped() private async void PollBuilds(IBuildProvider provider, BuildMonitorSettings settings) { - var builds = await Task.Run(() => provider.GetBuilds(settings.SelectedBuildDefinitions, settings)); - OnBuildsUpdated(builds.ToList()); + try + { + var builds = await Task.Run(() => provider.GetBuilds(settings.SelectedBuildDefinitions, settings)); + OnBuildsUpdated(builds.ToList()); + } + catch (Exception exception) + { + this.logger.Warn("Failure on polling builds", exception); + this.notificationProvider.ShowMessage("Failure on getting builds", $"Please check the connection for project(s) {String.Join(", ", settings.SelectedBuildDefinitions.Select(b => b.Project.Name).Distinct())}."); + } } #endregion @@ -122,6 +132,9 @@ private async void PollBuilds(IBuildProvider provider, BuildMonitorSettings sett private Boolean isPolling; + private ILog logger = LogManager.GetLogger(typeof(BuildMonitor)); + private INotificationProvider notificationProvider; + private readonly Dictionary> providerSettingsGroup = new Dictionary>(); private readonly Timer timer = new Timer(); diff --git a/BuildsAppReborn.Access/BuildsAppReborn.Access.csproj b/BuildsAppReborn.Access/BuildsAppReborn.Access.csproj index 40f2929..cad78dc 100644 --- a/BuildsAppReborn.Access/BuildsAppReborn.Access.csproj +++ b/BuildsAppReborn.Access/BuildsAppReborn.Access.csproj @@ -30,6 +30,10 @@ 4 + + ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll + True + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True @@ -57,6 +61,10 @@ + + {1F3A73B2-A17D-4606-BF7A-5FA53D119227} + BuildsAppReborn.Contracts.UI + {02D4B94B-D332-48BE-A880-406AE76B8EBE} BuildsAppReborn.Contracts diff --git a/BuildsAppReborn.Access/packages.config b/BuildsAppReborn.Access/packages.config index 7ee8c10..759a0c2 100644 --- a/BuildsAppReborn.Access/packages.config +++ b/BuildsAppReborn.Access/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/BuildsAppReborn.Client/App.config b/BuildsAppReborn.Client/App.config index 0eab8fc..fc40f8c 100644 --- a/BuildsAppReborn.Client/App.config +++ b/BuildsAppReborn.Client/App.config @@ -1,9 +1,10 @@  - +
+
@@ -23,4 +24,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BuildsAppReborn.Client/App.xaml.cs b/BuildsAppReborn.Client/App.xaml.cs index 9319343..4ab28cd 100644 --- a/BuildsAppReborn.Client/App.xaml.cs +++ b/BuildsAppReborn.Client/App.xaml.cs @@ -10,6 +10,7 @@ using BuildsAppReborn.Contracts; using Hardcodet.Wpf.TaskbarNotification; +using log4net.Config; namespace BuildsAppReborn.Client { @@ -38,6 +39,8 @@ protected override void OnStartup(StartupEventArgs e) var compositionContainer = BuildCompositionContainer(); + XmlConfigurator.Configure(); + this.updateChecker = compositionContainer.GetExportedValue(); this.updateChecker.Start(); this.updateChecker.UpdateCheck(); diff --git a/BuildsAppReborn.Client/BuildsAppReborn.Client.csproj b/BuildsAppReborn.Client/BuildsAppReborn.Client.csproj index 6b17173..ec3ffd6 100644 --- a/BuildsAppReborn.Client/BuildsAppReborn.Client.csproj +++ b/BuildsAppReborn.Client/BuildsAppReborn.Client.csproj @@ -59,6 +59,10 @@ ..\packages\squirrel.windows.1.5.2\lib\Net45\ICSharpCode.SharpZipLib.dll True + + ..\packages\log4net.2.0.8\lib\net45-full\log4net.dll + True + ..\packages\MahApps.Metro.1.4.3\lib\net45\MahApps.Metro.dll True diff --git a/BuildsAppReborn.Client/packages.config b/BuildsAppReborn.Client/packages.config index be756fa..adb6e8c 100644 --- a/BuildsAppReborn.Client/packages.config +++ b/BuildsAppReborn.Client/packages.config @@ -3,6 +3,7 @@ +