Пример #1
0
        public static bool FindAnyTeam(AzureDevOpsClientContext context, Guid?projectId, out WebApiTeamRef team)
        {
            if (!projectId.HasValue)
            {
                if (FindDefaultProject(context, out TeamProjectReference project))
                {
                    projectId = project.Id;
                }
            }

            // Check if we already have a team that has been cached for this project
            if (!context.TryGetValue <WebApiTeamRef>("$" + projectId + "Team", out team))
            {
                TeamHttpClient teamClient = context.Connection.GetClient <TeamHttpClient>();
                team = teamClient.GetTeamsAsync(projectId.ToString(), top: 1).Result.FirstOrDefault();
                if (team != null)
                {
                    context.SetValue <WebApiTeamRef>("$" + projectId + "Team", team);
                }
                else
                {
                    // create a team?
                    throw new Exception("No team available for running this sample.");
                }
            }

            return(team != null);
        }
Пример #2
0
        public static bool FindRepository(AzureDevOpsClientContext context, Guid projectId, string repositoryName, out GitRepository repo)
        {
            // Check if we already have a repo loaded
            VssConnection connection = context.Connection;
            GitHttpClient gitClient  = connection.GetClient <GitHttpClient>();

            // Check if an ID was already set (this could have been provided by the caller)
            if (!context.TryGetValue("repository" + repositoryName, out Guid repoId))
            {
                repo = gitClient.GetRepositoriesAsync(projectId).Result.FirstOrDefault(c => c.Name == repositoryName);
            }
            else
            {
                repo = gitClient.GetRepositoryAsync(repoId.ToString()).Result;
            }

            if (repo != null)
            {
                context.SetValue("repository" + repositoryName, repo);
            }
            else
            {
                // create a project here?
                throw new Exception("No repos available for running the sample.");
            }

            return(repo != null);
        }
Пример #3
0
        public static bool FindDefaultProject(AzureDevOpsClientContext context, out TeamProjectReference project)
        {
            // Check if we already have a default project loaded
            if (!context.TryGetValue("$defautProject", out project))
            {
                var connection    = context.Connection;
                var projectClient = connection.GetClient <ProjectHttpClient>();

                // Check if an ID was already set (this could have been provided by the caller)

                if (!context.TryGetValue("projectId", out Guid projectId))
                {
                    context.TryGetValue("projectName", out string projectName);
                    var projects = projectClient.GetProjects(null, top: 10).Result;
                    project = projects.OrderBy(c => c.Name == projectName ? 0 : 1).FirstOrDefault();
                }
                else
                {
                    // Get the details for this project
                    project = projectClient.GetProject(projectId.ToString()).Result;
                }
            }

            if (project != null)
            {
                context.SetValue("$defautProject", project);
            }
            else
            {
                // create a project here?
                throw new Exception("No projects available for running the sample.");
            }

            return(project != null);
        }