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

Commit 7b734a8

Browse files
authored
Merge pull request #575 from github-for-unity/shana/async-rollup-fixes
Download cancellation and progress reporting
2 parents ad4357e + 4cc04a6 commit 7b734a8

File tree

83 files changed

+1701
-814
lines changed

Some content is hidden

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

83 files changed

+1701
-814
lines changed

GitHub.Unity.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskSystem", "src\tests\Tas
2727
EndProject
2828
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "src\tests\TestApp\TestApp.csproj", "{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}"
2929
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWebServer", "src\tests\TestWebServer\TestWebServer.csproj", "{3DD3451C-30FA-4294-A3A9-1E080342F867}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -94,6 +96,12 @@ Global
9496
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.dev|Any CPU.Build.0 = Debug|Any CPU
9597
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
9698
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Release|Any CPU.Build.0 = Release|Any CPU
99+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
100+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Debug|Any CPU.Build.0 = Debug|Any CPU
101+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.dev|Any CPU.ActiveCfg = Debug|Any CPU
102+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.dev|Any CPU.Build.0 = Debug|Any CPU
103+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Release|Any CPU.Build.0 = Release|Any CPU
97105
EndGlobalSection
98106
GlobalSection(SolutionProperties) = preSolution
99107
HideSolutionNode = FALSE
@@ -106,5 +114,6 @@ Global
106114
{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
107115
{1A382F40-FD9E-43E1-89C1-320073F35CE9} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
108116
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
117+
{3DD3451C-30FA-4294-A3A9-1E080342F867} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
109118
EndGlobalSection
110119
EndGlobal

script

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Octokit;
6+
using GitHub.Logging;
67

78
namespace GitHub.Unity
89
{
@@ -16,10 +17,10 @@ public static IApiClient Create(UriString repositoryUrl, IKeychain keychain)
1617
var hostAddress = HostAddress.Create(repositoryUrl);
1718

1819
return new ApiClient(repositoryUrl, keychain,
19-
new GitHubClient(AppConfiguration.ProductHeader, credentialStore, hostAddress.ApiUri));
20+
new GitHubClient(ApplicationConfiguration.ProductHeader, credentialStore, hostAddress.ApiUri));
2021
}
2122

22-
private static readonly ILogging logger = Logging.GetLogger<ApiClient>();
23+
private static readonly ILogging logger = LogHelper.GetLogger<ApiClient>();
2324
public HostAddress HostAddress { get; }
2425
public UriString OriginalUrl { get; }
2526

src/GitHub.Api/Application/AppConfiguration.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using Octokit;
3+
4+
namespace GitHub.Unity
5+
{
6+
public static class ApplicationConfiguration
7+
{
8+
public const int DefaultWebTimeout = 3000;
9+
10+
static ApplicationConfiguration()
11+
{
12+
var executingAssembly = typeof(ApplicationConfiguration).Assembly;
13+
AssemblyName = executingAssembly.GetName();
14+
ProductHeader = new ProductHeaderValue(ApplicationInfo.ApplicationSafeName, AssemblyName.Version.ToString());
15+
}
16+
17+
/// <summary>
18+
/// The currently executing assembly.
19+
/// </summary>
20+
public static AssemblyName AssemblyName { get; }
21+
22+
/// <summary>
23+
/// The product header used in the user agent.
24+
/// </summary>
25+
public static ProductHeaderValue ProductHeader { get; private set; }
26+
27+
public static int WebTimeout { get; set; } = DefaultWebTimeout;
28+
}
29+
}

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using System.Linq;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using Octokit;
65
using System.Collections.Generic;
6+
using GitHub.Logging;
77

