8000 Master PR for refactoring connections by grokys · Pull Request #1277 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

Master PR for refactoring connections #1277

Merged
merged 43 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b790d96
ILoginCache -> IKeychain
grokys Aug 25, 2017
1c81104
Use IKeychain for credentials.
grokys Aug 25, 2017
21f888e
Updated parameter name.
grokys Aug 25, 2017
7e061d1
Removed unneeded usings.
grokys Aug 25, 2017
c8b8dd7
Updated variable names.
grokys Aug 25, 2017
95f2c0b
Remove `IObservableKeychainAdapter`.
grokys Aug 25, 2017
7b4080f
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Aug 30, 2017
3b13736
Store "master" credential.
grokys Aug 30, 2017
a142423
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Sep 7, 2017
bcfbd79
Fix broken merge.
grokys Sep 7, 2017
c52a261
Merge branch 'fixes/1176-duplicate-login-classes' into fixes/harden-c…
grokys Sep 7, 2017
e6c5d89
Merge branch 'master' into fixes/1176-duplicate-login-classes
grokys Oct 20, 2017
17c845e
Merge branch 'fixes/1176-duplicate-login-classes' into fixes/harden-c…
grokys Oct 20, 2017
a627271
Merge branch 'master' into refactor/connections-master
grokys Oct 20, 2017
470ea13
Removed `IConnection.Repositories`.
grokys Oct 20, 2017
d98ec51
Refactored ConnectionManager/Connection.
grokys Oct 23, 2017
aa78f03
Refactored RepositoryHost(s).
grokys Oct 23, 2017
7cf89c9
Added DebuggerDisplay back in.
grokys Oct 23, 2017
213a7fc
Moved LocalRepositories to GitHub.VisualStudio.
grokys Oct 24, 2017
90c35c5
Track login metrics.
grokys Oct 26, 2017
9db05a7
Fix failing tests.
grokys Oct 26, 2017
f854b79
WIP: Removing RepositoryHost(s)
grokys Oct 26, 2017
3240372
WIP: Still removing RepositoryHost(s)
grokys Oct 26, 2017
038f232
WIP: Removing RepositoryHost(s) from tests.
grokys Oct 26, 2017
a57a759
Finished migrating tests (I think).
grokys Oct 27, 2017
95cd0b1
Added IModelServiceFactory implemenation.
grokys Oct 27, 2017
6034643
Added IGlobalConnection.
grokys Oct 27, 2017
17aebf8
Removed ConnectionManager.ConnectionCreated.
grokys Oct 27, 2017
00232f0
Merge branch 'master' into refactor/connections-master
grokys Nov 3, 2017
01aad33
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys Nov 3, 2017
217e415
Merge branch 'refactor/connections/local-repositories' into refactor/…
grokys Nov 3, 2017
7e57621
Insert AccountCacheItem for connection.
grokys Nov 7, 2017
e45d0c6
Merge branch 'master' into refactor/connections-master
grokys Nov 7, 2017
8f6d218
Merge branch 'refactor/connections-master' into refactor/connections/…
grokys Nov 7, 2017
32f073a
Merge branch 'refactor/connections/local-repositories' into refactor/…
grokys Nov 7, 2017
9f15db6
Merge branch 'refactor/connection-manager' into refactor/connections/…
grokys Nov 7, 2017
cd546bb
Fix CA errors.
grokys Nov 7, 2017
def6070
Merge pull request #1283 from github/refactor/connections/remove-repo…
grokys Nov 8, 2017
fc57163
Merge branch 'master' into refactor/connections-master
grokys Nov 8, 2017
d9c2a2f
Removed empty file.
grokys Nov 8, 2017
cefd4b9
Merge branch 'master' into refactor/connections-master
grokys Nov 14, 2017
7d7b188
Merge branch 'master' into refactor/connections-master
grokys Nov 20, 2017
4701dd0
Merge branch 'master' into refactor/connections-master
grokys Nov 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .ncrunch/GitHub.Logging.v3.ncrunchproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
</Settings>
</ProjectConfiguration>
12 changes: 12 additions & 0 deletions GitHubVS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.InlineReviews", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.InlineReviews.UnitTests", "test\GitHub.InlineReviews.UnitTests\GitHub.InlineReviews.UnitTests.csproj", "{17EB676B-BB91-48B5-AA59-C67695C647C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.Logging", "src\GitHub.Logging\GitHub.Logging.csproj", "{8D73575A-A89F-47CC-B153-B47DD06837F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -403,6 +405,16 @@ Global
{17EB676B-BB91-48B5-AA59-C67695C647C2}.Release|Any CPU.Build.0 = Release|Any CPU
{17EB676B-BB91-48B5-AA59-C67695C647C2}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{17EB676B-BB91-48B5-AA59-C67695C647C2}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.DebugCodeAnalysis|Any CPU.ActiveCfg = DebugCodeAnalysis|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.DebugCodeAnalysis|Any CPU.Build.0 = DebugCodeAnalysis|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.DebugWithoutVsix|Any CPU.ActiveCfg = Debug|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.DebugWithoutVsix|Any CPU.Build.0 = Debug|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.Release|Any CPU.Build.0 = Release|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions src/GitHub.Api/GitHub.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
<Project>{6afe2e2d-6db0-4430-a2ea-f5f5388d2f78}</Project>
<Name>GitHub.Extensions</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.Logging\GitHub.Logging.csproj">
<Project>{8d73575a-a89f-47cc-b153-b47dd06837f0}</Project>
<Name>GitHub.Logging</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
13 changes: 7 additions & 6 deletions src/GitHub.App/Api/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Security.Cryptography;
using System.Text;
using GitHub.Primitives;
using NLog;
using Octokit;
using Octokit.Reactive;
using ReactiveUI;
Expand All @@ -18,14 +17,16 @@
using System.Collections.Generic;
using GitHub.Models;
using GitHub.Extensions;
using GitHub.Logging;
using Serilog;

