/// <summary> /// Connects to the TFS server specified by <see cref="IServerManagement.CurrentUri"/>. /// </summary> public async Task ConnectAsync() { await HandleServerError(async() => { IsConnecting = true; try { var serverUrl = Servers.CurrentUri; bool serverChanged = !UriEqualityComparer.Instance.Equals(serverUrl, _explorer.Server?.Uri); if (_explorer.Server != null) { _explorer.Server.ConnectionStatusChanged -= Server_ConnectionStatusChanged; } await _explorer.ConnectAsync(serverUrl); _explorer.Server.ConnectionStatusChanged += Server_ConnectionStatusChanged; var currentProjectName = ProjectName; ProjectNames.Clear(); ProjectNames.AddRange((await _explorer.GetTeamProjectsAsync()).Select(n => n.Name)); // Restore project name on reconnect. if (ProjectNames.Contains(currentProjectName) && !serverChanged) { ProjectName = currentProjectName; } if (serverChanged) { ProjectName = null; } IsConnected = true; Servers.Add(serverUrl); OnConnectionSucceeded(serverUrl); await Task.CompletedTask; } finally { IsConnecting = false; } }); }