88
namespace GitHub.Unity
99
{
1010
abstract class ApplicationManagerBase : IApplicationManager
1111
{
12-
protected static ILogging Logger { get; } = Logging.GetLogger<IApplicationManager>();
12+
protected static ILogging Logger { get; } = LogHelper.GetLogger<IApplicationManager>();
1313

1414
private RepositoryManager repositoryManager;
1515

@@ -36,7 +36,7 @@ protected void Initialize()
3636
LocalSettings.Initialize();
3737
SystemSettings.Initialize();
3838

39-
Logging.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
39+
LogHelper.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
4040
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4141
Platform.Initialize(ProcessManager, TaskManager);
4242
GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token);
@@ -47,66 +47,23 @@ public void Run(bool firstRun)
4747
{
4848
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
4949

50-
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
51-
.ThenInUI(InitializeUI);
52-
53-
//GitClient.GetConfig cannot be called until there is a git path set so it is wrapped in an ActionTask
54-
var windowsCredentialSetup = new ActionTask(CancellationToken, () => {
55-
GitClient.GetConfig("credential.helper", GitConfigSource.Global).Then((b, credentialHelper) => {
56-
if (!string.IsNullOrEmpty(credentialHelper))
57-
{
58-
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
59-
afterGitSetup.Start();
60-
}
61-
else
62-
{
63-
Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");
64-
65-
GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
66-
.Then(() => { afterGitSetup.Start(); }).Start();
67-
}
68-
}).Start();
69-
});
70-
71-
var afterPathDetermined = new ActionTask<NPath>(CancellationToken, (b, path) => {
72-
Logger.Trace("Setting Environment git path: {0}", path);
73-
Environment.GitExecutablePath = path;
74-
}).ThenInUI(() => {
75-
Environment.User.Initialize(GitClient);
76-
77-
if (Environment.IsWindows)
78-
{
79-
windowsCredentialSetup.Start();
80-
}
81-
else
82-
{
83-
afterGitSetup.Start();
84-
}
85-
});
86-
87-
88-
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
89-
if (gitExecutablePath != null && gitExecutablePath.FileExists())
50+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
51+
if (gitExecutablePath != null && gitExecutablePath.FileExists()) // we have a git path
9052
{
9153
Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
92-
93-
new FuncTask<NPath>(CancellationToken, () => gitExecutablePath)
94-
.Then(afterPathDetermined)
95-
.Start();
54+
InitializeEnvironment(gitExecutablePath);
9655
}
97-
else
56+
else // we need to go find git
9857
{
9958
Logger.Trace("No git path found in settings");
10059

60+
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken, (b, path) => InitializeEnvironment(path)) { Affinity = TaskAffinity.UI };
10161
var findExecTask = new FindExecTask("git", CancellationToken)
102-
.Finally((b, ex, path) => {
62+
.FinallyInUI((b, ex, path) => {
10363
if (b && path != null)
10464
{
10565
Logger.Trace("FindExecTask Success: {0}", path);
106-
107-
new FuncTask<NPath>(CancellationToken, () => path)
108-
.Then(afterPathDetermined)
109-
.Start();
66+
InitializeEnvironment(gitExecutablePath);
11067
}
11168
else
11269
{
@@ -119,15 +76,8 @@ public void Run(bool firstRun)
11976
var installDetails = new GitInstallDetails(applicationDataPath, true);
12077
var gitInstaller = new GitInstaller(Environment, CancellationToken, installDetails);
12178

122-
gitInstaller.SetupGitIfNeeded(new ActionTask<NPath>(CancellationToken, (b, path) => {
123-
Logger.Trace("GitInstaller Success: {0}", path);
124-
new FuncTask<NPath>(CancellationToken, () => path)
125-
.Then(afterPathDetermined)
126-
.Start();
127-
}), new ActionTask(CancellationToken, () => {
128-
Logger.Warning("GitInstaller Failure");
129-
findExecTask.Start();
130-
}));
79+
// if successful, continue with environment initialization, otherwise try to find an existing git installation
80+
gitInstaller.SetupGitIfNeeded(initEnvironmentTask, findExecTask);
13181
}
13282
}
13383

@@ -216,6 +166,45 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
216166
protected abstract void InitializeUI();
217167
protected abstract void SetProjectToTextSerialization();
218168

169+
/// <summary>
170+
/// Initialize environment after finding where git is. This needs to run on the main thread
171+
/// </summary>
172+
/// <param name="gitExecutablePath"></param>
173+
private void InitializeEnvironment(NPath gitExecutablePath)
174+
{
175+
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
176+
.ThenInUI(InitializeUI);
177+
178+
Environment.GitExecutablePath = gitExecutablePath;
179+
Environment.User.Initialize(GitClient);
180+
181+
if (Environment.IsWindows)
182+
{
183+
GitClient
184+
.GetConfig("credential.helper", GitConfigSource.Global)
185+
.Then((b, credentialHelper) => {
186+
if (!string.IsNullOrEmpty(credentialHelper))
187+
{
188+
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
189+
afterGitSetup.Start();
190+
}
191+
else
192+
{
193+
Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");
194+
195+
GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
196+
.Then(afterGitSetup)
197+
.Start();
198+
}
199+
})
200+
.Start();
201+
}
202+
else
203+
{
204+
afterGitSetup.Start();
205+
}
206+
}
207+
219208
private bool disposed = false;
220209
protected virtual void Dispose(bool disposing)
221210
{

src/GitHub.Api/Authentication/Keychain.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Octokit;
6+
using GitHub.Logging;
67

78
namespace GitHub.Unity
89
{
@@ -22,7 +23,7 @@ class Keychain : IKeychain
2223
{
2324
const string ConnectionFile = "connections.json";
2425

25-
private readonly ILogging logger = Logging.GetLogger<Keychain>();
26+
private readonly ILogging logger = LogHelper.GetLogger<Keychain>();
2627

2728
private readonly ICredentialManager credentialManager;
2829
private readonly NPath cachePath;

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Net;
33
using System.Threading.Tasks;
44
using Octokit;
5+
using GitHub.Logging;
56

67
namespace GitHub.Unity
78
{
@@ -19,7 +20,7 @@ public enum LoginResultCodes
1920
/// </summary>
2021
class LoginManager : ILoginManager
2122
{
22-
private readonly ILogging logger = Logging.GetLogger<LoginManager>();
23+
private readonly ILogging logger = LogHelper.GetLogger<LoginManager>();
2324

2425
private readonly string[] scopes = { "user", "repo", "gist", "write:public_key" };
2526
private readonly IKeychain keychain;

src/GitHub.Api/Events/RepositoryWatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using sfw.net;
7+
using GitHub.Logging;
78

89
namespace GitHub.Unity
910
{
@@ -293,7 +294,7 @@ public void Dispose()
293294
Dispose(true);
294295
}
295296

296-
protected static ILogging Logger { get; } = Logging.GetLogger<RepositoryWatcher>();
297+
protected static ILogging Logger { get; } = LogHelper.GetLogger<RepositoryWatcher>();
297298

298299
private enum EventType
299300
{

src/GitHub.Api/Git/GitClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using GitHub.Logging;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Threading;
@@ -401,7 +402,7 @@ public ITask<string> Unlock(string file, bool force,
401402
.Configure(processManager);
402403
}
403404

404-
protected static ILogging Logger { get; } = Logging.GetLogger<GitClient>();
405+
protected static ILogging Logger { get; } = LogHelper.GetLogger<GitClient>();
405406
}
406407

407408
public struct GitUser

0 commit comments

Comments
 (0)