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

Commit 24b63c1

Browse files
Changing UsageModel back to a class
1 parent af62175 commit 24b63c1

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/GitHub.Exports/Models/UsageModel.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
namespace GitHub.Models
44
{
5-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes", Justification = "It'll use reflection by default and we're fine with that")]
6-
public struct UsageModel
5+
public class UsageModel
76
{
8-
public static UsageModel Default = new UsageModel
9-
{
10-
Guid = Guid.Empty
11-
};
12-
137
public Guid Guid { get; set; }
148
public DateTimeOffset Date { get; set; }
159
public string AppVersion { get; set; }

src/GitHub.VisualStudio/Services/UsageTracker.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,12 @@ public async Task IncrementCounter(Expression<Func<UsageModel, int>> counter)
4848
await Initialize();
4949
var data = await service.ReadLocalData();
5050
var usage = await GetCurrentReport(data);
51-
// because Model is a struct, it needs to be boxed in order for reflection to work
52-
object model = usage;
5351
var property = (MemberExpression)counter.Body;
5452
var propertyInfo = (PropertyInfo)property.Member;
5553
log.Verbose("Increment counter {Name}", propertyInfo.Name);
56-
var value = (int)propertyInfo.GetValue(model);
57-
propertyInfo.SetValue(model, value + 1);
58-
59-
//TODO: Understand changes here
60-
//usage.Model = (UsageModel)model;
61-
//await service.WriteLocalData(data);
54+
var value = (int)propertyInfo.GetValue(usage);
55+
propertyInfo.SetValue(usage, value + 1);
56+
await service.WriteLocalData(data);
6257
}
6358

6459
IDisposable StartTimer()
@@ -131,7 +126,7 @@ async Task<UsageModel> GetCurrentReport(UsageData data)
131126
{
132127
var current = data.Reports.FirstOrDefault(x => x.Date.Date == DateTimeOffset.Now.Date);
133128

134-
if (current.Equals(UsageModel.Default))
129+
if (current == null)
135130
{
136131
var guid = await service.GetUserGuid();
137132
current = UsageModel.Create(guid);

0 commit comments

Comments
 (0)