8000 Merge pull request #1283 from github/refactor/connections/remove-repo… · github/VisualStudio@def6070 · 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.

Commit def6070

Browse files
authored
Merge pull request #1283 from github/refactor/connections/remove-repositoryhosts
< 8000 span class="ws-pre-wrap extended-commit-description-container f6 wb-break-word text-mono mt-2 prc-Text-Text-0ima0">Remove RepositoryHost(s)
2 parents e45d0c6 + cd546bb commit def6070

File tree

80 files changed

+1903
-1822
lines changed

Some content is hidden

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

80 files changed

+1903
-1822
lines changed

src/GitHub.App/Controllers/UIController.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Reactive.Disposables;
1515
using System.Reactive.Linq;
1616
using System.Reactive.Subjects;
17+
using System.Reactive.Threading.Tasks;
1718
using System.Windows;
1819
using GitHub.Logging;
1920

@@ -98,7 +99,6 @@ internal enum Trigger
9899

99100
readonly IUIFactory factory;
100101
readonly IGitHubServiceProvider gitHubServiceProvider;
101-
readonly IRepositoryHosts hosts;
102102
readonly IConnectionManager connectionManager;
103103

104104
readonly CompositeDisposable disposables = new CompositeDisposable();
@@ -140,25 +140,22 @@ internal enum Trigger
140140

141141
public UIController(IGitHubServiceProvider serviceProvider)
142142
: this(serviceProvider,
143-
serviceProvider.TryGetService<IRepositoryHosts>(),
144143
serviceProvider.TryGetService<IUIFactory>(),
145144
serviceProvider.TryGetService<ICo F987 nnectionManager>())
146145
{
147146
Guard.ArgumentNotNull(serviceProvider, nameof(serviceProvider));
148147
}
149148

150149
public UIController(IGitHubServiceProvider gitHubServiceProvider,
151-
IRepositoryHosts hosts, IUIFactory factory,
150+
IUIFactory factory,
152151
IConnectionManager connectionManager)
153152
{
154153
Guard.ArgumentNotNull(gitHubServiceProvider, nameof(gitHubServiceProvider));
155-
Guard.ArgumentNotNull(hosts, nameof(hosts));
156154
Guard.ArgumentNotNull(factory, nameof(factory));
157155
Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));
158156

159157
this.factory = factory;
160158
this.gitHubServiceProvider = gitHubServiceProvider;
161-
this.hosts = hosts;
162159
this.connectionManager = connectionManager;
163160

164161
#if DEBUG
@@ -220,7 +217,7 @@ public void Start()
220217
else // sanity check: it makes zero sense to pass a connection in when calling the auth flow
221218
Log.Assert(false, "Calling the auth flow with a connection makes no sense!");
222219

