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

Commit a77a6a6

Browse files
Merge remote-tracking branch 'remotes/origin/master' into fixes/open-source-ready
2 parents 692b639 + 5f3aa0c commit a77a6a6

32 files changed

+480
-84
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[submodule "script"]
2+
path = script
3+
url = [email protected]:github/UnityBuildScripts
14
[submodule "submodules/octokit.net"]
25
path = submodules/octokit.net
36
url = https://github.com/editor-tools/octokit.net.git

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh -eux
2-
Configuration="Debug"
2+
Configuration="dev"
33
if [ $# -gt 0 ]; then
44
Configuration=$1
55
fi

script

Submodule script added at 8b3a7f0

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System.Reflection;
2-
using GitHub.Unity;
32
using Octokit;
43

54
namespace GitHub.Unity
65
{
7-
class AppConfiguration : IAppConfiguration
6+
static class AppConfiguration
87
{
9-
public AppConfiguration()
8+
static AppConfiguration()
109
{
1110
var executingAssembly = typeof(AppConfiguration).Assembly;
1211
AssemblyName = executingAssembly.GetName();
@@ -16,11 +15,11 @@ public AppConfiguration()
1615
/// <summary>
1716
/// The currently executing assembly.
1817
/// </summary>
19-
public AssemblyName AssemblyName { get; private set; }
18+
public static AssemblyName AssemblyName { get; private set; }
2019

2120
/// <summary>
2221
/// The product header used in the user agent.
2322
/// </summary>
24-
public ProductHeaderValue ProductHeader { get; private set; }
23+
public static ProductHeaderValue ProductHeader { get; private set; }
2524
}
2625
}

src/GitHub.Api/ApplicationManagerBase.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ abstract class ApplicationManagerBase : IApplicationManager
1111
protected static ILogging Logger { get; } = Logging.GetLogger<IApplicationManager>();
1212

1313
private IEnvironment environment;
14-
private AppConfiguration appConfiguration;
1514
private RepositoryManager repositoryManager;
1615

1716
public ApplicationManagerBase(SynchronizationContext synchronizationContext)
@@ -36,7 +35,7 @@ protected void Initialize()
3635
LocalSettings.Initialize();
3736
SystemSettings.Initialize();
3837

39-
Logging.TracingEnabled = UserSettings.Get("EnableTraceLogging", false);
38+
Logging.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
4039
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4140
Platform.Initialize(ProcessManager, TaskManager);
4241
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
@@ -93,7 +92,7 @@ public virtual ITask RestartRepository()
9392
var gitConfig = new GitConfig(repositoryPathConfiguration.DotGitConfig);
9493

9594
var repositoryWatcher = new RepositoryWatcher(Platform, repositoryPathConfiguration, TaskManager.Token);
96-
repositoryManager = new RepositoryManager(Platform, TaskManager, gitConfig, repositoryWatcher,
95+
repositoryManager = new RepositoryManager(Platform, TaskManager, UsageTracker, gitConfig, repositoryWatcher,
9796
GitClient, repositoryPathConfiguration, TaskManager.Token);
9897

9998
await repositoryManager.Initialize().SafeAwait();
@@ -135,7 +134,7 @@ private async Task SetupAndRestart(ProgressReport progress)
135134
private async Task<NPath> LookForGitInstallationPath()
136135
{
137136
NPath cachedGitInstallPath = null;
138-
var path = SystemSettings.Get("GitInstallPath");
137+
var path = SystemSettings.Get(Constants.GitInstallPathKey);
139138
if (!String.IsNullOrEmpty(path))
140139
cachedGitInstallPath = path.ToNPath();
141140

@@ -147,6 +146,32 @@ private async Task<NPath> LookForGitInstallationPath()
147146
return await GitClient.FindGitInstallation().SafeAwait();
148147
}
149148

149+
protected void SetupMetrics(string unityVersion, bool firstRun)
150+
{
151+
Logger.Trace("Setup metrics");
152+
153+
var usagePath = Environment.UserCachePath.Combine(Constants.UsageFile);
154+
155+
string id = null;
156+
if (UserSettings.Exists(Constants.GuidKey))
157+
{
158+
id = UserSettings.Get(Constants.GuidKey);
159+
}
160+
161+
if (String.IsNullOrEmpty(id))
162+
{
163+
id = Guid.NewGuid().ToString();
164+
UserSettings.Set(Constants.GuidKey, id);
165+
}
166+
167+
UsageTracker = new UsageTracker(UserSettings, usagePath, id, unityVersion);
168+
169+
if (firstRun)
170+
{
171+
UsageTracker.IncrementLaunchCount();
172+
}
173+
}
174+
150175
private bool disposed = false;
151176
protected virtual void Dispose(bool disposing)
152177
{
@@ -164,14 +189,6 @@ public void Dispose()
164189
Dispose(true);
165190
}
166191

167-
public AppConfiguration AppConfiguration
168-
{
169-
get
170-
{
171-
return appConfiguration ?? (appConfiguration = new AppConfiguration());
172-
}
173-
}
174-
175192
public IEnvironment Environment
176193
{
177194
get
@@ -209,5 +226,6 @@ public IEnvironment Environment
209226
public ISettings LocalSettings { get; protected set; }
210227
public ISettings SystemSettings { get; protected set; }
211228
public ISettings UserSettings { get; protected set; }
229+
public IUsageTracker UsageTracker { get; protected set; }
212230
}
213231
}

src/GitHub.Api/Constants.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace GitHub.Unity
2+
{
3+
static class Constants
4+
{
5+
public const string GuidKey = "Guid";
6+
public const string MetricsKey = "MetricsEnabled";
7+
public const string UsageFile = "usage.json";
8+
public const string GitInstallPathKey = "GitInstallPath";
9+
public const string TraceLoggingKey = "EnableTraceLogging";
10+
}
11+
}

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AssemblyName>GitHub.Api</AssemblyName>
1212
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14-
<BuildType Condition="Exists('..\..\script\src\ApiClientConfiguration.cs')">Internal</BuildType>
14+
<BuildType Condition="Exists('$(SolutionDir)\script\src\MetricsService.cs')">Internal</BuildType>
1515
<OutputPath>bin\$(Configuration)\</OutputPath>
1616
<TargetFrameworkProfile />
1717
<LangVersion>6</LangVersion>
@@ -47,7 +47,7 @@
4747
<DebugSymbols>true</DebugSymbols>
4848
<DebugType>full</DebugType>
4949
<Optimize>false</Optimize>
50-
<DefineConstants>DEBUG;TRACE;DEVELOPER_BUILD</DefineConstants>
50+
<DefineConstants>TRACE;DEBUG;DEVELOPER_BUILD</DefineConstants>
5151
<ErrorReport>prompt</ErrorReport>
5252
<WarningLevel>4</WarningLevel>
5353
<RunCodeAnalysis>false</RunCodeAnalysis>
@@ -102,6 +102,7 @@
102102
<Compile Include="Authentication\LoginManager.cs" />
103103
<Compile Include="Authentication\ILoginManager.cs" />
104104
<Compile Include="ApplicationManagerBase.cs" />
105+
<Compile Include="Constants.cs" />
105106
<Compile Include="DefaultEnvironment.cs" />
106107
<Compile Include="Extensions\EnvironmentExtensions.cs" />
107108
<Compile Include="Extensions\FileEventExtensions.cs" />
@@ -128,6 +129,13 @@
128129
<Compile Include="NewTaskSystem\TaskManager.cs" />
129130
<Compile Include="Platform\FindExecTask.cs" />
130131
<Compile Include="ProgressReport.cs" />
132+
<Compile Include="Metrics\IMetricsService.cs" />
133+
<Compile Include="Metrics\IUsageTracker.cs" />
134+
<Compile Include="Metrics\UsageModel.cs" />
135+
<Compile Include="Metrics\UsageTracker.cs" />
136+
<Compile Include="$(SolutionDir)\script\src\MetricsService.cs" Condition="$(Buildtype) == 'Internal'">
137+
<Link>Metrics\MetricsService.cs</Link>
138+
</Compile>
131139
<Compile Include="Git\Tasks\GitLfsInstallTask.cs" />
132140
<Compile Include="Extensions\GitStatusExtensions.cs" />
133141
<Compile Include="Git\Tasks\GitRemoteChangeTask.cs" />
@@ -212,7 +220,6 @@
212220
<Compile Include="Guard.cs" />
213221
<Compile Include="Authentication\ICredentialManager.cs" />
214222
<Compile Include="IEnvironment.cs" />
215-
<Compile Include="IAppConfiguration.cs" />
216223
<Compile Include="Primitives\HostAddress.cs" />
217224
<Compile Include="Primitives\StringEquivalent.cs" />
218225
<Compile Include="Primitives\UriString.cs" />
@@ -226,6 +233,10 @@
226233
<Compile Include="Api\ApiClient.cs" />
227234
</ItemGroup>
228235
<ItemGroup>
236+
<ProjectReference Include="..\..\submodules\dotnet-httpClient35\System.Net.Http\System.Net.Http-net_3_5.csproj">
237+
<Project>{9862694D-E4FA-418B-8692-A0280FEDDF36}</Project>
238+
<Name>System.Net.Http-net_3_5</Name>
239+
</ProjectReference>
229240
<ProjectReference Include="..\..\submodules\octokit.net\Octokit-Extensions35\Octokit-Extensions35.csproj">
230241
<Project>{eb4b074e-62a7-4f1d-8f95-e64b7aea0236}</Project>
231242
<Name>Octokit-Extensions35</Name>

src/GitHub.Api/GitHub.Api.csproj.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=io/@EntryIndexedValue">True</s:Boolean>
99
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=io_005Cwatchers/@EntryIndexedValue">True</s:Boolean>
1010
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=io_005Cwatches/@EntryIndexedValue">True</s:Boolean>
11+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=metrics/@EntryIndexedValue">True</s:Boolean>
1112
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=outputprocessors/@EntryIndexedValue">True</s:Boolean>
1213
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platform/@EntryIndexedValue">True</s:Boolean>
1314
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=primitives/@EntryIndexedValue">True</s:Boolean>

src/GitHub.Api/IAppConfiguration.cs

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

0 commit comments

Comments
 (0)