Skip to content

Commit

Permalink
- opening of artifacts and build details now async, shows waiting cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Grabarevic committed Jun 2, 2017
1 parent 9ee4ad1 commit 7548727
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 26 deletions.
63 changes: 37 additions & 26 deletions BuildsAppReborn.Client/ViewModels/BuildsStatusViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using BuildsAppReborn.Client.Interfaces;
using BuildsAppReborn.Contracts.Models;
using BuildsAppReborn.Contracts.UI;
using BuildsAppReborn.Infrastructure;
using BuildsAppReborn.Infrastructure.Wpf;
using log4net;
using Prism.Commands;

Expand All @@ -26,8 +28,8 @@ public BuildsStatusViewModel(BuildCache buildCache)
this.timer = new Timer {Interval = 10000, AutoReset = true}; // update every 10 seconds
this.timer.Elapsed += (sender, args) => { OnBuildCacheUpdated(null, null); };
BuildCache.CacheUpdated += OnBuildCacheUpdated;
HistoryClickCommand = new DelegateCommand<BuildItem>(OnHistoryClickCommand);
OpenArtifactCommand = new DelegateCommand<IArtifact>(OnOpenArtifactCommand);
HistoryClickCommand = new DelegateCommand<BuildItem>(a => Task.Run(() => OnHistoryClickCommand(a)));
OpenArtifactCommand = new DelegateCommand<IArtifact>(a => Task.Run(() => OnOpenArtifactCommand(a)));
}

#endregion
Expand Down Expand Up @@ -66,51 +68,60 @@ private void OnBuildCacheUpdated(Object sender, EventArgs eventArgs)

private void OnHistoryClickCommand(BuildItem item)
{
StartProcess(item?.Build?.PortalUrl);
using (new WaitingIndicator())
{
StartProcess(item?.Build?.PortalUrl);
}
}

private void OnOpenArtifactCommand(IArtifact artifact)
{
if (artifact != null)
{
// when it is a drop location folder, tries to be jump into the sub folder if possible
// ToDo: extract the artifact types in enums etc, as this is too TFS specific
if (artifact.Type == "FilePath" &&
!String.IsNullOrWhiteSpace(artifact.Data) &&
!String.IsNullOrWhiteSpace(artifact.Name))
using (new WaitingIndicator())
{
var combinedPath = Path.Combine(artifact.Data, artifact.Name);
if (Directory.Exists(combinedPath))
// when it is a drop location folder, tries to be jump into the sub folder if possible
// ToDo: extract the artifact types in enums etc, as this is too TFS specific
if (artifact.Type == "FilePath" &&
!String.IsNullOrWhiteSpace(artifact.Data) &&
!String.IsNullOrWhiteSpace(artifact.Name))
{
if (StartProcess(combinedPath))
var combinedPath = Path.Combine(artifact.Data, artifact.Name);
if (Directory.Exists(combinedPath))
{
return;
if (StartProcess(combinedPath))
{
return;
}
}
}
}

// fallback option to start the provided download URL
StartProcess(artifact.DownloadUrl);
// fallback option to start the provided download URL
StartProcess(artifact.DownloadUrl);
}
}
}

private Boolean StartProcess(String url)
{
if (!String.IsNullOrWhiteSpace(url))
using (new WaitingIndicator())
{
try
{
Process.Start(url);
return true;
}
catch (Exception exception)
if (!String.IsNullOrWhiteSpace(url))
{
this.logger.Warn("Exception on StartProcess", exception);
return false;
try
{
Process.Start(url);
return true;
}
catch (Exception exception)
{
this.logger.Warn("Exception on StartProcess", exception);
return false;
}
}
}

return false;
return false;
}
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\BuildsAppReborn.Client\Properties\GlobalAssemblyInfo.cs">
Expand All @@ -64,6 +66,7 @@
<Compile Include="UrlValidator.cs" />
<Compile Include="ViewModelBase.cs" />
<Compile Include="Wpf\InverseBooleanConverter.cs" />
<Compile Include="Wpf\WaitingIndicator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
36 changes: 36 additions & 0 deletions BuildsAppReborn.Infrastructure/Wpf/WaitingIndicator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Threading;
using System.Windows;
using System.Windows.Input;

namespace BuildsAppReborn.Infrastructure.Wpf
{
public class WaitingIndicator : IDisposable
{
#region Constructors

public WaitingIndicator()
{
Interlocked.Increment(ref count);
Application.Current.Dispatcher.Invoke(() => Mouse.OverrideCursor = Cursors.Wait);
}

#endregion

#region Implementation of IDisposable

public void Dispose()
{
Interlocked.Decrement(ref count);

if (count == 0)
{
Application.Current.Dispatcher.Invoke(() => Mouse.OverrideCursor = null);
}
}

#endregion

private static Int32 count;
}
}

0 comments on commit 7548727

Please sign in to comment.