如何在WIQL工作项中获得层次结构 [英] how to get Hiearchical structure in WIQL workitem

查看:155
本文介绍了如何在WIQL工作项中获得层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这样的TFS中有一个股骨结构 其中一个功能可以具有"N"个产品积压项目,而单个产品产品积压项目"可以具有"N"个任务/错误 树状结构

i have a hiearchial strurcture in TFS like this where a 1 Feature can have 'N' number of Product backlog items and single product Product backlogitem can have 'N' number of task/bugs tree structure

功能1->
PB1->
Task1,task2,task3

Feature1->
PB1->
Task1,task2,task3

我的查询

string querystring = string.Format("select [System.Id], [System.Title],[Story.Author],[Story.Owner],[System.AssignedTo]," +
                " [System.WorkItemType],[Microsoft.VSTS.Scheduling.StoryPoints],[Microsoft.VSTS.Common.Priority]," +
                "[Microsoft.VSTS.Scheduling.Effort], [Actual.Effort.Completed]" +
                ",[System.State]," +
                "[System.IterationPath]" +
                " FROM WorkItemLinks" +
                " WHERE" +
                " ([Source].[System.TeamProject]='{0}'" +
                " and [Source].[System.IterationPath] UNDER 'MRI_SCRUM_GIT\\Pluse Pheonix\\Sprint 1'" +
                " and [Source].[System.WorkitemType]<>'' " +
                ")" +

                " and ([System.Links.LinkType]='System.LinkTypes.Hierarchy-Forward')" +
                " and ([Target].[System.WorkItemType] <> '' )" +
                " ORDER BY [System.Id] " +
               " mode (Recursive)", projectname);

现在如何获取C#代码中的所有字段,如下图所示

Now how do i get all the fields in C# code like the below image

推荐答案

以下网站上的代码段已存在:

Here is already a code snippet on the following website:

https://docs.microsoft.com/en-us/vsts/integrate/quickstarts/work-item-quickstart

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi.Patch.Json;
using Microsoft.VisualStudio.Services.WebApi.Patch;
using Microsoft.VisualStudio.Services.WebApi;
using System.Net.Http.Headers;
using System.Net.Http;
using Newtonsoft.Json;

public class ExecuteQuery
{
    readonly string _uri;
    readonly string _personalAccessToken;
    readonly string _project;

    /// <summary>
    /// Constructor. Manually set values to match your account.
    /// </summary>
    public ExecuteQuery()
    {
        _uri = "https://accountname.visualstudio.com";
        _personalAccessToken = "personal access token";
        _project = "project name";
    }

    /// <summary>
    /// Execute a WIQL query to return a list of bugs using the .NET client library
    /// </summary>
    /// <returns>List of Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem</returns>
    public List<WorkItem> RunGetBugsQueryUsingClientLib()
    {
        Uri uri = new Uri(_uri);
        string personalAccessToken = _personalAccessToken;
        string project = _project;

        VssBasicCredential credentials = new VssBasicCredential("", _personalAccessToken);

        //create a wiql object and build our query
        Wiql wiql = new Wiql()
        {
            Query = "Select [State], [Title] " +
                    "From WorkItems " +
                    "Where [Work Item Type] = 'Bug' " +
                    "And [System.TeamProject] = '" + project + "' " +
                    "And [System.State] <> 'Closed' " +
                    "Order By [State] Asc, [Changed Date] Desc"
        };

        //create instance of work item tracking http client
        using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(uri, credentials))
        {
            //execute the query to get the list of work items in the results
            WorkItemQueryResult workItemQueryResult = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result;

            //some error handling                
            if (workItemQueryResult.WorkItems.Count() != 0)
            {
                //need to get the list of our work item ids and put them into an array
                List<int> list = new List<int>();
                foreach (var item in workItemQueryResult.WorkItems)
                {
                    list.Add(item.Id);
                }
                int[] arr = list.ToArray();

                //build a list of the fields we want to see
                string[] fields = new string[3];
                fields[0] = "System.Id";
                fields[1] = "System.Title";
                fields[2] = "System.State";

                //get work items for the ids found in query
                var workItems = workItemTrackingHttpClient.GetWorkItemsAsync(arr, fields, workItemQueryResult.AsOf).Result;

                Console.WriteLine("Query Results: {0} items found", workItems.Count);

                //loop though work items and write to console
                foreach (var workItem in workItems)
                {
                    Console.WriteLine("{0}          {1}                     {2}", workItem.Id, workItem.Fields["System.Title"], workItem.Fields["System.State"]);
                }

                return workItems;
            }

            return null;
        }
    }
}

这篇关于如何在WIQL工作项中获得层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