namespace GitHub.Api
{
public partial class ApiClient : IApiClient
{
const string ScopesHeader = "X-OAuth-Scopes";
const string ProductName = Info.ApplicationInfo.ApplicationDescription;
static readonly Logger log = LogManager.GetCurrentClassLogger();
static readonly ILogger log = LogManager.ForContext<ApiClient>();

readonly IObservableGitHubClient gitHubClient;
// There are two sets of authorization scopes, old and new:
Expand Down Expand Up @@ -187,7 +188,7 @@ static string GetSha256Hash(string input)
}
catch (Exception e)
{
log.Error("IMPOSSIBLE! Generating Sha256 hash caused an exception.", e);
log.Error(e, "IMPOSSIBLE! Generating Sha256 hash caused an exception");
return null;
}
}
Expand All @@ -205,14 +206,14 @@ static string GetMachineNameSafe()
}
catch (Exception e)
{
log.Info("Failed to retrieve host name using `DNS.GetHostName`.", e);
log.Information(e, "Failed to retrieve host name using `DNS.GetHostName`");
try
{
return Environment.MachineName;
}
catch (Exception ex)
{
log.Info("Failed to retrieve host name using `Environment.MachineName`.", ex);
log.Warning(ex, "Failed to retrieve host name using `Environment.MachineName`");
return "(unknown)";
}
}
Expand All @@ -233,7 +234,7 @@ static string GetMachineIdentifier()
}
catch (Exception e)
{
log.Info("Could not retrieve MAC address. Fallback to using machine name.", e);
log.Warning(e, "Could not retrieve MAC address. Fallback to using machine name");
return GetMachineNameSafe();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/GitHub.App/Caches/ImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
using GitHub.Extensions;
using GitHub.Extensions.Reactive;
using GitHub.Factories;
using GitHub.Logging;
using GitHub.Services;
using Rothko;
using Serilog;

namespace GitHub.Caches
{
[Export(typeof(IImageCache))]
[PartCreationPolicy(CreationPolicy.Shared)]
public sealed class ImageCache : IImageCache
{
static readonly NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
static readonly ILogger log = LogManager.ForContext<ImageCache>();

public const string ImageCacheFileName = "images.cache.db";
readonly IObservable<IBlobCache> cacheFactory;
Expand Down Expand Up @@ -159,7 +161,7 @@ static IObservable<Unit> VacuumIfNecessary(IBlobCache blobCache, bool force = fa
.SelectMany(Observable.Defer(() => blobCache.Insert(key, new byte[] { 1 })))
.Catch<Unit, Exception>(ex =>
{
log.Error("Could not vacuum image cache", ex);
log.Error(ex, "Could not vacuum image cache");
return Observable.Return(Unit.Default);
})
.AsCompletion();
Expand Down
9 changes: 5 additions & 4 deletions src/GitHub.App/Caches/SharedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System.Reactive;
using System.Reactive.Linq;
using Akavache;
using NLog;
using GitHub.Logging;
using Serilog;

namespace GitHub.Caches
{
Expand All @@ -16,7 +17,7 @@ namespace GitHub.Caches
public class SharedCache : ISharedCache
{
const string enterpriseHostApiBaseUriCacheKey = "enterprise-host-api-base-uri";
static readonly Logger log = LogManager.GetCurrentClassLogger();
static readonly ILogger log = LogManager.ForContext<SharedCache>();

static SharedCache()
{
Expand All @@ -26,7 +27,7 @@ static SharedCache()
}
catch (Exception e)
{
log.Error("Error while running the static inializer for SharedCache", e);
log.Error(e, "Error while running the static inializer for SharedCache");
}
}

Expand Down Expand Up @@ -87,7 +88,7 @@ static IBlobCache GetBlobCacheWithFallback(Func<IBlobCache> blobCacheFunc, strin
}
catch (Exception e)
{
log.Error(string.Format(CultureInfo.InvariantCulture, "Failed to set the {0} cache.", cacheName), e);
log.Error(e, "Failed to set the {CacheName} cache", cacheName);
return new InMemoryBlobCache();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/GitHub.App/Controllers/UIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Windows;
using GitHub.Logging;

namespace GitHub.Controllers
{
Expand Down Expand Up @@ -167,12 +168,12 @@ public UIController(IGitHubServiceProvider gitHubServiceProvider,
var waitDispatcher = RxApp.MainThreadScheduler as WaitForDispatcherScheduler;
if (waitDispatcher != null)
{
Debug.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
Log.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
"DispatcherScheduler is set correctly");
}
else
{
Debug.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
Log.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
"The MainThreadScheduler is using the wrong dispatcher");
}
}
Expand Down Expand Up @@ -218,7 +219,7 @@ public void Start()
if (selectedFlow != UIControllerFlow.Authentication)
gitHubServiceProvider.AddService(this, connection);
else // sanity check: it makes zero sense to pass a connection in when calling the auth flow
Debug.Assert(false, "Calling the auth flow with a connection makes no sense!");
Log.Assert(false, "Calling the auth flow with a connection makes no sense!");

hosts.EnsureInitialized().ToObservable()
.ObserveOn(RxApp.MainThreadScheduler)
Expand Down
3 changes: 1 addition & 2 deletions src/GitHub.App/Factories/ApiClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public class ApiClientFactory : IApiClientFactory
readonly ProductHeaderValue productHeader;

[ImportingConstructor]
public ApiClientFactory(IKeychain keychain, IProgram program, ILoggingConfiguration config)
public ApiClientFactory(IKeychain keychain, IProgram program)
{
Keychain = keychain;
productHeader = program.ProductHeader;
config.Configure();
}

public Task<IGitHubClient> CreateGitHubClient(HostAddress hostAddress)
Expand Down
7 changes: 4 additions & 3 deletions src/GitHub.App/Factories/SqlitePersistentBlobCacheFactory.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using Akavache;
using Akavache.Sqlite3;
using NLog;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Reactive.Linq;
using System.Threading.Tasks;
using GitHub.Extensions;
using GitHub.Logging;
using Serilog;

namespace GitHub.Factories
{
[Export(typeof(IBlobCacheFactory))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class SqlitePersistentBlobCacheFactory : IBlobCacheFactory
{
static readonly Logger log = LogManager.GetCurrentClassLogger();
static readonly ILogger log = LogManager.ForContext<SqlitePersistentBlobCacheFactory>();
Dictionary<string, IBlobCache> cache = new Dictionary<string, IBlobCache>();

public IBlobCache CreateBlobCache(string path)
Expand All @@ -31,7 +32,7 @@ public IBlobCache CreateBlobCache(string path)
}
catch(Exception ex)
{
log.Error("Error while creating SQLitePersistentBlobCache for {0}. {1}", path, ex);
log.Error(ex, "Error while creating SQLitePersistentBlobCache for {Path}", path);
return new InMemoryBlobCache();
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/GitHub.App/GitHub.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NLog">
<HintPath>..\..\packages\NLog.3.1.0.0\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\..\packages\Serilog.2.5.0\lib\net46\Serilog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="rothko, Version=0.0.2.0, Culture=neutral, PublicKeyToken=9f664c41f503810a, processorArchitecture=MSIL">
<HintPath>..\..\packages\Rothko.0.0.2-ghfvs\lib\net45\rothko.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -140,7 +141,6 @@
<Compile Include="Extensions\EnvironmentExtensions.cs" />
<Compile Include="Factories\UIFactory.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Infrastructure\LoggingConfiguration.cs" />
<Compile Include="Models\PullRequestFileModel.cs" />
<Compile Include="Models\PullRequestModel.cs" />
<Compile Include="Resources.Designer.cs">
Expand Down Expand Up @@ -190,7 +190,6 @@
<Compile Include="SampleData\SampleViewModels.cs" />
<Compile Include="Api\ApiClient.cs" />
<Compile Include="Factories\ApiClientFactory.cs" />
<None Include="Services\Browser.cs" />
<Compile Include="Services\EnterpriseProbe.cs" />
<Compile Include="Services\ErrorMap.cs" />
<Compile Include="Services\ErrorMessage.cs" />
Expand Down Expand Up @@ -294,6 +293,10 @@
<Project>{6afe2e2d-6db0-4430-a2ea-f5f5388d2f78}</Project>
<Name>GitHub.Extensions</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.Logging\GitHub.Logging.csproj">
<Project>{8d73575a-a89f-47cc-b153-b47dd06837f0}</Project>
<Name>GitHub.Logging</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.UI.Reactive\GitHub.UI.Reactive.csproj">
<Project>{158b05e8-fdbc-4d71-b871-c96e28d5adf5}</Project>
<Name>GitHub.UI.Reactive</Name>
Expand All @@ -305,6 +308,9 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\SerilogAnalyzer.0.12.0.0\analyzers\dotnet\cs\SerilogAnalyzer.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
65 changes: 0 additions & 65 deletions src/GitHub.App/Infrastructure/LoggingConfiguration.cs

This file was deleted.

4 changes: 4 additions & 0 deletions src/GitHub.App/Models/RepositoryHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
using System.Diagnostics;
using GitHub.Api;
using GitHub.Extensions;
using GitHub.Logging;
using GitHub.Primitives;
using GitHub.Services;
using ReactiveUI;
using Serilog;
using static System.FormattableString;

namespace GitHub.Models
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RepositoryHost : ReactiveObject, IRepositoryHost
{
static readonly ILogger log = LogManager.ForContext<RepositoryHosts>();

readonly IConnection connection;

public RepositoryHost(
Expand Down
Loading
0