Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e868ea4

Browse files
committed
Save the language and assembly info too, rename id to guid
1 parent aea0fb7 commit e868ea4

File tree

10 files changed

+31
-51
lines changed

10 files changed

+31
-51
lines changed

script

src/GitHub.Api/Api/ApiClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ namespace GitHub.Unity
77
{
88
class ApiClient : IApiClient
99
{
10-
public static IApiClient Create(UriString repositoryUrl, IKeychain keychain, IAppConfiguration appConfiguration)
10+
public static IApiClient Create(UriString repositoryUrl, IKeychain keychain)
1111
{
1212
var credentialStore = keychain.Connect(repositoryUrl);
1313
var hostAddress = HostAddress.Create(repositoryUrl);
1414

1515
return new ApiClient(repositoryUrl, keychain,
16-
new GitHubClient(appConfiguration.ProductHeader, credentialStore, hostAddress.ApiUri));
16+
new GitHubClient(AppConfiguration.ProductHeader, credentialStore, hostAddress.ApiUri));
1717
}
1818

1919
private static readonly Unity.ILogging logger = Unity.Logging.GetLogger<ApiClient>();

src/GitHub.Api/AppConfiguration.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace GitHub.Unity
55
{
6-
class AppConfiguration : IAppConfiguration
6+
static class AppConfiguration
77
{
8-
public AppConfiguration()
8+
static AppConfiguration()
99
{
1010
var executingAssembly = typeof(AppConfiguration).Assembly;
1111
AssemblyName = executingAssembly.GetName();
@@ -15,11 +15,11 @@ public AppConfiguration()
1515
/// <summary>
1616
/// The currently executing assembly.
1717
/// </summary>
18-
public AssemblyName AssemblyName { get; private set; }
18+
public static AssemblyName AssemblyName { get; private set; }
1919

2020
/// <summary>
2121
/// The product header used in the user agent.
2222
/// </summary>
23-
public ProductHeaderValue ProductHeader { get; private set; }
23+
public static ProductHeaderValue ProductHeader { get; private set; }
2424
}
2525
}

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@
219219
<Compile Include="Guard.cs" />
220220
<Compile Include="Authentication\ICredentialManager.cs" />
221221
<Compile Include="IEnvironment.cs" />
222-
<Compile Include="IAppConfiguration.cs" />
223222
<Compile Include="Primitives\HostAddress.cs" />
224223
<Compile Include="Primitives\StringEquivalent.cs" />
225224
<Compile Include="Primitives\UriString.cs" />

src/GitHub.Api/IAppConfiguration.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/GitHub.Api/Metrics/UsageModel.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitHub.Unity
66
{
77
class Usage
88
{
9-
public string Id { get; set; }
9+
public string Guid { get; set; }
1010
public DateTime Date { get; set; }
1111
public string AppVersion { get; set; }
1212
public string UnityVersion { get; set; }
@@ -17,28 +17,27 @@ class Usage
1717
class UsageModel
1818
{
1919
public List<Usage> Reports { get; set; } = new List<Usage>();
20-
public string Id { get; set; }
20+
public string Guid { get; set; }
2121

2222
private Usage currentUsage;
2323

2424
public Usage GetCurrentUsage()
2525
{
2626
var date = DateTime.UtcNow.Date;
27-
if (currentUsage != null)
27+
if (currentUsage == null)
2828
{
29-
if (currentUsage.Date == date)
30-
{
31-
return currentUsage;
32-
}
33-
34-
currentUsage = null;
29+
currentUsage = Reports.FirstOrDefault(usage => usage.Date == date);
3530
}
3631

37-
currentUsage = Reports.FirstOrDefault(usage => usage.Date == date);
38-
39-
if (currentUsage == null)
32+
if (currentUsage?.Date == date)
33+
{
34+
// update any fields that might be missing, if we've changed the format
35+
if (currentUsage.Guid != Guid)
36+
currentUsage.Guid = Guid;
37+
}
38+
else
4039
{
41-
currentUsage = new Usage { Date = date, Id = Id };
40+
currentUsage = new Usage { Date = date, Guid = Guid };
4241
Reports.Add(currentUsage);
4342
}
4443

src/GitHub.Api/Metrics/UsageTracker.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using System.Timers;
66
using Rackspace.Threading;
7+
using System.Globalization;
78

89
namespace GitHub.Unity
910
{
@@ -13,19 +14,19 @@ class UsageTracker : IUsageTracker
1314
private static IMetricsService metricsService;
1415

1516
private readonly NPath storePath;
16-
private readonly string id;
17+
private readonly string guid;
1718
private readonly string unityVersion;
1819

1920
private bool firstRun = true;
2021
private Timer timer;
2122

22-
public UsageTracker(NPath storePath, string id, string unityVersion)
23+
public UsageTracker(NPath storePath, string guid, string unityVersion)
2324
{
24-
this.id = id;
25+
this.guid = guid;
2526
this.storePath = storePath;
2627
this.unityVersion = unityVersion;
2728

28-
Logger.Trace("id:{0}", id);
29+
Logger.Trace("guid:{0}", guid);
2930
RunTimer();
3031
}
3132

@@ -60,15 +61,8 @@ private UsageStore LoadUsage()
6061
if (result == null)
6162
{
6263
result = new UsageStore();
63-
result.Model.Id = id;
64+
result.Model.Guid = guid;
6465
}
65-
//TODO: Figure out these values
66-
//result.Model.Lang = CultureInfo.InstalledUICulture.IetfLanguageTag;
67-
//result.Model.AppVersion = AssemblyVersionInformation.Version;
68-
69-
//TODO: Get Unity Version
70-
//result.Model.UnityVersion
71-
//result.Model.VSVersion = vsservices.VSVersion;
7266

7367
return result;
7468
}
@@ -196,6 +190,8 @@ public void IncrementLaunchCount()
196190
var usage = usageStore.Model.GetCurrentUsage();
197191
usage.NumberOfStartups++;
198192
usage.UnityVersion = unityVersion;
193+
usage.Lang = CultureInfo.InstalledUICulture.IetfLanguageTag;
194+
usage.AppVersion = AppConfiguration.AssemblyName.Version.ToString();
199195

200196
Logger.Trace("IncrementLaunchCount Date:{0} NumberOfStartups:{1}", usage.Date, usage.NumberOfStartups);
201197

src/UnityExtension/Assets/Editor/GitHub.Unity/Services/AuthenticationService.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ namespace GitHub.Unity
55
{
66
class AuthenticationService
77
{
8-
private readonly IAppConfiguration appConfiguration;
98
private readonly IApiClient client;
109

1110
private LoginResult loginResultData;
1211

13-
public AuthenticationService(UriString host, IAppConfiguration appConfiguration, IKeychain keychain)
12+
public AuthenticationService(UriString host, IKeychain keychain)
1413
{
15-
this.appConfiguration = appConfiguration;
16-
client = ApiClient.Create(host, keychain, appConfiguration);
14+
client = ApiClient.Create(host, keychain);
1715
}
1816

1917
public void Login(string username, string password, Action<string> twofaRequired, Action<bool, string> authResult)

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private AuthenticationService AuthenticationService
4545
host = UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
4646
}
4747

48-
AuthenticationService = new AuthenticationService(host, new AppConfiguration(), Platform.Keychain);
48+
AuthenticationService = new AuthenticationService(host, Platform.Keychain);
4949
}
5050
return authenticationService;
5151
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private void SignOut(object obj)
234234
host = UriString.ToUriString(HostAddress.GitHubDotComHostAddress.WebUri);
235235
}
236236

237-
var apiClient = ApiClient.Create(host, Platform.Keychain, new AppConfiguration());
237+
var apiClient = ApiClient.Create(host, Platform.Keychain);
238238
apiClient.Logout(host);
239239
}
240240

0 commit comments

Comments
 (0)