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

Commit f38b93e

Browse files
committed
Task-ize ConnectionManagerExtensions.
`ConnectionManagerExtensions` methods were returning `IObservables` but only returning a single value. Convert them to return `Task`s so they can be used in Team Explorer etc.
1 parent 2353ab1 commit f38b93e

File tree

2 files changed

+48
-60
lines changed

2 files changed

+48
-60
lines changed
Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,13 @@
11
using System;
2-
using System.Linq;
3-
using System.Reactive.Linq;
4-
using System.Reactive.Threading.Tasks;
52
using System.Threading.Tasks;
63
using GitHub.Factories;
74
using GitHub.Models;
8-
using GitHub.Primitives;
95
using GitHub.Services;
106

117
namespace GitHub.Extensions
128
{
139
public static class ConnectionManagerExtensions
1410
{
15-
public static IObservable<bool> IsLoggedIn(this IConnectionManager cm)
16-
{
17-
Guard.ArgumentNotNull(cm, nameof(cm));
18-
19-
return Observable.FromAsync(async () =>
20-
{
21-
var connections = await cm.GetLoadedConnections();
22-
return connections.Any(x => x.ConnectionError == null);
23-
});
24-
}
25-
26-
public static IObservable<bool> IsLoggedIn(this IConnectionManager cm, HostAddress address)
27-
{
28-
Guard.ArgumentNotNull(cm, nameof(cm));
29-
Guard.ArgumentNotNull(address, nameof(address));
30-
31-
return Observable.FromAsync(async () =>
32-
{
33-
var connections = await cm.GetLoadedConnections();
34-
return connections.Any(x => x.HostAddress == address && x.ConnectionError == null);
35-
});
36-
}
37-
38-
public static IObservable<bool> IsLoggedIn(this IConnection connection)
39-
{
40-
Guard.ArgumentNotNull(connection, nameof(connection));
41-
42-
return Observable.Return(connection?.IsLoggedIn ?? false);
43-
}
44-
45-
public static IObservable<IConnection> GetConnection(this IConnectionManager cm, HostAddress address)
46-
{
47-
Guard.ArgumentNotNull(cm, nameof(cm));
48-
Guard.ArgumentNotNull(address, nameof(address));
49-
50-
return cm.GetLoadedConnections()
51-
.ToObservable()
52-
.Select(x => x.FirstOrDefault(y => y.HostAddress == address));
53-
}
54-
55-
public static IObservable<IConnection> GetLoggedInConnections(this IConnectionManager cm)
56-
{
57-
Guard.ArgumentNotNull(cm, nameof(cm));
58-
59-
return cm.GetLoadedConnections()
60-
.ToObservable()
61-
.Select(x => x.FirstOrDefault(y => y.IsLoggedIn));
62-
}
63-
6411
public static async Task<IModelService> GetModelService(
6512
this IConnectionManager cm,
6613
ILocalRepositoryModel repository,
@@ -69,12 +16,5 @@ public static async Task<IModelService> GetModelService(
6916
var connection = await cm.LookupConnection(repository);
7017
return connection != null ? await factory.CreateAsync(connection) : null;
7118
}
72-
73-
public static IObservable<IConnection> LookupConnection(this IConnectionManager cm, ILocalRepositoryModel repository)
74-
{
75-
return Observable.Return(repository?.CloneUrl != null
76-
? cm.Connections.FirstOrDefault(c => c.HostAddress.Equals(HostAddress.Create(repository.CloneUrl)))
77-
: null);
78-
}
7919
}
8020
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using GitHub.Models;
5+
using GitHub.Primitives;
6+
using GitHub.Services;
7+
8+
namespace GitHub.Extensions
9+
{
10+
public static class ConnectionManagerExtensions
11+
{
12+
public static async Task<bool> IsLoggedIn(this IConnectionManager cm)
13+
{
14+
Guard.ArgumentNotNull(cm, nameof(cm));
15+
16+
var connections = await cm.GetLoadedConnections();
17+
return connections.Any(x => x.ConnectionError == null);
18+
}
19+
20+
public static async Task<bool> IsLoggedIn(this IConnectionManager cm, HostAddress address)
21+
{
22+
Guard.ArgumentNotNull(cm, nameof(cm));
23+
Guard.ArgumentNotNull(address, nameof(address));
24+
25+
var connections = await cm.GetLoadedConnections();
26+
return connections.Any(x => x.HostAddress == address && x.ConnectionError == null);
27+
}
28+
29+
public static async Task<IConnection> GetLoggedInConnections(this IConnectionManager cm)
30+
{
31+
Guard.ArgumentNotNull(cm, nameof(cm));
32+
33+
var connections = await cm.GetLoadedConnections();
34+
return connections.FirstOrDefault(x => x.IsLoggedIn);
35+
}
36+
37+
public static Task<IConnection> LookupConnection(this IConnectionManager cm, ILocalRepositoryModel repository)
38+
{
39+
if (repository?.CloneUrl != null)
40+
{
41+
var hostAddress = HostAddress.Create(repository.CloneUrl);
42+
return cm.GetConnection(hostAddress);
43+
}
44+
45+
return null;
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)