Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public static GitRepository FindRepository(AzureDevOpsClientContext context, Guid projectId, string repositoryName)
        {
            if (!FindRepository(context, projectId, repositoryName, out GitRepository repo))
            {
                throw new Exception("No repositories available. Create a repo in this project and run the sample again.");
            }

            return(repo);
        }
Ejemplo n.º 5
0
        public static WebApiTeamRef FindAnyTeam(AzureDevOpsClientContext context, Guid?projectId)
        {
            if (!FindAnyTeam(context, projectId, out WebApiTeamRef team))
            {
                throw new Exception("No sample teams available. Create a project/team in this collection and run the sample again.");
            }

            return(team);
        }
Ejemplo n.º 6
0
        public static TeamProjectReference FindDefaultProject(AzureDevOpsClientContext context)
        {
            if (!FindDefaultProject(context, out TeamProjectReference project))
            {
                throw new Exception("No sample projects available. Create a project in this collection and run the sample again.");
            }

            return(project);
        }
Ejemplo n.º 7
0
        public static GitRepository FindRepository(AzureDevOpsClientContext context, string repositoryName)
        {
            var project = AzureProjectHelper.FindDefaultProject(context);

            if (!FindRepository(context, project.Id, repositoryName, out GitRepository repo))
            {
                throw new Exception("No repositories available. Create a repo in this project and run the sample again.");
            }

            return(repo);
        }
Ejemplo n.º 8
0
 protected void InitializeAzureContext()
 {
     AzureContext = CreateContext();
     AddProperty("projectName", Context.Options.ProjectName);
     AddProperty("repository" + Context.Options.RepositoryName, Context.Options.RepositoryId);
 }
Ejemplo n.º 9
0
        public static Guid?FindRepositoryId(AzureDevOpsClientContext context, Guid projectId, string repositoryName)
        {
            var repository = FindRepository(context, projectId, repositoryName);

            return(repository?.Id);
        }
Ejemplo n.º 10
0
 public static Guid FindDefaultProjectId(AzureDevOpsClientContext context)
 {
     return(FindDefaultProject(context).Id);
 }
Ejemplo n.º 11
0
 public static string GetCurrentUserDisplayName(AzureDevOpsClientContext context)
 {
     return(context.Connection.AuthorizedIdentity.ProviderDisplayName);
 }
Ejemplo n.º 12
0
 public static Guid GetCurrentUserId(AzureDevOpsClientContext context)
 {
     return(context.Connection.AuthorizedIdentity.Id);
 }