10000 Remove RepositoryHost(s) by grokys · Pull Request #1283 · 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.

Remove RepositoryHost(s) #1283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
16 changes: 6 additions & 10 deletions src/GitHub.App/Controllers/UIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Windows;
using GitHub.Logging;

Expand Down Expand Up @@ -98,7 +99,6 @@ internal enum Trigger

readonly IUIFactory factory;
readonly IGitHubServiceProvider gitHubServiceProvider;
readonly IRepositoryHosts hosts;
readonly IConnectionManager connectionManager;

readonly CompositeDisposable disposables = new CompositeDisposable();
Expand Down Expand Up @@ -140,25 +140,22 @@ internal enum Trigger

public UIController(IGitHubServiceProvider serviceProvider)
: this(serviceProvider,
serviceProvider.TryGetService<IRepositoryHosts>(),
serviceProvider.TryGetService<IUIFactory>(),
serviceProvider.TryGetService<IConnectionManager>())
{
Guard.ArgumentNotNull(serviceProvider, nameof(serviceProvider));
}

public UIController(IGitHubServiceProvider gitHubServiceProvider,
IRepositoryHosts hosts, IUIFactory factory,
IUIFactory factory,
IConnectionManager connectionManager)
{
Guard.ArgumentNotNull(gitHubServiceProvider, nameof(gitHubServiceProvider));
Guard.ArgumentNotNull(hosts, nameof(hosts));
Guard.ArgumentNotNull(factory, nameof(factory));
Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));

this.factory = factory;
this.gitHubServiceProvider = gitHubServiceProvider;
this.hosts = hosts;
this.connectionManager = connectionManager;

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

