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

Commit 32a0bb9

Browse files
committed
Fix all the things!
Add a tracker class to accurately track the state of the local git repository list, so we can update our lists accordingly. Cleanup and fix a bunch of list-refreshing stuff.
1 parent 0263a15 commit 32a0bb9

File tree

8 files changed

+151
-108
lines changed

8 files changed

+151
-108
lines changed

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ public IObservable<IConnection> Login()
211211
public void Logout()
212212
{
213213
}
214+
215+
public void Dispose()
216+
{
217+
}
214218
}
215219

216220
public RepositoryPublishViewModelDesigner()
@@ -572,8 +576,9 @@ public void Login()
572576
{
573577
}
574578

575-
public void OpenRepository()
579+
public bool OpenRepository()
576580
{
581+
return true;
577582
}
578583

579584
public IConnection SectionConnection { get; }

src/GitHub.Exports/Models/IConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace GitHub.Models
88
{
9-
public interface IConnection
9+
public interface IConnection : IDisposable
1010
{
1111
HostAddress HostAddress { get; }
1212
string Username { get; }

src/GitHub.Exports/Models/IConnectionManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public interface IConnectionManager
1919
// for telling IRepositoryHosts that we need to login from cache
2020
[SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly")]
2121
event Func<IConnection, IObservable<IConnection>> DoLogin;
22-
void RefreshRepositories(IVSServices services);
22+
void RefreshRepositories();
2323
}
2424
}

src/GitHub.Exports/Services/Connection.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,25 @@ public void Logout()
3232
{
3333
manager.RequestLogout(this);
3434
}
35+
36+
#region IDisposable Support
37+
private bool disposed = false; // To detect redundant calls
38+
39+
protected virtual void Dispose(bool disposing)
40+
{
41+
if (!disposed)
42+
{
43+
if (disposing)
44+
Repositories.Clear();
45+
disposed = true;
46+
}
47+
}
48+
49+
public void Dispose()
50+
{
51+
Dispose(true);
52+
GC.SuppressFinalize(this);
53+
}
54+
#endregion
3555
}
3656
}

src/GitHub.Exports/ViewModels/IGitHubConnectSection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IGitHubConnectSection
99
void DoClone();
1010
void SignOut();
1111
void Login();
12-
void OpenRepository();
12+
bool OpenRepository();
1313
IConnection SectionConnection { get; }
1414
}
1515
}

src/GitHub.VisualStudio/Services/ConnectionManager.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ConnectionCacheItem
2727
public class ConnectionManager : IConnectionManager
2828
{
2929
readonly string cachePath;
30+
readonly IVSServices vsServices;
3031
const string cacheFile = "ghfvs.connections";
3132

3233
public event Func<IConnection, IObservable<IConnection>> DoLogin;
@@ -39,8 +40,9 @@ public class ConnectionManager : IConnectionManager
3940
Action<string> dirCreate;
4041

4142
[ImportingConstructor]
42-
public ConnectionManager(IProgram program)
43+
public ConnectionManager(IProgram program, IVSServices services)
4344
{
45+
vsServices = services;
4446
fileExists = (path) => System.IO.File.Exists(path);
4547
readAllText = (path, encoding) => System.IO.File.ReadAllText(path, encoding);
4648
writeAllText = (path, content) => System.IO.File.WriteAllText(path, content);
@@ -59,8 +61,9 @@ public ConnectionManager(IProgram program)
5961
Connections.CollectionChanged += RefreshConnections;
6062
}
6163

62-
public ConnectionManager(IProgram program, Rothko.IOperatingSystem os)
64+
public ConnectionManager(IProgram program, Rothko.IOperatingSystem os, IVSServices services)
6365
{
66+
vsServices = services;
6467
fileExists = (path) => os.File.Exists(path);
6568
readAllText = (path, encoding) => os.File.ReadAllText(path, encoding);
6669
writeAllText = (path, content) => os.File.WriteAllText(path, content);
@@ -106,7 +109,7 @@ public bool RemoveConnection(HostAddress address)
106109
var c = Connections.FirstOrDefault(x => x.HostAddress.Equals(address));
107110
if (c == null)
108111
return false;
109-
Connections.Remove(c);
112+
RequestLogout(c);
110113
return true;
111114
}
112115

@@ -123,10 +126,8 @@ public void RequestLogout(IConnection connection)
123126
Connections.Remove(connection);
124127
}
125128

126-
public void RefreshRepositories(IVSServices services)
129+
public void RefreshRepositories()
127130
{
128-
var list = services.GetKnownRepositories();
129-
list.GroupBy(r => Connections.FirstOrDefault(c => c.HostAddress == HostAddress.Create(r.CloneUrl)))
130131
var list = vsServices.GetKnownRepositories();
131132
list.GroupBy(r => Connections.FirstOrDefault(c => c.HostAddress.Equals(HostAddress.Create(r.CloneUrl))))
132133
.Where(g => g.Key != null)
@@ -148,13 +149,12 @@ void RefreshConnections(object sender, System.Collections.Specialized.NotifyColl
148149
{
149150
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
150151
{
151-
// RepositoryHosts hasn't been loaded so it can't handle logging out, we have to do it ourselves
152-
if (DoLogin == null)
152+
foreach (IConnection c in e.OldItems)
153153
{
154-
foreach (IConnection c in e.OldItems)
155-
{
154+
// RepositoryHosts hasn't been loaded so it can't handle logging out, we have to do it ourselves
155+
if (DoLogin == null)
156156
Api.SimpleCredentialStore.RemoveCredentials(c.HostAddress.CredentialCacheKeyHost);
157-
}
157+
c.Dispose();
158158
}
159159
}
160160
SaveConnectionsToCache();

0 commit comments

Comments
 (0)