public async Task <IEnumerable <TfsProject> > FetchAvailableProjects(TfsConfigurationRawData rawData) { try { if (string.IsNullOrEmpty(rawData.Url) || string.IsNullOrEmpty(rawData.CollectionName)) { return(Enumerable.Empty <TfsProject>()); } if (rawData.AuthenticationType == AuthenticationType.Token && string.IsNullOrEmpty(rawData.Token?.PlainText())) { return(Enumerable.Empty <TfsProject>()); } if (rawData.AuthenticationType == AuthenticationType.Account && (string.IsNullOrEmpty(rawData.Username) || string.IsNullOrEmpty(rawData.Password?.PlainText()))) { return(Enumerable.Empty <TfsProject>()); } var pool = new TfsConnectionPool(); var vssConnection = pool.CreateConnection(rawData); if (vssConnection == null) { return(Enumerable.Empty <TfsProject>()); } var projectClient = vssConnection.GetClient <ProjectHttpClient>(); var projects = await projectClient.GetProjects(ProjectState.WellFormed); return(projects.Select(p => new TfsProject(p))); } catch (Exception e) { Log.Info().Message("Failed to fetch projects").Exception(e).Write(); return(Enumerable.Empty <TfsProject>()); } }
public async Task <IEnumerable <TfsRepository> > FetchAvailableRepositories(TfsConfigurationRawData rawData) { IsLoading = true; try { if (string.IsNullOrEmpty(rawData.Url) || string.IsNullOrEmpty(rawData.CollectionName)) { return(Enumerable.Empty <TfsRepository>()); } if (rawData.AuthenticationType == AuthenticationType.Token && string.IsNullOrEmpty(rawData.Token?.PlainText())) { return(Enumerable.Empty <TfsRepository>()); } if (rawData.AuthenticationType == AuthenticationType.Account && (string.IsNullOrEmpty(rawData.Username) || string.IsNullOrEmpty(rawData.Password?.PlainText()))) { return(Enumerable.Empty <TfsRepository>()); } if (rawData.Project == null) { return(Enumerable.Empty <TfsRepository>()); } var pool = new TfsConnectionPool(); var vssConnection = pool.CreateConnection(rawData); if (vssConnection == null) { return(Enumerable.Empty <TfsRepository>()); } var gitClient = vssConnection.GetClient <GitHttpClient>(); var repositories = await gitClient.GetRepositoriesAsync(rawData.Project.Id); return(repositories.Select(r => new TfsRepository(r)).ToList()); } catch (Exception e) { Log.Info().Message("Failed to fetch repositories").Exception(e).Write(); return(Enumerable.Empty <TfsRepository>()); } finally { IsLoading = false; } }