Skip to content

Commit

Permalink
fix requester image not loading when using access token
Browse files Browse the repository at this point in the history
  • Loading branch information
rb111 committed Mar 30, 2017
1 parent 0ea030c commit 6fe8bfd
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 64 deletions.
3 changes: 3 additions & 0 deletions BuildsAppReborn.Access/Models/Tfs2017BuildDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ internal class Tfs2017BuildDefinition : IBuildDefinition
[JsonProperty("url")]
public String Url { get; private set; }

[JsonIgnore]
public String BuildSettingsId { get; internal set; }

#endregion
}
}
27 changes: 27 additions & 0 deletions BuildsAppReborn.Access/Models/Tfs2017User.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using BuildsAppReborn.Contracts.Models;
using Newtonsoft.Json;

Expand Down Expand Up @@ -26,6 +27,32 @@ internal class Tfs2017User : IUser
[JsonProperty("url")]
public String Url { get; private set; }

[JsonIgnore]
public Byte[] ImageData
{
get
{
if (this.imageData == null && ImageDataLoader != null)
{
this.imageData = Task.Run(() => ImageDataLoader).Result;
}
return this.imageData;
}
}

#endregion

#region Internal Properties

[JsonIgnore]
internal Task<Byte[]> ImageDataLoader { get; set; }

#endregion

#region Private Fields

private Byte[] imageData;

