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

Commit 6f96918

Browse files
Making UsageModel a class again & correcting tests
It made sense to have UsageModel be a struct before because it was a singular value. Now it is an element in an array, it is much easier to use an object in this situation.
1 parent b68e0cd commit 6f96918

File tree

4 files changed

+116
-151
lines changed

4 files changed

+116
-151
lines changed

src/GitHub.Exports/Models/UsageModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
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
{
87
public DimensionsModel Dimensions { get; set; }
98
public MeasuresModel Measures { get; set; }

src/GitHub.VisualStudio/Services/UsageService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ public async Task<Guid> GetUserGuid()
7777
return userGuid.Value;
7878
}
7979

80-
public bool IsToday(DateTimeOffset date)
81-
{
82-
return date.Date == DateTimeOffset.Now.Date;
83-
}
84-
8580
public IDisposable StartTimer(Func<Task> callback, TimeSpan dueTime, TimeSpan period)
8681
{
8782
return new Timer(

src/GitHub.VisualStudio/Services/UsageTracker.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async Task<UsageModel> GetCurrentReport(UsageData data)
126126
{
127127
var current = data.Reports.FirstOrDefault(x => x.Dimensions.Date.Date == DateTimeOffset.Now.Date);
128128

129-
if (Guid.Empty.Equals(current.Dimensions.Guid))
129+
if (current == null)
130130
{
131131
var guid = await service.GetUserGuid();
132132
current = UsageModel.Create(guid);
@@ -140,12 +140,12 @@ async Task<UsageModel> GetCurrentReport(UsageData data)
140140

141141
if (connectionManager.Connections.Any(x => x.HostAddress.IsGitHubDotCom()))
142142
{
143-
current.Dimensions.IsGitHubUser |= true;
143+
current.Dimensions.IsGitHubUser = true;
144144
}
145145

146146
if (connectionManager.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()))
147147
{
148-
current.Dimensions.IsEnterpriseUser |= true;
148+
current.Dimensions.IsEnterpriseUser = true;
149149
}
150150

151151
return current;

0 commit comments

Comments
 (0)