Skip to content

Commit

Permalink
fix connection with access token, minor ui changes in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rb111 committed Mar 30, 2017
1 parent ae833ef commit 6fd7eb6
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ public String AccessToken
get { return String.Empty; }
set
{
MonitorSettings[Tfs2017BuildProvider.PersonalAccessTokenSettingsKey] = value;
OnPropertyChanged();
ConnectCommand?.RaiseCanExecuteChanged();
// ToDo: Token should only be saved if connection was successful
if (!String.IsNullOrWhiteSpace(value))
{
MonitorSettings[Tfs2017BuildProvider.PersonalAccessTokenSettingsKey] = value;
OnPropertyChanged();
ConnectCommand?.RaiseCanExecuteChanged();
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions BuildsAppReborn.Access.UI/Views/Tfs2017BuildProviderView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Margin="6 0 0 0"
HorizontalAlignment="Left"
Content="{x:Static resources:Resource.TfsConnectionAccessTokenLabel}" />
<TextBox Grid.Column="1"
Expand All @@ -89,7 +88,7 @@
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Width="150"
Margin="6 0 0 0"
Margin="6 6 0 0"
Command="{Binding ConnectCommand}"
Content="{x:Static resources:Resource.TfsConnectButtonContent}" />
<ProgressBar Grid.Column="1"
Expand All @@ -99,7 +98,7 @@
Visibility="{Binding IsConnecting,
Converter={StaticResource BooleanToVisibilityConverter}}" />
</Grid>
<TextBlock Grid.Row="5" Text="{Binding StatusText}" Foreground="Red" />
<TextBlock Margin="6 6 0 0" Grid.Row="5" Text="{Binding StatusText}" Foreground="Red" />
<ItemsControl Grid.Row="6"
Grid.IsSharedSizeScope="True"
ItemsSource="{Binding BuildDefinitions}">
Expand Down
12 changes: 7 additions & 5 deletions BuildsAppReborn.Access/BuildMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Timers;
using BuildsAppReborn.Contracts;
Expand Down Expand Up @@ -117,17 +116,20 @@ private async void PollBuilds(IBuildProvider provider, BuildMonitorSettings sett
{
var builds = await Task.Run(() => provider.GetBuilds(settings.SelectedBuildDefinitions, settings));

if (builds.StatusCode != HttpStatusCode.OK)
if (!builds.IsSuccessStatusCode)
{
this.logger.Warn($"Http status code {builds.StatusCode} returned while polling for builds!");
this.notificationProvider.ShowMessage("Failure on getting builds", $"Please check the connection for project(s) '{String.Join(", ", settings.SelectedBuildDefinitions.Select(b => b.Project.Name).Distinct())}'. StatusCode was '{builds.StatusCode}'. See log for more details.");
}
else
{
OnBuildsUpdated(builds.Data.ToList());
}

OnBuildsUpdated(builds.Data.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())}.");
this.notificationProvider.ShowMessage("Failure on getting builds", $"Please check the connection for project(s) '{String.Join(", ", settings.SelectedBuildDefinitions.Select(b => b.Project.Name).Distinct())}'. See log for details.");
}
}

Expand Down
25 changes: 16 additions & 9 deletions BuildsAppReborn.Access/Tfs2017BuildProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ public async Task<DataResponse<IEnumerable<IBuildDefinition>>> GetBuildDefinitio
var requestUrl = $"{projectUrl}/_apis/build/definitions?api-version={ApiVersion}";

var requestResponse = await GetRequestResponse(requestUrl, settings);
var result = await requestResponse.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<List<Tfs2017BuildDefinition>>(JObject.Parse(result)["value"].ToString());

return new DataResponse<IEnumerable<IBuildDefinition>> {Data = data, StatusCode = requestResponse.StatusCode};
if (requestResponse.IsSuccessStatusCode)
{
var result = await requestResponse.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<List<Tfs2017BuildDefinition>>(JObject.Parse(result)["value"].ToString());

return new DataResponse<IEnumerable<IBuildDefinition>> {Data = data, StatusCode = requestResponse.StatusCode};
}
return new DataResponse<IEnumerable<IBuildDefinition>> {Data = Enumerable.Empty<IBuildDefinition>(), StatusCode = requestResponse.StatusCode};
}

