// http://blogs.microsoft.co.il/shair/2009/01/13/tfs-api-part-3-get-project-list-using-icommonstructureservice/ private static ProjectInfo[] GetDefaultProjectInfo(TfsTeamProjectCollection tfs) { // Create ICommonStructureService object that will take TFS Structure Service. ICommonStructureService structureService = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); // Use ListAllProjects method to get all Team Projects in the TFS. ProjectInfo[] projects = structureService.ListAllProjects(); return(projects); }
/// <summary> /// Получить список Team Projects /// </summary> public List <string> GetTfsTeamProjects() { List <ProjectInfo> projectInfoList = new List <ProjectInfo>(structureService.ListAllProjects()); IEnumerable <string> teamProjectsList = projectInfoList. Where(proj => proj.Status != ProjectState.Deleting). Select(proj => proj.Name); List <string> sortTeamProjects = teamProjectsList.ToList(); sortTeamProjects.Sort(); return(sortTeamProjects); }
/// <summary> /// Gets the users. /// </summary> /// <returns></returns> public List <TeamFoundationIdentity> GetUsers() { TfsTeamProjectCollection projectCollection = this.GetTeamProjectCollection(); ICommonStructureService css = (ICommonStructureService)projectCollection.GetService(typeof(ICommonStructureService)); IGroupSecurityService gss = projectCollection.GetService <IGroupSecurityService>(); IIdentityManagementService ims = projectCollection.GetService <IIdentityManagementService>(); // get the tfs project var projectList = css.ListAllProjects(); var project = projectList.FirstOrDefault(o => o.Name.Equals(this.TfsServer.ActiveProjectContext.ProjectName, StringComparison.InvariantCultureIgnoreCase)); // project doesn't exist if (project == null) { return(null); } // get the tfs group var groupList = gss.ListApplicationGroups(project.Uri); List <Identity> groups; if (ConfigurationManager.CurrentConfiguration.UserGroups != null && ConfigurationManager.CurrentConfiguration.UserGroups.Count > 0) { groups = groupList.Where(o => ConfigurationManager.CurrentConfiguration.UserGroups.Contains(o.AccountName)).ToList(); // you can also use DisplayName } else { groups = groupList.ToList(); } List <TeamFoundationIdentity> contributors = new List <TeamFoundationIdentity>(); foreach (Identity group in groups) { Identity sids = gss.ReadIdentity(SearchFactor.Sid, group.Sid, QueryMembership.Expanded); // there are no users if (sids.Members.Length == 0) { continue; } // convert to a list contributors.AddRange(ims.ReadIdentities(IdentitySearchFactor.Identifier, sids.Members, MembershipQuery.Direct, ReadIdentityOptions.None).SelectMany(x => x).Where(x => x.IsContainer == false)); } return(contributors.GroupBy(x => x.DisplayName).Select(g => g.First()).OrderBy(x => x.DisplayName).ToList()); }
static int Main(string[] args) { // C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe with "/rootsuffix Exp" // or // Start Project with -c https://dev.bittitan.com/tfs/BitTitan -p SendBus -f TfsPoking.dgml Options options = new Options(); Parser parser = new Parser(settings => { settings.CaseSensitive = false; settings.HelpWriter = Console.Error; settings.ParsingCulture = CultureInfo.InvariantCulture; }); bool result = parser.ParseArguments(args, options); if (!result) { ConsoleEntryPoint.Fail(); return(-1); } Uri collectionUri = new Uri(options.Collection); TfsTeamProjectCollection tfsTeamProjectCollection = new TfsTeamProjectCollection(collectionUri, CredentialCache.DefaultCredentials); tfsTeamProjectCollection.EnsureAuthenticated(); ICommonStructureService commonStructureService = tfsTeamProjectCollection.GetService <ICommonStructureService>(); IEnumerable <ProjectInfo> projectInfoList = commonStructureService.ListAllProjects(); if (options.Projects.Any()) { projectInfoList = projectInfoList.Where(pil => options.Projects.Contains(pil.Name)).ToArray(); } TfsPermissionGraphGenerator generator = new TfsPermissionGraphGenerator(); XDocument xDocument = generator.GenerateDependencyGraph(tfsTeamProjectCollection, projectInfoList); string dgmlTempFilePath = (String.IsNullOrEmpty(options.OutputFile)) ? "TfsPermissionVisualizer.dgml" : options.OutputFile; xDocument.Save(dgmlTempFilePath); return(0); }
public void ListAllProjects() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) { return; } TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService)); ProjectInfo[] projects = css.ListAllProjects(); foreach (ProjectInfo pinfo in projects) { Assert.IsNotNull(pinfo.Name); Assert.IsNotNull(pinfo.Status); Assert.IsNotNull(pinfo.Uri); } }
public ProjectInfo[] GetTFSProjectInfo() { ICommonStructureService svc = ProjectCollection.GetService <ICommonStructureService>(); return(svc.ListAllProjects()); }