我想让所有用户在项目中进行迭代。
让我们说项目'Precient'有9个不同的用户,有20次迭代,所以我希望不同的用户拥有项目WIQL C#
中的所有迭代。它与问题有关。
WIQL query to get all the team and the users in a Project?
但并没有完全帮助我
答案 0 :(得分:2)
您可以通过REST API或Net API获得该功能。这是Net API的示例。
您可以从Project root Iterations获得所有迭代。
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
namespace GetUserіAndItearions
{
class Program
{
public class Iteration
{
public string Path;
public DateTime DateFrom;
public DateTime DateTo;
}
static void Main(string[] args)
{
string _teamProject = "Your_Project_Name";
try
{
TfsTeamProjectCollection _tpc = new TfsTeamProjectCollection(new Uri("http://your_server:8080/tfs/DefaultCollection"));
GetAllUsers(_tpc, _teamProject);
GetAllIterations(_tpc, _teamProject);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
private static void GetAllIterations(TfsTeamProjectCollection pTpc, string pProjectName)
{
List<Iteration> _its = new List<Iteration>();
WorkItemStore _wistore = pTpc.GetService<WorkItemStore>();
var _css = pTpc.GetService<ICommonStructureService4>();
foreach (Node _node in _wistore.Projects[pProjectName].IterationRootNodes)
FillIterations(_css, _node, _its);
Console.WriteLine("Iterations:");
foreach (Iteration _it in _its) Console.WriteLine("{0}:{1}-{2}", _it.Path,
(_it.DateFrom == DateTime.MinValue) ? "0" : _it.DateFrom.ToShortDateString(), (_it.DateTo== DateTime.MinValue) ? "0" : _it.DateTo.ToShortDateString());
}
private static void FillIterations(ICommonStructureService4 pCss, Node pNode, List<Iteration> pIts)
{
var _nodeInfo = pCss.GetNode(pNode.Uri.AbsoluteUri);
pIts.Add(new Iteration { Path = _nodeInfo.Path,
DateFrom = (_nodeInfo.StartDate == null) ? DateTime.MinValue : (DateTime)_nodeInfo.StartDate,
DateTo = (_nodeInfo.FinishDate == null) ? DateTime.MinValue : (DateTime)_nodeInfo.FinishDate });
if (pNode.HasChildNodes)
foreach (Node _node in pNode.ChildNodes)
FillIterations(pCss, _node, pIts);
}
private static void GetAllUsers(TfsTeamProjectCollection pTpc, string pProjectName)
{
List<string> listUsers = new List<string>();
WorkItemStore _wistore = pTpc.GetService<WorkItemStore>();
var _gss = pTpc.GetService<IIdentityManagementService>();
var _teamProject = _wistore.Projects[pProjectName];
string _validGroupName = "[" + pProjectName + "]\\Project Valid Users";
TeamFoundationIdentity _group = _gss.ReadIdentity(IdentitySearchFactor.DisplayName, _validGroupName, MembershipQuery.Expanded, ReadIdentityOptions.ExtendedProperties);
List<string> _memebersIds = new List<string>();
foreach (var _member in _group.Members) _memebersIds.Add(_member.Identifier);
var _members = _gss.ReadIdentities(IdentitySearchFactor.Identifier, _memebersIds.ToArray(), MembershipQuery.Expanded, ReadIdentityOptions.ExtendedProperties);
foreach (var _member in _members) if (!_member[0].IsContainer) listUsers.Add(_member[0].DisplayName);
Console.WriteLine("Users:");
foreach (var _user in listUsers) Console.WriteLine("{0}", _user);
}
}
}
答案 1 :(得分:1)
无法通过WIQL从团队中获取用户。 WIQL是一种工作项查询语言,用于查询错误,任务和其他类型的工作项。返回值应该是工作项。
您需要使用api作为@Shamray提供来检索用户。以下博客还提供了一个示例:
http://blogs.microsoft.co.il/shair/2012/05/20/tfs-api-part-44-vs11-teams-and-team-members/