@@ -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