TFS SDK 10 ——分组(Group)和成员(Member)
这篇来介绍怎样读取TFS服务器上的用户信息
首先TFS默认有如下分组(Group):
SharePoint Web Application Services
Team Foundation Administrators
Team Foundation Proxy Service Accounts
Team Foundation Service Accounts
Team Foundation Valid Users
Work Item Only View Users
其中
Team Foundation Valid Users 包含其他所有分组
Team Foundation Administrators 包含 Team Foundation Service Accounts
然后每一个Collection也有类似如上的默认分组,及同样的包含关系
Project Collection Administrators
Project Collection Build Administrators
Project Collection Build Service Accounts
Project Collection Proxy Service Accounts
Project Collection Service Accounts
Project Collection Test Service Accounts
Project Collection Valid Users
其中
Project Collection Valid Users 包含其他所有分组
Project Collection Administrators包含Project Collection Service Accounts
我们可以在TFS server 端看到这些。
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;
//连接TFS string tpcURL = "http://127.0.0.1:8080/tfs/defaultcollection"; TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tpcURL)); IGroupSecurityService gss = (IGroupSecurityService)tpc.GetService(typeof(IGroupSecurityService));//所有关于分组和成员的相关的操作都是基于IGroupSecurityService的。 //1:获取全部用户 //先查出用户的Id。参数 QueryMembership 指定是否包含其下从属分组的用户 Identity sids = gss.ReadIdentity(SearchFactor.AccountName, "Team Foundation Valid Users", QueryMembership.Expanded);
//通过id获取用户的信息,包括名称,邮箱等等 var members = gss.ReadIdentities(SearchFactor.Sid, sids.Members, QueryMembership.Expanded);
//2:获取指定项目下的所有分组 VersionControlServer version = tpc.GetService(typeof(VersionControlServer)) as VersionControlServer; TeamProject[] allProjects = version.GetAllTeamProjects(true); string projectUrl = allProjects[0].ArtifactUri.AbsoluteUri; Identity[] groups = gss.ListApplicationGroups(projectUrl); //3:添加分组 string groupName = "MyGroup"; string desp = "My Group Description"; string groupSid = gss.CreateApplicationGroup(projectUrl, groupName, desp); //4: 删除分组 gss.DeleteApplicationGroup(groupSid); //5:获取指定分组下的成员 Identity group = groups[0]; var gsids = gss.ReadIdentity(SearchFactor.Sid, group.Sid, QueryMembership.Expanded); Identity[] gmembers = gss.ReadIdentities(SearchFactor.Sid, gsids.Members, QueryMembership.Expanded); //成员不一定是指用户(User) ,也可能是分组(Group) //成员的类型有如下几种: //gmembers[0].Type== IdentityType.ApplicationGroup; //gmembers[0].Type== IdentityType.InvalidIdentity //gmembers[0].Type== IdentityType.UnknownIdentityType //gmembers[0].Type== IdentityType.WindowsGroup //gmembers[0].Type== IdentityType.WindowsUser
//6:把指定成员添加到指定分组 string memberSid = gmembers[0].Sid; gss.AddMemberToApplicationGroup(group.Sid, memberSid); //7:把指定成员从指定分组移除 gss.RemoveMemberFromApplicationGroup(group.Sid, memberSid);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库