使用TFS WIQL获取用户故事的变更集ID?

时间:2014-03-12 17:30:44

标签: c# tfs wiql

检索分配给我的用户故事

WorkItemStore _WorkItemStore = (WorkItemStore) __ProjectCollection.GetService(typeof(WorkItemStore));                      
String _Query = @"SELECT [System.Id] FROM WorkItems where [Assigned to] = @Me AND [Work Item Type] = 'User Story'";
WorkItemCollection _Collection = _WorkItemStore.Query(_Query);

用户素材可以将任务或错误工作项类型指定为子项。然后,错误/任务具有与其相关联的变更集。

我是否可以检索附加到作为这些用户故事的子项的任务/错误的这些变更集的列表?

1 个答案:

答案 0 :(得分:2)

我添加此答案作为替代方案,但我仍然想知道是否有可能通过WIQL查询获得相同的结果。

我编写的递归函数,用于检索与任何子工作项关联的用户的所有变更集。

public List<Changeset> Query(int id, List<Changeset> associatedChangesets)
{            
    WorkItemStore _WorkItemStore = (WorkItemStore) __ProjectCollection.GetService(typeof(WorkItemStore));            
    WorkItem _WorkItem = _WorkItemStore.GetWorkItem(id);

    List<Changeset> _AssociatedChangesets;

    if (associatedChangesets == null)
    {
            _AssociatedChangesets = new List<Changeset>();
    }
    else
    {
        _AssociatedChangesets = associatedChangesets;
    }

    foreach (Link _Link in _WorkItem.Links)
    {
        RelatedLink _RelatedLink = null;
        ExternalLink _ExternalLink = null;

        if(_Link is RelatedLink)
        {
            _RelatedLink = (RelatedLink)_Link;
        }
        else if(_Link is ExternalLink)
        {
            _ExternalLink = (ExternalLink)_Link;
        }

        if (_ExternalLink != null)
        {
            ArtifactId _Artifact = LinkingUtilities.DecodeUri(_ExternalLink.LinkedArtifactUri);
            if (String.Equals(_Artifact.ArtifactType, "Changeset", StringComparison.Ordinal))
            {                        
                _AssociatedChangesets.Add(__VersionControl.ArtifactProvider.GetChangeset(new Uri(_ExternalLink.LinkedArtifactUri)));
            }
        }

        if (_RelatedLink != null)
        {
            if (String.Equals(_RelatedLink.LinkTypeEnd.Name, "Child", StringComparison.Ordinal))
            {
                associatedChangesets = Query(_RelatedLink.RelatedWorkItemId, _AssociatedChangesets);
            }
        }
    }
    return associatedChangesets;
}