public WebApiTeam RenameTeam() { // Use the previously created team (from the sample above) WebApiTeamRef team; TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); if (!this.Context.TryGetValue <WebApiTeamRef>("$newTeam", out team) || !this.Context.TryGetValue <TeamProjectReference>("$projectOfNewTeam", out project)) { throw new Exception("Run the create team sample above first."); } //Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient <TeamHttpClient>(); WebApiTeam teamUpdateParameters = new WebApiTeam() { Name = team.Name + " (renamed)" }; WebApiTeam updatedTeam = teamClient.UpdateTeamAsync(teamUpdateParameters, project.Id.ToString(), team.Id.ToString()).Result; Console.WriteLine("Team renamed from '{0}' to '{1}'", team.Name, updatedTeam.Name); return(updatedTeam); }
/// <summary> /// Get detailed team information /// </summary> /// <param name="TeamProjectName"></param> /// <param name="TeamName"></param> static void GetTeamInfo(string TeamProjectName, string TeamName) { WebApiTeam team = TeamClient.GetTeamAsync(TeamProjectName, TeamName).Result; Console.WriteLine("Team name: " + team.Name); Console.WriteLine("Team description:\n{0}\n", team.Description); List <TeamMember> teamMembers = TeamClient.GetTeamMembersWithExtendedPropertiesAsync(TeamProjectName, TeamName).Result; string teamAdminName = (from tm in teamMembers where tm.IsTeamAdmin == true select tm.Identity.DisplayName).FirstOrDefault(); if (teamAdminName != null) { Console.WriteLine("Team Administrator:" + teamAdminName); } Console.WriteLine("Team members:"); foreach (TeamMember teamMember in teamMembers) { if (!teamMember.IsTeamAdmin) { Console.WriteLine(teamMember.Identity.DisplayName); } } }
public WebApiTeam CreateTeam() { // Find a project to create the team in TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); string teamName = "Sample team " + Guid.NewGuid(); string teamDescription = "Short description of my new team"; // Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient <TeamHttpClient>(); // Construct team parameters object WebApiTeam newTeamCreateParameters = new WebApiTeam() { Name = teamName, Description = teamDescription }; WebApiTeam newTeam = teamClient.CreateTeamAsync(newTeamCreateParameters, project.Id.ToString()).Result; Console.WriteLine("Team created: '{0}' (ID: {1})", newTeam.Name, newTeam.Id); // Save the team for use later in the rename/delete samples this.Context.SetValue <WebApiTeamRef>("$newTeam", newTeam); this.Context.SetValue <TeamProjectReference>("$projectOfNewTeam", project); return(newTeam); }
private Models.Team CreateTeamObject(WebApiTeam innerTeam, bool includeMembers = false, bool includeSettings = false) { var team = new Models.Team(innerTeam); if (includeMembers) { var client = GetClient <TeamHttpClient>(); Logger.Log($"Retrieving team membership information for team '{team.Name}'"); var members = client.GetTeamMembersWithExtendedPropertiesAsync(team.ProjectName, team.Name) .GetResult($"Error retrieving membership information for team {team.Name}"); team.TeamMembers = members; } if (includeSettings) { Logger.Log($"Retrieving team settings for team '{team.Name}'"); var workClient = GetClient <WorkHttpClient>(); var ctx = new TeamContext(team.ProjectName, team.Name); team.Settings = workClient.GetTeamSettingsAsync(ctx) .GetResult($"Error retrieving settings for team {team.Name}"); } return(team); }
public static string ToBotString(this WebApiTeam obj) { if (obj == null) { return("Информация о команде не найдена."); } return(string.Format("Ваша команда <b>{0}</b>.<br />{1}", obj.Name, obj.Description)); }
public WebApiTeam UpdateTeam(string project, string team, WebApiTeam teamData) { VssConnection connection = new VssConnection(_uri, _credentials); TeamHttpClient teamHttpClient = connection.GetClient <TeamHttpClient>(); WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; return(result); }
/// <summary> /// Creates a team in the given project /// </summary> /// <param name="projectId">ID of project to associate with team</param> /// <param name="team">Team to create</param> /// <returns>Team with properties set from creation</returns> public async Task <WebApiTeam> CreateTeamForProjectAsync(string projectId, WebApiTeam team) { var client = await GetClientAsync <TeamHttpClient>(); logger.LogInformation("CreateTeamForProjectAsync TeamName = {0} ProjectId = {1}", team.Name, projectId); var result = await client.CreateTeamAsync(team, projectId); return(result); }
public WebApiTeam GetTeam(string project, string team) { // create team object using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) { WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; return(result); } }
public WebApiTeam UpdateTeam(string project, string team, WebApiTeam teamData) { // create team object using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) { WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; return(result); } }
public WebApiTeam GetTeam() { string teamName = "My new team"; VssConnection connection = new VssConnection(_uri, _credentials); TeamHttpClient teamHttpClient = connection.GetClient <TeamHttpClient>(); WebApiTeam result = teamHttpClient.GetTeamAsync(_configuration.Project, teamName).Result; return(result); }
/// <summary> /// Create a new team /// </summary> /// <param name="TeamProjectName"></param> /// <param name="TeamName"></param> static void CreateNewTeam(string TeamProjectName, string TeamName) { WebApiTeam newTeam = new WebApiTeam(); newTeam.Name = TeamName; newTeam.Description = "Created from a command line"; newTeam = TeamClient.CreateTeamAsync(newTeam, TeamProjectName).Result; Console.WriteLine("The new team '{0}' has been created in the team project '{1}'", newTeam.Name, newTeam.ProjectName); }
public void ShowAllTeamSubscriptions() { VssConnection connection = Context.Connection; // // Step 1: construct query to find all subscriptions belonging to teams in the project // TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); // Get all teams in the project TeamHttpClient teamClient = connection.GetClient <TeamHttpClient>(); IEnumerable <WebApiTeam> teams = teamClient.GetTeamsAsync(project.Id.ToString()).Result; // Construct a set of query conditions (one for each team) IEnumerable <SubscriptionQueryCondition> conditions = teams.Select <WebApiTeam, SubscriptionQueryCondition>(team => { return(new SubscriptionQueryCondition() { SubscriberId = team.Id }); } ); // Construct the query, making sure to return basic details for subscriptions the caller doesn't have read access to SubscriptionQuery query = new SubscriptionQuery() { Conditions = conditions, QueryFlags = SubscriptionQueryFlags.AlwaysReturnBasicInformation }; // // Part 2: query and show the results // NotificationHttpClient notificationClient = connection.GetClient <NotificationHttpClient>(); IEnumerable <NotificationSubscription> subscriptions = notificationClient.QuerySubscriptionsAsync(query).Result; var subscriptionsByTeam = subscriptions.GroupBy <NotificationSubscription, Guid>(sub => { return(Guid.Parse(sub.Subscriber.Id)); }); foreach (var group in subscriptionsByTeam) { // Find the corresponding team for this group WebApiTeam team = teams.First(t => { return(t.Id.Equals(group.Key)); }); // Show the details for each subscription owned by this team foreach (NotificationSubscription subscription in group) { LogSubscription(subscription); } } }
public WebApiTeam GetTeam() { string project = _configuration.Project; string team = "My new team"; // create team object using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) { WebApiTeam result = teamHttpClient.GetTeamAsync(project, team).Result; return(result); } }
/// <summary> /// Gets a list of TeamMembers /// </summary> /// <param name="team">Team</param> /// <returns>List of TeamMembers for the given team</returns> public async Task <List <TeamMember> > GetMembersAsync(WebApiTeam team) { var client = await GetClientAsync <TeamHttpClient>(); logger.LogInformation("GetMembersAsync TeamId = {0}, TeamName = {1}", team.Id, team.Name); var members = await client.GetTeamMembersWithExtendedPropertiesAsync( team.ProjectId.ToString(), team.Id.ToString() ); return(members); }
// <summary> /// Update an existing team /// </summary> /// <param name="TeamProjectName"></param> /// <param name="TeamName"></param> static void UpdateTeam(string TeamProjectName, string TeamName) { WebApiTeam team = TeamClient.GetTeamAsync(TeamProjectName, TeamName).Result; WebApiTeam updatedTeam = new WebApiTeam { Name = team.Name + " updated", Description = team.Description.Replace("Created", "Updated") }; updatedTeam = TeamClient.UpdateTeamAsync(updatedTeam, team.ProjectName, team.Name).Result; Console.WriteLine("The team '{0}' has been updated in the team project '{1}'", updatedTeam.Name, updatedTeam.ProjectName); }
private Team Map(string organization, string project, WebApiTeam toMap, List <WorkItem> workItems) { return(new Team { Id = toMap.id, Name = toMap.name, Description = toMap.description, Url = $"https://dev.azure.com/{organization}/{project}/_backlogs/backlog/{toMap.name}", WorkItemTypes = MapWorkItemType(workItems), Contributors = MapWorkItemContributor(workItems), Iterations = MapIterations(workItems) }); }
public WebApiTeam CreateTeam() { WebApiTeam teamData = new WebApiTeam() { Name = "My new team" }; VssConnection connection = new VssConnection(_uri, _credentials); TeamHttpClient teamHttpClient = connection.GetClient <TeamHttpClient>(); WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, _configuration.Project).Result; return(result); }
static void Main(string[] args) { // instantiate a vss connection using the Project Collection URI as Base Uri var visualStudioServicesConnection = new VssConnection(new Uri(TeamProjectCollectionUri), new VssCredentials()); // Get a Team client var teamHttpClient = visualStudioServicesConnection.GetClient <TeamHttpClient>(); // Retrieve existing Team(s) // ############################## // First lets retrieve the teams (first 10 again) for the given Project(Id) var allTeams = teamHttpClient.GetTeamsAsync(ProjectId, top: 10, skip: 0).Result; foreach (var team in allTeams) { Console.WriteLine("Team '{0}' (Id: {1})", team.Name, team.Id); } // Create Team(s) // ############################## var somewhatRandomValueForTeamName = (int)(DateTime.UtcNow - DateTime.UtcNow.Date).TotalSeconds; // We can also create new Team(s), the minimum amount of information you have to provide is var newTeam = new WebApiTeam() { // .. only the .Name of the new Team // albeit it may NOT contain these characters: @ ~ ; ' + = , < > | / \ ? : & $ * " # [ ] // but i.e. whitespaces are just fine Name = $"My new Team {somewhatRandomValueForTeamName}" }; // once we've prepared the team instance, we call the api endpoint using the teamHttpClient var newlyCreatedTeam = teamHttpClient.CreateTeamAsync(newTeam, ProjectId).Result; Console.WriteLine("Team '{0}' (Id: {1}) created", newlyCreatedTeam.Name, newlyCreatedTeam.Id); // Retrieve Team Members // ############################## Console.WriteLine("Team with Id '{0}' contains the following member(s)", TeamIdKnownToContainMembers); foreach (var identityReference in teamHttpClient.GetTeamMembersWithExtendedPropertiesAsync(ProjectId, TeamIdKnownToContainMembers, 10, 0).Result) { Console.WriteLine("-- '{0}' (Id: {1})", identityReference.Identity.DisplayName, identityReference.Identity.Id); } // Delete Team(s) // ############################## // we can als delete existing Teams, i.e. the one we've just created teamHttpClient.DeleteTeamAsync(ProjectId, newlyCreatedTeam.Id.ToString()).Wait(); }
public WebApiTeam UpdateTeam() { string teamName = "My new team"; WebApiTeam teamData = new WebApiTeam() { Description = "my awesome team description" }; VssConnection connection = new VssConnection(_uri, _credentials); TeamHttpClient teamHttpClient = connection.GetClient <TeamHttpClient>(); WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, _configuration.Project, teamName).Result; return(result); }
public WebApiTeam CreateTeam() { string project = _configuration.Project; WebApiTeam teamData = new WebApiTeam() { Name = "My new team" }; // create team object using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) { WebApiTeam result = teamHttpClient.CreateTeamAsync(teamData, project).Result; return(result); } }
public WebApiTeam UpdateTeam() { string project = _configuration.Project; string team = "My new team"; WebApiTeam teamData = new WebApiTeam() { Description = "my awesome team description" }; // create team object using (TeamHttpClient teamHttpClient = new TeamHttpClient(_uri, _credentials)) { WebApiTeam result = teamHttpClient.UpdateTeamAsync(teamData, project, team).Result; return(result); } }
public WebApiTeam GetTeam() { // Get any project then get any team from it TeamProjectReference project = ClientSampleHelpers.FindAnyProject(this.Context); string teamName = ClientSampleHelpers.FindAnyTeam(this.Context, project.Id).Name; // Get a client VssConnection connection = Context.Connection; TeamHttpClient teamClient = connection.GetClient <TeamHttpClient>(); WebApiTeam team = teamClient.GetTeamAsync(project.Id.ToString(), teamName).Result; Console.WriteLine("ID : {0}", team.Id); Console.WriteLine("Name : {0}", team.Name); Console.WriteLine("Description: {0}", team.Description); return(team); }
public ActionResult Get(string name) { using (TfsClaimsPrincipal claim = (TfsClaimsPrincipal)HttpContext.User) { CommandHandler handler = new CommandHandler(claim, null); WebApiTeam team = name == "@Me" ? handler.GetTeamById(claim.TfsIdentity) : handler.GetTeam(claim.TfsIdentity.ProjectId.ToString(), name); if (claim.IsReturnJson) { return(new JsonResult(team)); } else { return(claim.GetContentResult(team.ToBotString())); } } }
/// <summary> /// Creates a new team using the <paramref name="teamToCreate" /> as template in the project corresponding to the <paramref name="projectNameOrId" />. /// </summary> /// <param name="teamHttpClient">The team HTTP client.</param> /// <param name="teamToCreate">The team to create.</param> /// <param name="projectNameOrId">The project name or identifier.</param> /// <param name="userState">The user state object to pass along to the underlying method.</param> /// <returns> /// The created team. /// </returns> /// <exception cref="ArgumentNullException">teamHttpClient</exception> public static IObservable <WebApiTeam> CreateTeam( this TeamHttpClient teamHttpClient, WebApiTeam teamToCreate, string projectNameOrId, object userState = null) { if (teamHttpClient == null) { throw new ArgumentNullException(nameof(teamHttpClient)); } if (teamToCreate == null) { throw new ArgumentNullException(nameof(teamToCreate)); } if (string.IsNullOrWhiteSpace(projectNameOrId)) { throw new ArgumentOutOfRangeException(nameof(projectNameOrId), $"'{nameof(projectNameOrId)}' may not be null or empty or whitespaces only"); } return(Observable.FromAsync(cancellationToken => teamHttpClient.CreateTeamAsync(teamToCreate, projectNameOrId, userState, cancellationToken))); }
private async Task <WebApiTeam> EnsureTeamExists( BuildDefinition pipeline, string suffix, TeamPurpose purpose, IEnumerable <WebApiTeam> teams, bool persistChanges) { var result = teams.FirstOrDefault( team => { // Swallowing exceptions because parse errors on // free form text fields which might be non-yaml text // are not exceptional var metadata = YamlHelper.Deserialize <TeamMetadata>(team.Description, swallowExceptions: true); return(metadata?.PipelineId == pipeline.Id && metadata?.Purpose == purpose); }); if (result == default) { logger.LogInformation("Team Not Found Suffix = {0}", suffix); var teamMetadata = new TeamMetadata { PipelineId = pipeline.Id, Purpose = purpose, }; var newTeam = new WebApiTeam { Description = YamlHelper.Serialize(teamMetadata), // Ensure team name fits within maximum 64 character limit // https://docs.microsoft.com/en-us/azure/devops/organizations/settings/naming-restrictions?view=azure-devops#teams Name = StringHelper.MaxLength($"{pipeline.Name} -- {suffix}", MaxTeamNameLength), }; logger.LogInformation("Create Team for Pipeline PipelineId = {0} Purpose = {1}", pipeline.Id, purpose); if (persistChanges) { result = await service.CreateTeamForProjectAsync(pipeline.Project.Id.ToString(), newTeam); } } return(result); }
private async Task EnsureSynchronizedNotificationTeamIsChild(WebApiTeam parent, WebApiTeam child, bool persistChanges) { var parentDescriptor = await service.GetDescriptorAsync(parent.Id); var childDescriptor = await service.GetDescriptorAsync(child.Id); var isInTeam = await service.CheckMembershipAsync(parentDescriptor, childDescriptor); logger.LogInformation("Child In Parent ParentId = {0}, ChildId = {1}, IsInTeam = {2}", parent.Id, child.Id, isInTeam); if (!isInTeam) { logger.LogInformation("Adding Child Team"); if (persistChanges) { await service.AddToTeamAsync(parentDescriptor, childDescriptor); } } }
private async Task <WebApiTeam> EnsureTeamExists( BuildDefinition pipeline, string suffix, TeamPurpose purpose, IEnumerable <WebApiTeam> teams, bool persistChanges) { var result = teams.FirstOrDefault( team => { // Swallowing exceptions because parse errors on // free form text fields which might be non-yaml text // are not exceptional var metadata = YamlHelper.Deserialize <TeamMetadata>(team.Description, swallowExceptions: true); return(metadata?.PipelineId == pipeline.Id && metadata?.Purpose == purpose); }); if (result == default) { logger.LogInformation("Team Not Found Suffix = {0}", suffix); var teamMetadata = new TeamMetadata { PipelineId = pipeline.Id, Purpose = purpose, }; var newTeam = new WebApiTeam { Description = YamlHelper.Serialize(teamMetadata), Name = $"{pipeline.Name} -- {suffix}", }; logger.LogInformation("Create Team for Pipeline PipelineId = {0} Purpose = {1}", pipeline.Id, purpose); if (persistChanges) { result = await service.CreateTeamForProjectAsync(pipeline.Project.Id.ToString(), newTeam); } } return(result); }
public void CL_ProjectsAndTeams_Teams_UpdateTeam_Success() { // arrange Teams request = new Teams(_configuration); WebApiTeam teamData = new WebApiTeam() { Name = "My new team", Description = "my awesome team description" }; // act try { var result = request.UpdateTeam(_configuration.Project, "My new team", teamData); // assert Assert.AreEqual("My new team", result.Name); } catch (System.AggregateException) { Assert.Inconclusive("'My new team' does not exist"); } }
public void CL_ProjectsAndTeams_Teams_CreateTeam_Success() { // arrange Teams request = new Teams(_configuration); WebApiTeam teamData = new WebApiTeam() { Name = "My new team" }; // act try { var result = request.CreateTeam(_configuration.Project, teamData); // assert Assert.AreEqual("My new team", result.Name); } catch (System.AggregateException) { Assert.Inconclusive("'My new team' already exists"); } }
public async Task <WebApiTeam> CreateTeamAsync(WebApiTeam team, Guid projectId) { return(await teamClient.CreateTeamAsync(team, projectId.ToString())); }
/// <summary> /// Gets all team members for the given <paramref name="project" /> and <paramref name="team" />. /// </summary> /// <param name="client">The <see cref="TeamHttpClient" /> to use.</param> /// <param name="connection">The connection for the <paramref name="client" /> that will be used to retrieve the identities for the team members.</param> /// <param name="project">The project.</param> /// <param name="team">The team.</param> /// <param name="pageSize">Page size to use while retrieving the projects.</param> /// <param name="userState">The user state object.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// </exception> public static Task<IReadOnlyCollection<Identity>> GetAllTeamMembers(this TeamHttpClient client, VssConnection connection, TeamProject project, WebApiTeam team, int pageSize = 10, object userState = null, CancellationToken cancellationToken = default(CancellationToken)) { if (client == null) throw new ArgumentNullException(nameof(client)); if (connection == null) throw new ArgumentNullException(nameof(connection)); if (project == null) throw new ArgumentNullException(nameof(project)); if (team == null) throw new ArgumentNullException(nameof(team)); return client.GetAllTeamMembers(connection, project.Id, team.Id, pageSize, userState, cancellationToken); }