Skip to content

Commit

Permalink
fix issue with notification title differ from build status when using…
Browse files Browse the repository at this point in the history
… group by pullrequest
  • Loading branch information
Luka Grabarevic committed May 17, 2018
1 parent b28ecd8 commit 7487f5c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 11 deletions.
1 change: 1 addition & 0 deletions BuildsAppReborn.Access.UI/BuildsAppReborn.Access.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</Compile>
<Compile Include="Base\View\BuildProviderViewBase.cs" />
<Compile Include="Notifications\NotificationHelper.cs" />
<Compile Include="Notifications\NotificationProviderBase.cs" />
<Compile Include="Notifications\Windows10NotificationProvider.cs" />
<Compile Include="Notifications\DefaultNotificationProvider.cs" />
<Compile Include="Resources\Resource.Designer.cs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ namespace BuildsAppReborn.Access.UI.Notifications
{
[PriorityExport(typeof(INotificationProvider), -1)]
[PartCreationPolicy(CreationPolicy.Shared)]
internal class DefaultNotificationProvider : INotificationProvider
internal class DefaultNotificationProvider : NotificationProviderBase, INotificationProvider
{
#region Constructors

public DefaultNotificationProvider()
[ImportingConstructor]
public DefaultNotificationProvider(GeneralSettings generalSettings) : base(generalSettings)
{
this.notifier = new Notifier(cfg =>
{
Expand All @@ -38,7 +39,7 @@ public void ShowBuild(IBuild build, Func<IBuild, String> iconProvider, Action<IB
if (build == null) return;

var sb = new StringBuilder();
sb.AppendLine(build.GenerateTitle());
sb.AppendLine(GetTitle(build));
sb.AppendLine(build.GenerateStatus());
sb.AppendLine(build.GenerateUsername());
var displayOptions = new MessageOptions
Expand Down
10 changes: 9 additions & 1 deletion BuildsAppReborn.Access.UI/Notifications/NotificationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ public static String GenerateStatus(this IBuild build)
return build.Status.ToString();
}

public static String GenerateTitle(this IBuild build)
public static String GenerateTitle(this IBuild build, BuildViewStyle viewStyle)
{
if (viewStyle == BuildViewStyle.GroupByPullRequest)
{
if (build.PullRequest != null)
{
return $"{build.Definition.Project.Name} - {build.PullRequest.Title} - {build.BuildNumber}";
}
}

return $"{build.Definition.Project.Name} - {build.Definition.Name} - {build.BuildNumber}";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using BuildsAppReborn.Contracts.Models;

namespace BuildsAppReborn.Access.UI.Notifications
{
internal abstract class NotificationProviderBase
{
#region Constructors

protected NotificationProviderBase(GeneralSettings generalSettings)
{
this.generalSettings = generalSettings;
}

#endregion

#region Public Methods

public virtual String GetTitle(IBuild build)
{
return build.GenerateTitle(this.generalSettings.ViewStyle);
}

#endregion

#region Private Fields

private GeneralSettings generalSettings;

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ namespace BuildsAppReborn.Access.UI.Notifications
{
[PriorityExport(typeof(INotificationProvider), 100)]
[PartCreationPolicy(CreationPolicy.Shared)]
internal class Windows10NotificationProvider : INotificationProvider
internal class Windows10NotificationProvider : NotificationProviderBase, INotificationProvider
{
#region Constructors

[ImportingConstructor]
public Windows10NotificationProvider(GeneralSettings generalSettings) : base(generalSettings)
{
}

#endregion

#region Implementation of INotificationProvider

public void ShowBuild(IBuild build, Func<IBuild, String> iconProvider, Action<IBuild> notificationClickAction)
Expand All @@ -22,7 +31,7 @@ public void ShowBuild(IBuild build, Func<IBuild, String> iconProvider, Action<IB
// Fill in the text elements
var stringElements = toastXml.GetElementsByTagName("text");

stringElements[0].AppendChild(toastXml.CreateTextNode(build.GenerateTitle()));
stringElements[0].AppendChild(toastXml.CreateTextNode(GetTitle(build)));
stringElements[1].AppendChild(toastXml.CreateTextNode(build.GenerateStatus()));
stringElements[2].AppendChild(toastXml.CreateTextNode(build.GenerateUsername()));

Expand Down
10 changes: 5 additions & 5 deletions BuildsAppReborn.Client/Cache/BuildCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public class BuildCache : ViewModelBase
#region Constructors

[ImportingConstructor]
internal BuildCache(IBuildMonitorBasic buildMonitor, IEqualityComparer<IBuildDefinition> buildDefinitionEqualityComparer, IEqualityComparer<IPullRequest> pullRequstEqualityComparer, GlobalSettingsContainer globalSettingsContainer)
internal BuildCache(IBuildMonitorBasic buildMonitor, IEqualityComparer<IBuildDefinition> buildDefinitionEqualityComparer, IEqualityComparer<IPullRequest> pullRequstEqualityComparer, GeneralSettings generalSettings)
{
BuildsStatus = new RangeObservableCollection<BuildStatusGroup>();
this.buildDefinitionEqualityComparer = buildDefinitionEqualityComparer;
this.pullRequstEqualityComparer = pullRequstEqualityComparer;
this.globalSettingsContainer = globalSettingsContainer;
this.generalSettings = generalSettings;
buildMonitor.BuildsUpdated += OnBuildsUpdated;
buildMonitor.MonitorStopped += (sender, args) => CacheStatus = BuildCacheStatus.NotConfigured;
buildMonitor.MonitorStarted += (sender, args) => CacheStatus = BuildCacheStatus.Loading;
Expand Down Expand Up @@ -137,11 +137,11 @@ private void OnBuildsUpdated(ICollection<IBuild> builds)

var buildStatusGroups = new List<BuildStatusGroup>();

if (this.globalSettingsContainer.GeneralSettings.ViewStyle == BuildViewStyle.GroupByBuildDefinition)
if (this.generalSettings.ViewStyle == BuildViewStyle.GroupByBuildDefinition)
{
buildStatusGroups.AddRange(GroupBuildsByDefinition(builds, BuildsStatus));
}
else if (this.globalSettingsContainer.GeneralSettings.ViewStyle == BuildViewStyle.GroupByPullRequest)
else if (this.generalSettings.ViewStyle == BuildViewStyle.GroupByPullRequest)
{
var prBuilds = builds.Where(a => a.PullRequest != null).ToList();

Expand Down Expand Up @@ -214,8 +214,8 @@ private void UpdateCurrentIcon()
private readonly IEqualityComparer<IBuildDefinition> buildDefinitionEqualityComparer;
private BuildCacheStatus cacheStatus;
private String currentIcon;
private readonly GlobalSettingsContainer globalSettingsContainer;
private readonly IEqualityComparer<IPullRequest> pullRequstEqualityComparer;
private readonly GeneralSettings generalSettings;

#endregion

Expand Down
1 change: 1 addition & 0 deletions BuildsAppReborn.Client/GlobalSettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public GlobalSettingsContainer()
/// <value>
/// The general settings.
/// </value>
[Export]
public GeneralSettings GeneralSettings
{
get
Expand Down
2 changes: 2 additions & 0 deletions BuildsAppReborn.Contracts/Models/GeneralSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;

namespace BuildsAppReborn.Contracts.Models
{
[PartCreationPolicy(CreationPolicy.Shared)]
public class GeneralSettings
{
#region Constructors
Expand Down

0 comments on commit 7487f5c

Please sign in to comment.