Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 0fc4dc2

Browse files
authored
Merge branch 'master' into fixes/1644-GitServiceHelper-avoid-MEF
2 parents acc9480 + 6cf4a55 commit 0fc4dc2

38 files changed

+1277
-488
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Windows.Input;
3+
using System.Linq.Expressions;
4+
using GitHub.Models;
5+
using GitHub.Services;
6+
using GitHub.Extensions;
7+
8+
namespace GitHub.Commands
9+
{
10+
/// <summary>
11+
/// A proxy <see cref="ICommand"/> that increments a usage counter after executing the command.
12+
/// </summary>
13+
public class UsageTrackingCommand : ICommand
14+
{
15+
readonly ICommand command;
16+
readonly Lazy<IUsageTracker> usageTracker;
17+
readonly Expression<Func<UsageModel.MeasuresModel, int>> counter;
18+
19+
/// <summary>
20+
/// The usage tracker and counter to increment after the target command is executed.
21+
/// </summary>
22+
/// <param name="usageTracker">The usage tracker.</param>
23+
/// <param name="counter">The counter to increment.</param>
24+
/// <param name="command">The target command.</param>
25+
public UsageTrackingCommand(
26+
Lazy<IUsageTracker> usageTracker, Expression<Func<UsageModel.MeasuresModel, int>> counter,
27+
ICommand command)
28+
{
29+
this.command = command;
30+
this.usageTracker = usageTracker;
31+
this.counter = counter;
32+
}
33+
34+
public event EventHandler CanExecuteChanged
35+
{
36+
add { command.CanExecuteChanged += value; }
37+
remove { command.CanExecuteChanged -= value; }
38+
}
39+
40+
public bool CanExecute(object parameter)
41+
{
42+
return command.CanExecute(parameter);
43+
}
44+
45+
public void Execute(object parameter)
46+
{
47+
command.Execute(parameter);
48+
usageTracker.Value.IncrementCounter(counter).Forget();
49+
}
50+
}
51+
}

src/GitHub.App/GitHub.App.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
<Reference Include="WindowsBase" />
206206
</ItemGroup>
207207
<ItemGroup>
208+
<Compile Include="Commands\UsageTrackingCommand.cs" />
208209
<Compile Include="Factories\ViewViewModelFactory.cs" />
209210
<Compile Include="Factories\ModelServiceFactory.cs" />
210211
<Compile Include="Models\IssueCommentModel.cs" />
@@ -402,7 +403,7 @@
402403
</ItemGroup>
403404
<ItemGroup>
404405
<EmbeddedResource Include="Resources.resx">
405-
<Generator>ResXFileCodeGenerator</Generator>
406+
<Generator>PublicResXFileCodeGenerator</Generator>
406407
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
407408
<SubType>Designer</SubType>
408409
</EmbeddedResource>

src/GitHub.App/Resources.Designer.cs

Lines changed: 68 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)