223-
connection.Login()
220+
connectionManager.GetLoadedConnections().ToObservable()
224221
.ObserveOn(RxApp.MainThreadScheduler)
225222
.Subscribe(_ => { }, () =>
226223
{
@@ -231,7 +228,7 @@ public void Start()
231228
else
232229
{
233230
connectionManager
234-
.GetLoggedInConnections(hosts)
231+
.GetLoggedInConnections()
235232
.FirstOrDefaultAsync()
236233
.Select(c =>
237234
{
@@ -445,8 +442,7 @@ void ConfigureSingleViewLogic(UIControllerFlow flow, UIViewType type)
445442

446443
UIControllerFlow SelectActiveFlow()
447444
{
448-
var host = connection != null ? hosts.LookupHost(connection.HostAddress) : null;
449-
var loggedIn = host?.IsLoggedIn ?? false;
445+
var loggedIn = connection?.IsLoggedIn ?? false;
450446
return loggedIn ? selectedFlow : UIControllerFlow.Authentication;
451447
}
452448

@@ -711,7 +707,7 @@ public void Dispose()
711707
public bool IsStopped => uiStateMachine.IsInState(UIViewType.None) || stopping;
712708
public UIControllerFlow CurrentFlow => activeFlow;
713709
public UIControllerFlow SelectedFlow => selectedFlow;
714-
bool LoggedIn => connection != null && hosts.LookupHost(connection.HostAddress).IsLoggedIn;
710+
bool LoggedIn => connection?.IsLoggedIn ?? false;
715711
bool? Success { get; set; }
716712
}
717713
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.Composition;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using GitHub.Caches;
7+
using GitHub.Models;
8+
using GitHub.Services;
9+
using Microsoft.VisualStudio.Shell;
10+
11+
namespace GitHub.Factories
12+
{
13+
[Export(typeof(IModelServiceFactory))]
14+
[PartCreationPolicy(CreationPolicy.Shared)]
15+
public sealed class ModelServiceFactory : IModelServiceFactory, IDisposable
16+
{
17+
readonly IApiClientFactory apiClientFactory;
18+
readonly IHostCacheFactory hostCacheFactory;
19+
readonly IAvatarProvider avatarProvider;
20+
readonly Dictionary<IConnection, ModelService> cache = new Dictionary<IConnection, ModelService>();
21+
readonly SemaphoreSlim cacheLock = new SemaphoreSlim(1);
22+
23+
[ImportingConstructor]
24+
public ModelServiceFactory(
25+
IApiClientFactory apiClientFactory,
26+
IHostCacheFactory hostCacheFactory,
27+
IAvatarProvider avatarProvider)
28+
{
29+
this.apiClientFactory = apiClientFactory;
30+
this.hostCacheFactory = hostCacheFactory;
31+
this.avatarProvider = avatarProvider;
32+
}
33+
34+
public async Task<IModelService> CreateAsync(IConnection connection)
35+
{
36+
ModelService result;
37+
38+
await cacheLock.WaitAsync();
39+
40+
try
41+
{
42+
if (!cache.TryGetValue(connection, out result))
43+
{
44+
result = new ModelService(
45+
await apiClientFactory.Create(connection.HostAddress),
46+
await hostCacheFactory.Create(connection.HostAddress),
47+
avatarProvider);
48+
result.InsertUser(AccountCacheItem.Create(connection.User));
49+
cache.Add(connection, result);
50+
}
51+
}
52+
finally
53+
{
54+
cacheLock.Release();
55+
}
56+
57+
return result;
58+
}
59+
60+
public IModelService CreateBlocking(IConnection connection)
61+
{
62+
return ThreadHelper.JoinableTaskFactory.Run(() => CreateAsync(connection));
63+
}
64+
65+
public void Dispose() => cacheLock.Dispose();
66+
}
67+
}

src/GitHub.App/Factories/RepositoryHostFactory.cs

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

src/GitHub.App/GitHub.App.csproj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@
129129
<Reference Include="WindowsBase" />
130130
</ItemGroup>
131131
<ItemGroup>
132+
<Compile Include="Factories\ModelServiceFactory.cs" />
132133
<Compile Include="Models\IssueCommentModel.cs" />
133134
<Compile Include="Models\PullRequestReviewCommentModel.cs" />
134135
<Compile Include="Models\PullRequestDetailArgument.cs" />
136+
<Compile Include="Services\GlobalConnection.cs" />
135137
<Compile Include="ViewModels\ViewModelBase.cs" />
136138
<Compile Include="Caches\CacheIndex.cs" />
137139
<Compile Include="Caches\CacheItem.cs" />
@@ -183,9 +185,6 @@
183185
<Compile Include="Info\GitHubUrls.cs" />
184186
<Compile Include="Infrastructure\ExportWrappers.cs" />
185187
<Compile Include="Models\Account.cs" />
186-
<Compile Include="Models\DisconnectedRepositoryHosts.cs" />
187-
<Compile Include="Models\RepositoryHost.cs" />
188-
<Compile Include="Models\RepositoryHosts.cs" />
189188
<Compile Include="Models\RemoteRepositoryModel.cs" />
190189
<Compile Include="SampleData\SampleViewModels.cs" />
191190
<Compile Include="Api\ApiClient.cs" />
@@ -195,7 +194,6 @@
195194
<Compile Include="Services\ErrorMessage.cs" />
196195
<Compile Include="Services\ErrorMessageTranslator.cs" />
197196
<Compile Include="Services\IEnterpriseProbe.cs" />
198-
<Compile Include="Factories\RepositoryHostFactory.cs" />
199197
<Compile Include="Services\RepositoryCreationService.cs" />
200198
<Compile Include="Services\GistPublishService.cs" />
201199
<Compile Include="Services\RepositoryPublishService.cs" />
@@ -208,7 +206,6 @@
208206
<Compile Include="UserErrors\PrivateRepositoryQuotaExceededUserError.cs" />
209207
<Compile Include="ViewModels\PanePageViewModelBase.cs" />
210208
<Compile Include="ViewModels\DialogViewModelBase.cs" />
211-
<Compile Include="Models\ConnectionRepositoryHostMap.cs" />
212209
<Compile Include="ViewModels\GistCreationViewModel.cs" />
213210
<Compile Include="ViewModels\NotAGitRepositoryViewModel.cs" />
214211
<Compile Include="ViewModels\NotAGitHubRepositoryViewModel.cs" />

src/GitHub.App/Models/ConnectionRepositoryHostMap.cs

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

src/GitHub.App/Models/DisconnectedRepositoryHosts.cs

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

0 commit comments

Comments
 (0)
0