Skip to content

Commit

Permalink
fix crash when no connection, added logging, show error toast
Browse files Browse the repository at this point in the history
  • Loading branch information
rb111 committed Mar 16, 2017
1 parent c36b772 commit 10717f7
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 5 deletions.
21 changes: 17 additions & 4 deletions BuildsAppReborn.Access/BuildMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -20,9 +21,10 @@ internal sealed class BuildMonitor : IBuildMonitorAdvanced
#region Constructors

[ImportingConstructor]
public BuildMonitor(LazyContainer<IBuildProvider, IBuildProviderMetadata> buildProviders)
public BuildMonitor(LazyContainer<IBuildProvider, IBuildProviderMetadata> buildProviders, [ImportMany] IEnumerable<INotificationProvider> notificationProviders)
{
this.buildProviders = buildProviders;
this.notificationProvider = notificationProviders.FirstOrDefault();
this.timer.Elapsed += (sender, args) => BeginPollingBuilds();
}

Expand Down Expand Up @@ -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
Expand All @@ -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<IBuildProvider, ICollection<BuildMonitorSettings>> providerSettingsGroup = new Dictionary<IBuildProvider, ICollection<BuildMonitorSettings>>();

private readonly Timer timer = new Timer();
Expand Down
8 changes: 8 additions & 0 deletions BuildsAppReborn.Access/BuildsAppReborn.Access.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -57,6 +61,10 @@
<Compile Include="Tfs2017BuildProvider.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BuildsAppReborn.Contracts.UI\BuildsAppReborn.Contracts.UI.csproj">
<Project>{1F3A73B2-A17D-4606-BF7A-5FA53D119227}</Project>
<Name>BuildsAppReborn.Contracts.UI</Name>
</ProjectReference>
<ProjectReference Include="..\BuildsAppReborn.Contracts\BuildsAppReborn.Contracts.csproj">
<Project>{02D4B94B-D332-48BE-A880-406AE76B8EBE}</Project>
<Name>BuildsAppReborn.Contracts</Name>
Expand Down
1 change: 1 addition & 0 deletions BuildsAppReborn.Access/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.8" targetFramework="net461" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" />
</packages>
33 changes: 32 additions & 1 deletion BuildsAppReborn.Client/App.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="BuildsAppReborn.Client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
Expand All @@ -23,4 +24,34 @@
</setting>
</BuildsAppReborn.Client.Properties.Settings>
</applicationSettings>
<log4net>
<root>
<appender-ref ref="RollingFileAppender" />
<appender-ref ref="UdpAppender" />
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value=".\log\barlog_%date{yyyy-MM-dd}.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} [%thread] %-5level : %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="FATAL" />
</filter>
</appender>
<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
<remoteAddress value="127.0.0.1" />
<remotePort value="878" />
<layout type="log4net.Layout.XmlLayout" />
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
</appender>
</log4net>
</configuration>
3 changes: 3 additions & 0 deletions BuildsAppReborn.Client/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using BuildsAppReborn.Contracts;

using Hardcodet.Wpf.TaskbarNotification;
using log4net.Config;

namespace BuildsAppReborn.Client
{
Expand Down Expand Up @@ -38,6 +39,8 @@ protected override void OnStartup(StartupEventArgs e)

var compositionContainer = BuildCompositionContainer();

XmlConfigurator.Configure();

this.updateChecker = compositionContainer.GetExportedValue<UpdateChecker>();
this.updateChecker.Start();
this.updateChecker.UpdateCheck();
Expand Down
4 changes: 4 additions & 0 deletions BuildsAppReborn.Client/BuildsAppReborn.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<HintPath>..\packages\squirrel.windows.1.5.2\lib\Net45\ICSharpCode.SharpZipLib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MahApps.Metro, Version=1.4.3.0, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.4.3\lib\net45\MahApps.Metro.dll</HintPath>
<Private>True</Private>
Expand Down
1 change: 1 addition & 0 deletions BuildsAppReborn.Client/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<package id="DeltaCompressionDotNet" version="1.1.0" targetFramework="net461" />
<package id="Dragablz" version="0.0.3.186" targetFramework="net461" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net461" />
<package id="log4net" version="2.0.8" targetFramework="net461" />
<package id="MahApps.Metro" version="1.4.3" targetFramework="net461" />
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" />
<package id="MaterialDesignThemes" version="2.2.1.750" targetFramework="net461" />
Expand Down

0 comments on commit 10717f7

Please sign in to comment.