我正在製作一個控制檯應用程序,它接受用戶輸入以創建一個新區域。基於該名稱,組將生成並放入項目中,並硬編碼到應用程序中。截至目前,下面的代碼將做到這一點:如何使用API將項目中的組添加到TFS中的區域?
Project that all areas will be placed into
-> Areas
-> New area just created
-> Security
-> Groups
-> Newly created groups
不過,我也想這些羣體被放置到區域本身:
Project that all areas will be placed into
-> Areas
-> New area just created
-> Security
-> Groups
-> Newly created groups
-> Security
-> Groups
-> Newly created groups
現在,當您查看安全的地區,它只有默認組,而不是我創建的組。
我無法找到任何有關通過API管理區域安全的信息。
public class AreaBuilder
{
static IIdentityManagementService _ims;
static List<TeamFoundationIdentity> m_groups = new List<TeamFoundationIdentity>();
static void Main(string[] args)
{
string projectName = "some_project";
string mainUri = "http://something:8080/tfs";
string collectionUri = "http://something:8080/tfs/some_collection";
Console.WriteLine("Enter the name of an area that you'd like to create: \n\n");
Console.Write("AreaBuilder> ");
string areaName = Console.ReadLine();
// Get the structure of the groups and their privileges
AreaStructure structure = new AreaStructure(areaName);
Dictionary<string, List<AreaStructure.Privileges>> groups = structure.getGroups();
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri));
VersionControlServer vcs = tpc.GetService<VersionControlServer>();
try
{
Microsoft.TeamFoundation.VersionControl.Client.TeamProject project = vcs.GetTeamProject(projectName);
IGroupSecurityService gss = tpc.GetService<IGroupSecurityService>();
foreach(string groupName in groups.Keys)
{
gss.CreateApplicationGroup(project.ArtifactUri.AbsoluteUri, groupName, null);
Console.WriteLine(groupName + " created.");
}
}
catch (Exception e)
{
Console.WriteLine("Could not create group: " + e.ToString());
}
WorkItemClassificationNode node = new WorkItemClassificationNode()
{
Name = areaName,
StructureType = TreeNodeStructureType.Area,
Children = new List<WorkItemClassificationNode>()
};
// Get the connection
VssConnection connection = new VssConnection(new Uri(collectionUri), new VssCredentials());
// Get the work item client
WorkItemTrackingHttpClient workItemTrackingClient = connection.
GetClient<WorkItemTrackingHttpClient>();
// Create the new area
WorkItemClassificationNode area = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(
node,
projectName,
TreeStructureGroup.Areas).Result;
// Get the project client
ProjectHttpClient projectClient = connection.GetClient<ProjectHttpClient>();
// Get the projects in the project client
IEnumerable<TeamProjectReference> projects = projectClient.GetProjects().Result;
Console.ReadLine();
}
}
另外,要爲組設置權限,必須傳遞一個對應於您試圖允許/拒絕的權限的int。但是,在[TeamProjectPermissions類](https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.framework.common.teamprojectpermissions(v = vs.120).aspx)中,它們缺少一個對應的整數創建標記定義_,刪除此項目中的工作項目_和_永久刪除此項目中的工作項目__的權限。所以我不知道如何將這些權限設置到項目中的某個組 –
@JoshEvans對不起,第一個誤解。已更新我的回覆。 –
謝謝帕特里克,很棒的鏈接。但是,您是否注意到我在上述評論中的問題? –