#endregion
}
}
17 changes: 17 additions & 0 deletions BuildsAppReborn.Access/Tfs2017BuildProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public async Task<DataResponse<IEnumerable<IBuildDefinition>>> GetBuildDefinitio
{
var result = await requestResponse.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<List<Tfs2017BuildDefinition>>(JObject.Parse(result)["value"].ToString());
foreach (var buildDefinition in data)
{
buildDefinition.BuildSettingsId = settings.UniqueId;
}

return new DataResponse<IEnumerable<IBuildDefinition>> {Data = data, StatusCode = requestResponse.StatusCode};
}
Expand Down Expand Up @@ -65,6 +69,8 @@ public async Task<DataResponse<IEnumerable<IBuild>>> GetBuilds(IEnumerable<IBuil
{
var result = await requestResponse.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<List<Tfs2017Build>>(JObject.Parse(result)["value"].ToString());
data.Select(d => d.Definition).OfType<Tfs2017BuildDefinition>().ToList().ForEach(d => d.BuildSettingsId = settings.UniqueId);
data.Select(d => d.Requester).OfType<Tfs2017User>().ToList().ForEach(a => a.ImageDataLoader = GetImageData(settings, a));

return new DataResponse<IEnumerable<IBuild>> {Data = data, StatusCode = requestResponse.StatusCode};
}
Expand All @@ -78,6 +84,17 @@ public async Task<DataResponse<IEnumerable<IBuild>>> GetBuilds(IEnumerable<IBuil

#region Private Static Methods

private static async Task<Byte[]> GetImageData(BuildMonitorSettings settings, IUser user)
{
var response = await GetRequestResponse(user.ImageUrl, settings);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsByteArrayAsync();
}

return null;
}

private static async Task<HttpResponseMessage> GetRequestResponse(String requestUrl, BuildMonitorSettings settings)
{
var credentials = settings.GetValueStrict<ICredentials>(ProjectCredentialsSettingKey);
Expand Down
12 changes: 1 addition & 11 deletions BuildsAppReborn.Client/Cache/BuildCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows;
using BuildsAppReborn.Client.Resources;
using BuildsAppReborn.Contracts;
Expand Down Expand Up @@ -84,13 +82,7 @@ protected virtual void OnCacheUpdated()

#region Private Methods

private async Task<Byte[]> GetRequesterImageWithDefaultCredentials(String requesterImageUrl)
{
var respone = await HttpRequestHelper.GetRequestResponse(requesterImageUrl, CredentialCache.DefaultCredentials);
return await respone.Content.ReadAsByteArrayAsync();
}

private async void OnBuildsUpdated(ICollection<IBuild> builds)
private void OnBuildsUpdated(ICollection<IBuild> builds)
{
if (!builds.Any()) return;

Expand All @@ -102,7 +94,6 @@ private async void OnBuildsUpdated(ICollection<IBuild> builds)

newStatus.BuildDefinition = grp.Key;
newStatus.AllBuildItems = grp.Select(a => new BuildItem(a)).ToList();
newStatus.CurrentBuild.RequesterImage = await GetRequesterImageWithDefaultCredentials(newStatus.CurrentBuild.Build.Requester.ImageUrl);
buildStatusGroups.Add(newStatus);
}
Application.Current.Dispatcher.Invoke(() =>
Expand Down Expand Up @@ -163,7 +154,6 @@ private void UpdateCurrentIcon()
#region Private Fields

private readonly IEqualityComparer<IBuildDefinition> buildDefinitionEqualityComparer;

private BuildCacheStatus cacheStatus;
private String currentIcon;

Expand Down
1 change: 1 addition & 0 deletions BuildsAppReborn.Client/SampleData/SampleBuildDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class SampleBuildDefinition : IBuildDefinition
public IProject Project { get; set; }
public String Type { get; set; }
public String Url { get; }
public String BuildSettingsId { get; }

#endregion
}
Expand Down
74 changes: 37 additions & 37 deletions BuildsAppReborn.Client/Views/BuildsStatusView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,48 +104,48 @@
<Image Grid.Row="0"
Height="50"
HorizontalAlignment="Right"
Source="{Binding CurrentBuild.RequesterImage}" />
Source="{Binding CurrentBuild.Build.Requester.ImageData}" />
<TextBlock Grid.Row="1"
HorizontalAlignment="Right"
Text="{Binding CurrentBuild.Build.Requester.DisplayName}" />

</Grid>

<!-- Build history -->
<ItemsControl Grid.Row="1"
Grid.Column="0"
Margin="1 10 0 10"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
ItemsSource="{Binding PreviousBuilds}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Width="10"
Margin="0 0 3 0"
Background="{Binding Build.Status,
Converter={StaticResource BuildStatusToSolidColorBrushForegroundConverter}}">
<Grid.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat=" {0} ({1} ago)">
<Binding Path="Build.Requester.DisplayName"/>
<Binding Path="BuildTime" Converter="{StaticResource BuildTimeToElapsedTimeConverter}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid.ToolTip>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- Build history -->
<ItemsControl Grid.Row="1"
Grid.Column="0"
Margin="1 10 0 10"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
ItemsSource="{Binding PreviousBuilds}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Width="10"
Margin="0 0 3 0"
Background="{Binding Build.Status,
Converter={StaticResource BuildStatusToSolidColorBrushForegroundConverter}}">
<Grid.ToolTip>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat=" {0} ({1} ago)">
<Binding Path="Build.Requester.DisplayName" />
<Binding Converter="{StaticResource BuildTimeToElapsedTimeConverter}" Path="BuildTime" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</Grid.ToolTip>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<!-- current build status with icon and text and date -->
<Grid Grid.Row="1" Grid.Column="1">
Expand Down Expand Up @@ -177,9 +177,9 @@
</ItemsControl>
</Grid>
<ProgressBar Grid.Column="0"
Margin="20"
Width="128"
Height="128"
Margin="20"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsIndeterminate="True">
Expand Down
16 changes: 0 additions & 16 deletions BuildsAppReborn.Contracts.UI/BuildItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ public DateTime BuildTime
}
}

public Byte[] RequesterImage
{
get { return this.requesterImage; }
set
{
this.requesterImage = value;
OnPropertyChanged();
}
}

#endregion

#region Private Methods
Expand Down Expand Up @@ -68,11 +58,5 @@ private DateTime GetBuildTime()
}

#endregion

#region Private Fields

private Byte[] requesterImage;

#endregion
}
}
2 changes: 2 additions & 0 deletions BuildsAppReborn.Contracts/Models/IBuildDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public interface IBuildDefinition
{
#region Public Properties

String BuildSettingsId { get; }

Int32 Id { get; }

String Name { get; }
Expand Down
2 changes: 2 additions & 0 deletions BuildsAppReborn.Contracts/Models/IUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface IUser

String Id { get; }

Byte[] ImageData { get; }

String ImageUrl { get; }

String UniqueName { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class DummyDefinition : IBuildDefinition

public String Url { get; }

public String BuildSettingsId { get; }

#endregion
}
}

0 comments on commit 6fe8bfd

Please sign in to comment.