connection.Login()
connectionManager.GetLoadedConnections().ToObservable()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ => { }, () =>
{
Expand All @@ -231,7 +228,7 @@ public void Start()
else
{
connectionManager
.GetLoggedInConnections(hosts)
.GetLoggedInConnections()
.FirstOrDefaultAsync()
.Select(c =>
{
Expand Down Expand Up @@ -445,8 +442,7 @@ void ConfigureSingleViewLogic(UIControllerFlow flow, UIViewType type)

UIControllerFlow SelectActiveFlow()
{
var host = connection != null ? hosts.LookupHost(connection.HostAddress) : null;
var loggedIn = host?.IsLoggedIn ?? false;
var loggedIn = connection?.IsLoggedIn ?? false;
return loggedIn ? selectedFlow : UIControllerFlow.Authentication;
}

Expand Down Expand Up @@ -711,7 +707,7 @@ public void Dispose()
public bool IsStopped => uiStateMachine.IsInState(UIViewType.None) || stopping;
public UIControllerFlow CurrentFlow => activeFlow;
public UIControllerFlow SelectedFlow => selectedFlow;
bool LoggedIn => connection != null && hosts.LookupHost(connection.HostAddress).IsLoggedIn;
bool LoggedIn => connection?.IsLoggedIn ?? false;
bool? Success { get; set; }
}
}
67 changes: 67 additions & 0 deletions src/GitHub.App/Factories/ModelServiceFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Threading;
using System.Threading.Tasks;
using GitHub.Caches;
using GitHub.Models;
using GitHub.Services;
using Microsoft.VisualStudio.Shell;

namespace GitHub.Factories
{
[Export(typeof(IModelServiceFactory))]
[PartCreationPolicy(CreationPolicy.Shared)]
public sealed class ModelServiceFactory : IModelServiceFactory, IDisposable
{
readonly IApiClientFactory apiClientFactory;
readonly IHostCacheFactory hostCacheFactory;
readonly IAvatarProvider avatarProvider;
readonly Dictionary<IConnection, ModelService> cache = new Dictionary<IConnection, ModelService>();
readonly SemaphoreSlim cacheLock = new SemaphoreSlim(1);

[ImportingConstructor]
public ModelServiceFactory(
IApiClientFactory apiClientFactory,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use ISimpleApiClientFactory here, so we can slowly move away from IApiClientFactory and get rid of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but ModelService still relies on IApiClient rather than ISimpleApiClient and needs the reactive stuff, so if we want to make that change it will have to be later I think.

IHostCacheFactory hostCacheFactory,
IAvatarProvider avatarProvider)
{
this.apiClientFactory = apiClientFactory;
this.hostCacheFactory = hostCacheFactory;
this.avatarProvider = avatarProvider;
}

public async Task<IModelService> CreateAsync(IConnection connection)
{
ModelService result;

await cacheLock.WaitAsync();

try
{
if (!cache.TryGetValue(connection, out result))
{
result = new ModelService(
await apiClientFactory.Create(connection.HostAddress),
await hostCacheFactory.Create(connection.HostAddress),
avatarProvider);
result.InsertUser(AccountCacheItem.Create(connection.User));
cache.Add(connection, result);
}
}
finally
{
cacheLock.Release();
}

return result;
}

public IModelService CreateBlocking(IConnection connection)
{
return ThreadHelper.JoinableTaskFactory.Run(() => CreateAsync(connection));
}

public void Dispose() => cacheLock.Dispose();
}
}
74 changes: 0 additions & 74 deletions src/GitHub.App/Factories/RepositoryHostFactory.cs

This file was deleted.

7 changes: 2 additions & 5 deletions src/GitHub.App/GitHub.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Factories\ModelServiceFactory.cs" />
<Compile Include="Models\IssueCommentModel.cs" />
<Compile Include="Models\PullRequestReviewCommentModel.cs" />
<Compile Include="Models\PullRequestDetailArgument.cs" />
<Compile Include="Services\GlobalConnection.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
<Compile Include="Caches\CacheIndex.cs" />
<Compile Include="Caches\CacheItem.cs" />
Expand Down Expand Up @@ -183,9 +185,6 @@
<Compile Include="Info\GitHubUrls.cs" />
<Compile Include="Infrastructure\ExportWrappers.cs" />
<Compile Include="Models\Account.cs" />
<Compile Include="Models\DisconnectedRepositoryHosts.cs" />
<Compile Include="Models\RepositoryHost.cs" />
<Compile Include="Models\RepositoryHosts.cs" />
<Compile Include="Models\RemoteRepositoryModel.cs" />
<Compile Include="SampleData\SampleViewModels.cs" />
<Compile Include="Api\ApiClient.cs" />
Expand All @@ -195,7 +194,6 @@
<Compile Include="Services\ErrorMessage.cs" />
<Compile Include="Services\ErrorMessageTranslator.cs" />
<Compile Include="Services\IEnterpriseProbe.cs" />
<Compile Include="Factories\RepositoryHostFactory.cs" />
<Compile Include="Services\RepositoryCreationService.cs" />
<Compile Include="Services\GistPublishService.cs" />
<Compile Include="Services\RepositoryPublishService.cs" />
Expand All @@ -208,7 +206,6 @@
<Compile Include="UserErrors\PrivateRepositoryQuotaExceededUserError.cs" />
<Compile Include="ViewModels\PanePageViewModelBase.cs" />
<Compile Include="ViewModels\DialogViewModelBase.cs" />
<Compile Include="Models\ConnectionRepositoryHostMap.cs" />
<Compile Include="ViewModels\GistCreationViewModel.cs" />
<Compile Include="ViewModels\NotAGitRepositoryViewModel.cs" />
<Compile Include="ViewModels\NotAGitHubRepositoryViewModel.cs" />
Expand Down
34 changes: 0 additions & 34 deletions src/GitHub.App/Models/ConnectionRepositoryHostMap.cs

This file was deleted.

57 changes: 0 additions & 57 deletions src/GitHub.App/Models/DisconnectedRepositoryHosts.cs

This file was deleted. 4965

Loading
0