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

Commit 10317fe

Browse files
committed
Display login failues in TE connect pane.
When a login error occurs, display a message in our Team Explorer Connect pane with a Rety and Sign Out button.
1 parent 0e69faa commit 10317fe

File tree

13 files changed

+322
-70
lines changed

13 files changed

+322
-70
lines changed

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.ComponentModel;
45
using System.Diagnostics.CodeAnalysis;
56
using System.Reactive;
67
using System.Threading.Tasks;
@@ -201,8 +202,15 @@ class Conn : IConnection
201202

202203
public Octokit.User User => null;
203204
public bool IsLoggedIn => true;
205+
public bool IsLoggingIn => false;
204206

205207
public Exception ConnectionError => null;
208+
209+
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
210+
{
211+
add { }
212+
remove { }
213+
}
206214
}
207215

208216
public RepositoryPublishViewModelDesigner()
@@ -421,12 +429,21 @@ public void Login()
421429
{
422430
}
423431

432+
public void Retry()
433+
{
434+
}
435+
424436
public bool OpenRepository()
425437
{
426438
return true;
427439
}
428440

441+
public string ErrorMessage { get; set; }
429442
public IConnection SectionConnection { get; }
443+
public bool IsLoggingIn { get; set; }
444+
public bool ShowLogin { get; set; }
445+
public bool ShowLogout { get; set; }
446+
public bool ShowRetry { get; set; }
430447
public ICommand Clone { get; }
431448
}
432449

src/GitHub.Exports/Models/IConnection.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.ComponentModel;
3+
using System.Threading.Tasks;
24
using GitHub.Primitives;
35
using Octokit;
46

@@ -7,7 +9,7 @@ namespace GitHub.Models
79
/// <summary>
810
/// Represents a configured connection to a GitHub account.
911
/// </summary>
10-
public interface IConnection
12+
public interface IConnection : INotifyPropertyChanged
1113
{
1214
/// <summary>
1315
/// Gets the host address of the GitHub instance.
@@ -32,6 +34,11 @@ public interface IConnection
3234
/// </summary>
3335
bool IsLoggedIn { get; }
3436

37+
/// <summary>
38+
/// Gets a value indicating whether a login is currently being attempted on the connection.
39+
/// </summary>
40+
bool IsLoggingIn { get; }
41+
3542
/// <summary>
3643
/// Gets the exception that occurred when trying to log in, if <see cref="IsLoggedIn"/> is
3744
/// false.
Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.ComponentModel;
3+
using System.Runtime.CompilerServices;
24
using GitHub.Models;
35
using GitHub.Primitives;
46

@@ -9,31 +11,102 @@ namespace GitHub.Services
911
/// </summary>
1012
public class Connection : IConnection
1113
{
14+
string username;
15+
Octokit.User user;
16+
bool isLoggedIn;
17+
bool isLoggingIn;
18+
Exception connectionError;
19+
20+
public Connection(HostAddress hostAddress)
21+
{
22+
HostAddress = hostAddress;
23+
isLoggedIn = false;
24+
isLoggingIn = true;
25+
}
26+
1227
public Connection(
1328
HostAddress hostAddress,
14-
string userName,
15-
Octokit.User user,
16-
Exception connectionError)
29+
string username,
30+
Octokit.User user)
1731
{
1832
HostAddress = hostAddress;
19-
Username = userName;
20-
User = user;
21-
ConnectionError = connectionError;
33+
this.username = username;
34+
this.user = user;
35+
isLoggedIn = true;
2236
}
2337

2438
/// <inheritdoc/>
2539
public HostAddress HostAddress { get; }
2640

2741
/// <inheritdoc/>
28-
public string Username { get; }
42+
public string Username
43+
{
44+
get => username;
45+
private set => RaiseAndSetIfChanged(ref username, value);
46+
}
2947

3048
/// <inheritdoc/>
31-
public Octokit.User User { get; }
49+
public Octokit.User User
50+
{
51+
get => user;
52+
private set => RaiseAndSetIfChanged(ref user, value);
53+
}
54+
55+
/// <inheritdoc/>
56+
public bool IsLoggedIn
57+
{
58+
get => isLoggedIn;
59+
private set => RaiseAndSetIfChanged(ref isLoggedIn, value);
60+
}
3261

3362
/// <inheritdoc/>
34-
public bool IsLoggedIn => ConnectionError == null;
63+
public bool IsLoggingIn
64+
{
65+
get => isLoggingIn;
66+
private set => RaiseAndSetIfChanged(ref isLoggingIn, value);
67+
}
3568

3669
/// <inheritdoc/>
37-
public Exception ConnectionError { get; }
70+
public Exception ConnectionError
71+
{
72+
get => connectionError;
73+
private set => RaiseAndSetIfChanged(ref connectionError, value);
74+
}
75+
76+
/// <inheritdoc/>
77+
public event PropertyChangedEventHandler PropertyChanged;
78+
79+
public void SetLoggingIn()
80+
{
81+
ConnectionError = null;
82+
IsLoggedIn = false;
83+
IsLoggingIn = true;
84+
User = null;
85+
Username = null;
86+
}
87+
88+
public void SetError(Exception e)
89+
{
90+
ConnectionError = e;
91+
IsLoggingIn = false;
92+
IsLoggedIn = false;
93+
}
94+
95+
public void SetSuccess(Octokit.User user)
96+
{
97+
User = user;
98+
Username = user.Login;
99+
IsLoggingIn = false;
100+
IsLoggedIn = true;
101+
}
102+
103+
void RaiseAndSetIfChanged<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
104+
{
105+
if (!Equals(field, value))
106+
{
107+
field = value;
108+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
109+
}
110+
}
38111
}
39112
}

src/GitHub.Exports/Services/IConnectionManager.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,12 @@ public interface IConnectionManager
9292
/// <param name="address"></param>
9393
/// <returns>A task tracking the operation.</returns>
9494
Task LogOut(HostAddress address);
95+
96+
/// <summary>
97+
/// Retries logging in to a failed connection.
98+
/// </summary>
99+
/// <param name="connection">The connection.</param>
100+
/// <returns>The resulting connection.</returns>
101+
Task Retry(IConnection connection);
95102
}
96103
}

src/GitHub.Exports/ViewModels/IGitHubConnectSection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ public interface IGitHubConnectSection
88
void DoCreate();
99
void SignOut();
1010
void Login();
11+
void Retry();
1112
bool OpenRepository();
13+
string ErrorMessage { get; }
1214
IConnection SectionConnection { get; }
15+
bool IsLoggingIn { get; }
16+
bool ShowLogin { get; }
17+
bool ShowLogout { get; }
18+
bool ShowRetry { get; }
1319
ICommand Clone { get; }
1420
}
1521
}

0 commit comments

Comments
 (0)