private static TeamFoundation.Build.Client.IBuildDetailSpec CreateBuildDetailSpec(TeamFoundation.Build.Client.IBuildServer buildServer, string projectName, FilterNode rootFilterNode) { var detailSpec = default(TeamFoundation.Build.Client.IBuildDetailSpec); if (rootFilterNode != null) { var definitionSpec = buildServer.CreateBuildDefinitionSpec(projectName); var definition = rootFilterNode.SingleOrDefault(p => p.Key.Equals("Definition", StringComparison.OrdinalIgnoreCase)); var number = rootFilterNode.SingleOrDefault(p => p.Key.Equals("Number", StringComparison.OrdinalIgnoreCase)); var quality = rootFilterNode.SingleOrDefault(p => p.Key.Equals("Quality", StringComparison.OrdinalIgnoreCase)); var reason = rootFilterNode.SingleOrDefault(p => p.Key.Equals("Reason", StringComparison.OrdinalIgnoreCase)); var status = rootFilterNode.SingleOrDefault(p => p.Key.Equals("Status", StringComparison.OrdinalIgnoreCase)); var requestedFor = rootFilterNode.SingleOrDefault(p => p.Key.Equals("RequestedFor", StringComparison.OrdinalIgnoreCase)); if (definition != null) { if (definition.Sign != FilterExpressionType.Equal) { throw new DataServiceException(501, "Not Implemented", "Build Definition can only be filtered with an equality operator", "en-US", null); } definitionSpec.Name = definition.Value; } detailSpec = buildServer.CreateBuildDetailSpec(definitionSpec); if (number != null) { if (number.Sign != FilterExpressionType.Equal) { throw new DataServiceException(501, "Not Implemented", "Build Number can only be filtered with an equality operator", "en-US", null); } detailSpec.BuildNumber = number.Value; } if (quality != null) { if (quality.Sign != FilterExpressionType.Equal) { throw new DataServiceException(501, "Not Implemented", "Build Quality can only be filtered with an equality operator", "en-US", null); } detailSpec.Quality = quality.Value; } if (requestedFor != null) { if (requestedFor.Sign != FilterExpressionType.Equal) { throw new DataServiceException(501, "Not Implemented", "Requested For can only be filtered with an equality operator", "en-US", null); } detailSpec.RequestedFor = requestedFor.Value; } if (status != null) { if (status.Sign != FilterExpressionType.Equal) { throw new DataServiceException(501, "Not Implemented", "Build Status can only be filtered with an equality operator", "en-US", null); } var statusValue = default(TeamFoundation.Build.Client.BuildStatus); if (Enum.TryParse<TeamFoundation.Build.Client.BuildStatus>(status.Value, out statusValue)) { detailSpec.Status = statusValue; } } if (reason != null) { if (reason.Sign != FilterExpressionType.Equal) { throw new DataServiceException(501, "Not Implemented", "Build Reason can only be filtered with an equality operator", "en-US", null); } var reasonValue = default(TeamFoundation.Build.Client.BuildReason); if (Enum.TryParse<TeamFoundation.Build.Client.BuildReason>(reason.Value, out reasonValue)) { detailSpec.Reason = reasonValue; } } return detailSpec; } else { detailSpec = buildServer.CreateBuildDetailSpec(projectName); } return detailSpec; }
/// <summary> /// ContextChanged override. /// </summary> protected override async void ContextChanged(object sender, TeamFoundation.Client.ContextChangedEventArgs e) { base.ContextChanged(sender, e); // If the team project collection or team project changed, refresh the data for this section if (e.TeamProjectCollectionChanged || e.TeamProjectChanged) { await this.RefreshAsync(); } }
/// <summary> /// Sample method on how to extracts the git version control permissions. /// </summary> /// <param name="server">The server.</param> /// <param name="groups">The groups.</param> /// <param name="userIdentity">The user identity.</param> /// <param name="projectSecurityToken">The project security token.</param> /// <param name="identityManagementService">The identityManagementService.</param> /// <param name="vcs">The VCS.</param> /// <param name="gitService">The git service.</param> /// <returns>List of Permissions</returns> private static List<Permission> ExtractGitVersionControlPermissions(ISecurityService server, IEnumerable<string> groups, TeamFoundationIdentity userIdentity, string projectSecurityToken, IIdentityManagementService identityManagementService, VersionControlServer vcs, TeamFoundation.Git.Client.GitRepositoryService gitService) { Console.WriteLine("== Extract Git Version Control Permissions =="); SecurityNamespace gitVersionControlSecurityNamespace = server.GetSecurityNamespace(Helpers.GetSecurityNamespaceId(PermissionScope.GitSourceControl, server)); var gitProjectRepoService = gitService.QueryRepositories(projectSecurityToken); // This sample handle only the default repository, you can iterate through all repositories same way var defaultGitRepo = gitProjectRepoService.SingleOrDefault(gr => gr.Name.Equals(projectSecurityToken)); vcs.TryGetTeamProject(projectSecurityToken); if (defaultGitRepo == null) { return new List<Permission>(); } // Repository Security Token is repoV2/TeamProjectId/RepositoryId var repoIdToken = string.Format("repoV2{0}{1}{2}{3}", gitVersionControlSecurityNamespace.Description.SeparatorValue, defaultGitRepo.ProjectReference.Id, gitVersionControlSecurityNamespace.Description.SeparatorValue, defaultGitRepo.Id); // vcs.GetTeamProject(projectSecurityToken); AccessControlList versionControlAccessList = gitVersionControlSecurityNamespace.QueryAccessControlList( repoIdToken, new List<IdentityDescriptor> { userIdentity.Descriptor }, true); var gitVersionControlPermissions = new List<Permission>(); foreach (AccessControlEntry ace in versionControlAccessList.AccessControlEntries) { if (0 != ace.Allow) { var allowedVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.Allow).ToString(); gitVersionControlPermissions.AddRange( Helpers.GetActionDetailsByName(allowedVersionControlPermissions, "Allow", PermissionScope.GitSourceControl)); } if (0 != ace.Deny) { var denyVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.Deny).ToString(); gitVersionControlPermissions.AddRange( Helpers.GetActionDetailsByName(denyVersionControlPermissions, "Deny", PermissionScope.GitSourceControl)); } } if (gitVersionControlPermissions.Count == 0) { foreach (AccessControlEntry ace in versionControlAccessList.AccessControlEntries) { if (0 != ace.ExtendedInfo.EffectiveAllow) { var allowedVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.ExtendedInfo.EffectiveAllow).ToString(); gitVersionControlPermissions.AddRange( Helpers.GetActionDetailsByName(allowedVersionControlPermissions, "Allow", PermissionScope.GitSourceControl)); } if (0 != ace.ExtendedInfo.EffectiveDeny) { var denyVersionControlPermissions = ((EnumrationsList.GitPermissions)ace.ExtendedInfo.EffectiveDeny).ToString(); gitVersionControlPermissions.AddRange( Helpers.GetActionDetailsByName(denyVersionControlPermissions, "Deny", PermissionScope.GitSourceControl)); } } } foreach (string group in groups) { TeamFoundationIdentity groupIdentity = identityManagementService.ReadIdentity(IdentitySearchFactor.Identifier, group, MembershipQuery.None, ReadIdentityOptions.IncludeReadFromSource); AccessControlList groupAccessList = gitVersionControlSecurityNamespace.QueryAccessControlList( repoIdToken, new List<IdentityDescriptor> { groupIdentity.Descriptor }, true); foreach (AccessControlEntry ace in groupAccessList.AccessControlEntries) { if (0 != ace.Allow) { var allowedPermissions = ((EnumrationsList.GitPermissions)ace.Allow).ToString(); var permissionsList = Helpers.GetActionDetailsByName(allowedPermissions, "Inherited Allow", PermissionScope.GitSourceControl); Helpers.AppendGroupInheritanceInformation(permissionsList, groupIdentity.DisplayName); gitVersionControlPermissions.AddRange(permissionsList); } if (0 != ace.Deny) { var denyPermissions = ((EnumrationsList.GitPermissions)ace.Deny).ToString(); var permissionsList = Helpers.GetActionDetailsByName(denyPermissions, "Inherited Deny", PermissionScope.GitSourceControl); Helpers.AppendGroupInheritanceInformation(permissionsList, groupIdentity.DisplayName); gitVersionControlPermissions.AddRange(permissionsList); } } } var modifiedPermissions = Helpers.RemoveDuplicatePermissionsAndCombineGroups(gitVersionControlPermissions); return modifiedPermissions; }