async Task LoadConnectionsFromCache() { foreach (var c in await cache.Load()) { var client = await apiClientFactory.CreateGitHubClient(c.HostAddress); var addConnection = true; try { await loginManager.LoginFromCache(c.HostAddress, client); } catch (Octokit.ApiException e) { addConnection = false; VsOutputLogger.WriteLine("Cached credentials for connection {0} were invalid: {1}", c.HostAddress, e); } catch (Exception) { // Add the connection in this case - could be that there's no internet connection. } if (addConnection) { AddConnection(c.HostAddress, c.UserName); } } Connections.CollectionChanged += RefreshConnections; }
async Task LoadConnections(ObservableCollection <IConnection> result) { try { foreach (var c in await cache.Load()) { var client = CreateClient(c.HostAddress); User user = null; Exception error = null; try { user = await loginManager.LoginFromCache(c.HostAddress, client); } catch (Exception e) { error = e; } var connection = new Connection(c.HostAddress, c.UserName, user, error); result.Add(connection); await usageTracker.IncrementCounter(x => x.NumberOfLogins); } } finally { loaded.SetResult(null); } }
async Task LoadConnections(ObservableCollection <IConnection> result) { try { foreach (var c in await cache.Load()) { var connection = new Connection(c.HostAddress, c.UserName); result.Add(connection); } foreach (Connection connection in result) { var client = CreateClient(connection.HostAddress); LoginResult login = null; try { login = await loginManager.LoginFromCache(connection.HostAddress, client); connection.SetSuccess(login.User, login.Scopes); await usageTracker.IncrementCounter(x => x.NumberOfLogins); } catch (Exception e) { connection.SetError(e); } } } finally { loaded.SetResult(null); } }