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

Commit 5ed53a6

Browse files
Merge remote-tracking branch 'origin/master' into fixes/github-fork-limit-functionality
# Conflicts: # src/GitHub.Exports/Models/UsageModel.cs
2 parents 0061e2b + b9939d2 commit 5ed53a6

File tree

54 files changed

+1417
-591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1417
-591
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: 3 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" />
@@ -213,6 +214,7 @@
213214
<Compile Include="SampleData\ForkRepositoryExecuteViewModelDesigner.cs" />
214215
<Compile Include="SampleData\ForkRepositorySelectViewModelDesigner.cs" />
215216
<Compile Include="Models\PullRequestReviewModel.cs" />
217+
<Compile Include="SampleData\GitServiceDesigner.cs" />
216218
<Compile Include="SampleData\ForkRepositorySwitchViewModelDesigner.cs" />
217219
<Compile Include="SampleData\PullRequestFilesViewModelDesigner.cs" />
218220
<Compile Include="SampleData\PullRequestReviewAuthoringViewModelDesigner.cs" />
@@ -401,7 +403,7 @@
401403
</ItemGroup>
402404
<ItemGroup>
403405
<EmbeddedResource Include="Resources.resx">
404-
<Generator>ResXFileCodeGenerator</Generator>
406+
<Generator>PublicResXFileCodeGenerator</Generator>
405407
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
406408
<SubType>Designer</SubType>
407409
</EmbeddedResource>

0 commit comments

Comments
 (0)