WorkItemHttpClient - 未找到 TFS 工作项或没有读取它的权限
WorkItemHttpClient - TFS work item not found or not permission to read it
请查找以下 Wiql 查询。 (获取从某个日期到现在的所有工作项)
@"SELECT * FROM WorkItems WHERE [System.TeamProject] = '" + _teamProjectName + "' and( [System.ChangedDate] >= '" + fromDate + "' and [System.ChangedDate] <= '" + toDate + "') ORDER BY [System.AssignedTo]"
我正在按照以下代码从此查询中获取所有工作项。 (请让我知道查询是否正确)。但是每当我尝试调用此函数 GetWorkItemsAsync
时,我都会收到错误消息 -
TFS work item 'xyz' does not exist or you don't have permission to
read it
基本上 fromDate
是一周的开始,toDate
是一周的结束。
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>())
{
//execute the query to get the list of work items in the results
WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
IEnumerable<WorkItemReference> workItemRefs = workItemQueryResult.WorkItems;
List<DateTime> weekDatesToGetWorkItems = weekDates();
foreach (var item in weekDatesToGetWorkItems)
{
try
{
int skip = 0;
const int batchSize = 100;
do
{
workItemRefs = workItemQueryResult.WorkItems.Skip(skip).Take(batchSize);
if (workItemRefs.Any())
{
//Exception here
List<WorkItem> workItems = workItemTrackingHttpClient.GetWorkItemsAsync(workItemRefs.Select(wir => wir.Id), this.GetFieldNames(), item).Result;
}
}
while (workItemRefs.Count() == batchSize);
}
catch (Exception ex)
{
//// Always gives an exception for one of the workItem "TFS work item xyz does not exist or you don't have permission to read it"
}
}
}
问题 1:
知道如何调试或解决上述异常吗?
问题二:
我已经尝试通过传递单个 workitemId 使用 GetWorkItemAsync
获取工作项数据。这行得通,但我得到的数据与最新数据不同步,它总是给我前一周的数据。有没有正确的方法获取最新的?
非常感谢任何对此问题的帮助。
我的第二个问题得到了答案。看来我在时间部分犯了一个愚蠢的错误。
我添加了时间戳值,现在我可以获取最新数据了。
List<WorkItem> workItems = workItemTrackingHttpClient.GetWorkItemsAsync(workItemRefs.Select(wir => wir.Id), this.GetFieldNames(),
item.Add(new TimeStamp(23,59,59))).Result;
//// Adding timestamp worked here.
因此,下次如果您遇到与日期有关的问题,请不要忽略时间部分。 (愚蠢但总是被忽视)。
编码愉快!!
干杯!
请查找以下 Wiql 查询。 (获取从某个日期到现在的所有工作项)
@"SELECT * FROM WorkItems WHERE [System.TeamProject] = '" + _teamProjectName + "' and( [System.ChangedDate] >= '" + fromDate + "' and [System.ChangedDate] <= '" + toDate + "') ORDER BY [System.AssignedTo]"
我正在按照以下代码从此查询中获取所有工作项。 (请让我知道查询是否正确)。但是每当我尝试调用此函数 GetWorkItemsAsync
时,我都会收到错误消息 -
TFS work item 'xyz' does not exist or you don't have permission to read it
基本上 fromDate
是一周的开始,toDate
是一周的结束。
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient<WorkItemTrackingHttpClient>())
{
//execute the query to get the list of work items in the results
WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;
IEnumerable<WorkItemReference> workItemRefs = workItemQueryResult.WorkItems;
List<DateTime> weekDatesToGetWorkItems = weekDates();
foreach (var item in weekDatesToGetWorkItems)
{
try
{
int skip = 0;
const int batchSize = 100;
do
{
workItemRefs = workItemQueryResult.WorkItems.Skip(skip).Take(batchSize);
if (workItemRefs.Any())
{
//Exception here
List<WorkItem> workItems = workItemTrackingHttpClient.GetWorkItemsAsync(workItemRefs.Select(wir => wir.Id), this.GetFieldNames(), item).Result;
}
}
while (workItemRefs.Count() == batchSize);
}
catch (Exception ex)
{
//// Always gives an exception for one of the workItem "TFS work item xyz does not exist or you don't have permission to read it"
}
}
}
问题 1: 知道如何调试或解决上述异常吗?
问题二:
我已经尝试通过传递单个 workitemId 使用 GetWorkItemAsync
获取工作项数据。这行得通,但我得到的数据与最新数据不同步,它总是给我前一周的数据。有没有正确的方法获取最新的?
非常感谢任何对此问题的帮助。
我的第二个问题得到了答案。看来我在时间部分犯了一个愚蠢的错误。
我添加了时间戳值,现在我可以获取最新数据了。
List<WorkItem> workItems = workItemTrackingHttpClient.GetWorkItemsAsync(workItemRefs.Select(wir => wir.Id), this.GetFieldNames(),
item.Add(new TimeStamp(23,59,59))).Result;
//// Adding timestamp worked here.
因此,下次如果您遇到与日期有关的问题,请不要忽略时间部分。 (愚蠢但总是被忽视)。
编码愉快!! 干杯!