throw new Exception($"Error while processing method!");
Expand All @@ -56,12 +60,15 @@ public async Task<DataResponse<IEnumerable<IBuild>>> GetBuilds(IEnumerable<IBuil
{
var buildDefinitionsCommaList = String.Join(",", buildDefinitionsList.Select(a => a.Id));
var requestUrl = $"{projectUrl}/_apis/build/builds?api-version={ApiVersion}&definitions={buildDefinitionsCommaList}&maxBuildsPerDefinition={maxBuilds}";

var requestResponse = await GetRequestResponse(requestUrl, settings);
var result = await requestResponse.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<List<Tfs2017Build>>(JObject.Parse(result)["value"].ToString());

return new DataResponse<IEnumerable<IBuild>> {Data = data, StatusCode = requestResponse.StatusCode};
if (requestResponse.IsSuccessStatusCode)
{
var result = await requestResponse.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<List<Tfs2017Build>>(JObject.Parse(result)["value"].ToString());

return new DataResponse<IEnumerable<IBuild>> {Data = data, StatusCode = requestResponse.StatusCode};
}
return new DataResponse<IEnumerable<IBuild>> {Data = Enumerable.Empty<IBuild>(), StatusCode = requestResponse.StatusCode};
}

throw new Exception($"Error while processing method!");
Expand Down
20 changes: 14 additions & 6 deletions BuildsAppReborn.Client/ViewModels/GeneralSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.Composition;
using System;
using System.ComponentModel.Composition;
using System.Reflection;
using BuildsAppReborn.Client.Interfaces;
using BuildsAppReborn.Contracts.Models;
using BuildsAppReborn.Infrastructure;
Expand All @@ -20,8 +22,19 @@ internal GeneralSettingsViewModel(GlobalSettingsContainer globalSettingsContaine

#endregion

#region Implementation of ICloseable

public void OnClose()
{
this.updateChecker.Start();
}

#endregion

#region Public Properties

public Version CurrentAppVersion => Assembly.GetEntryAssembly().GetName().Version;

public GeneralSettings GeneralSettings => this.globalSettingsContainer.GeneralSettings;

#endregion
Expand All @@ -31,11 +44,6 @@ internal GeneralSettingsViewModel(GlobalSettingsContainer globalSettingsContaine
private readonly GlobalSettingsContainer globalSettingsContainer;
private readonly UpdateChecker updateChecker;

public void OnClose()
{
this.updateChecker.Start();
}

#endregion
}
}
70 changes: 47 additions & 23 deletions BuildsAppReborn.Client/Views/GeneralSettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,80 @@
</UserControl.Resources>
<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="30" />
<RowDefinition Height="0" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Version number -->
<TextBlock Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
FontWeight="Bold"
Text="While in pre release state some settings are not available!" />
<TextBlock Grid.Row="1"
Text="Current Application Version" />
<TextBlock Grid.Row="0"
Grid.Column="2"
FontWeight="Bold"
Text="{Binding CurrentAppVersion}" />
<!-- Note -->
<TextBlock Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="3"
Text="Note: While in pre release state some settings are not available." />
<!-- Settings -->
<TextBlock Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Bottom"
Text="Check for updates" />
<CheckBox Grid.Row="1"
Grid.Column="1"
<CheckBox Grid.Row="3"
Grid.Column="2"
VerticalAlignment="Bottom"
IsChecked="{Binding GeneralSettings.CheckForUpdates}"
IsEnabled="True" />
<TextBlock Grid.Row="2"
<TextBlock Grid.Row="4"
Grid.Column="0"
VerticalAlignment="Bottom"
Text="Check interval (minutes)" />
<TextBox Grid.Row="2"
Grid.Column="1"
<TextBox Grid.Row="4"
Grid.Column="2"
Margin="0 -15 0 0"
VerticalAlignment="Bottom"
IsEnabled="False"
Text="{Binding GeneralSettings.UpdateCheckInterval,
Converter={StaticResource MinutesToTimeSpanConverter}}" />
<TextBlock Grid.Row="3"
<TextBlock Grid.Row="5"
Grid.Column="0"
VerticalAlignment="Bottom"
Text="Notify when update available" />
<CheckBox Grid.Row="3"
Grid.Column="1"
<CheckBox Grid.Row="5"
Grid.Column="2"
VerticalAlignment="Bottom"
IsChecked="{Binding GeneralSettings.NotifyOnNewUpdate}"
IsEnabled="True" />
<TextBlock Grid.Row="4"
<TextBlock Grid.Row="6"
Grid.Column="0"
VerticalAlignment="Bottom"
Text="Auto install update" />
<CheckBox Grid.Row="4"
Grid.Column="1"
<CheckBox Grid.Row="6"
Grid.Column="2"
VerticalAlignment="Bottom"
IsChecked="{Binding GeneralSettings.AutoInstall}"
IsEnabled="False" />
<TextBlock Grid.Row="5"
<TextBlock Grid.Row="7"
Grid.Column="0"
VerticalAlignment="Bottom"
Text="Include pre releases" />
<CheckBox Grid.Row="5"
Grid.Column="1"
<CheckBox Grid.Row="7"
Grid.Column="2"
VerticalAlignment="Bottom"
IsChecked="{Binding GeneralSettings.IncludePreReleases}"
IsEnabled="False" />
</Grid>
Expand Down

0 comments on commit 6fd7eb6

Please sign in to comment.