将 TFS REST API 与存储查询一起使用时是否会复杂化? [英] Is the TFS REST API that compilcated when using it with stored queries?

查看:41
本文介绍了将 TFS REST API 与存储查询一起使用时是否会复杂化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里提到:使用 TFS REST API 获取迭代中的所有工作项我已经在 https://www.visualstudio.com/en-us/docs/integrate/api/wit/queries#get-a-query-or-folder

我们尝试根据 TFS 服务器上存储的查询生成更改日志文本文件.在 REST API 之前,我们使用的是 VS 2012/2013 TFS 库,但现在正在转向 REST.

We try to generate a change log text file based on a stored query on the TFS server. Prior to the REST API we were using the VS 2012/2013 TFS library but are now shifting to REST.

现在通过阅读文档,我看到在查询工作项时,我应该为最多 200 个工作项执行此操作 (https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#get-work-items)

Now by reading the docs I see that when querying work items I should do this for max 200 work items (https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#get-work-items)

如果我正确理解了文档,那么对于返回 607 个工作项的存储查询,我需要 6 个 http 查询.

If I understand the documentation correctly, then I need 6 http queries for a stored query that returns 607 work items.

  1. 按名称获取存储的查询 ->http://server/Project/_apis/wit/queries/Shared%20Queries/Change%20Log?api-version=1.0&$expand=all,返回查询的 WIQL url
  2. 查询 WIQL -> 返回 607 id
  3. 为前 200 个工作项创建工作项查询
  4. 未来 200 年
  5. 未来 200 年
  6. 接下来的 7 个
  1. Get Stored Query by name -> http://server/Project/_apis/wit/queries/Shared%20Queries/Change%20Log?api-version=1.0&$expand=all, which returns the WIQL url for the query
  2. Query WIQL -> returning 607 ids
  3. Create a work item query for the first 200 work items
  4. for the next 200
  5. for the next 200
  6. for the next 7

然后根据查询编号提供的显示列配置组合这些工作项并对其进行格式化.1.

Then assemble those work items and format them according to the display columns configuration which is provided by query no. 1.

通过测试 200 个工作项的限制,我发现本地安装实际上允许更多的工作项.目前,最大工作项数量由 GET 请求长度 2096 定义(在 TFS 2017 上测试).

By testing the 200 work item limit I found out that the on premise installation actually allow more work items. Currently the max amount of work items is defined by the GET request length of 2096 (tested on TFS 2017).

这是关于如何执行存储查询的确认方法吗?

Is this the confirmed approach on how to execute stored queries?

推荐答案

是的,这是正确的方法.

Yes, it is the right approach.

发送 REST API 的简单 C# 代码:

Simple C# code to send REST API:

String MyURI = "[REST API URL]";
            WebRequest WReq = WebRequest.Create(MyURI);
            WReq.Credentials =
                new NetworkCredential("[user name]", "[password]", "[domain]");

            WebResponse response = WReq.GetResponse();
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Console.WriteLine(responseFromServer);

另一方面,您可以运行查询WIQL 字符串.

关于获取存储查询的WIQL字符串,可以使用TFS .net客户端API.

Regarding to get WIQL string of stored query, you can use TFS .net client API.

NetworkCredential cred = new NetworkCredential("[user name]", "[password]", "[domain]");
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("[collection URL"), cred);
            tpc.EnsureAuthenticated();
            WorkItemStore wis = tpc.GetService(typeof(WorkItemStore)) as WorkItemStore;
 QueryHierarchy queryRoot = wis.Projects["[team project]"].QueryHierarchy;
            QueryFolder queryFolder = queryRoot["Shared Queries"] as QueryFolder;
            QueryDefinition qd = queryFolder["PBIS"] as QueryDefinition;
            string tt = qd.QueryText;

关于使用扩展客户端包调用查询REST API,您可以参考这个简单的代码:

Regarding call query REST API with Extended Client package, you can refer to this simple code:

var u = new Uri("[collection url]");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("v-stache", "Hua543@Hua543", "fareast")));
            var connection = new VssConnection(u, c);
            var workitemClient = connection.GetClient<WorkItemTrackingHttpClient>();
 var result = workitemClient.QueryByWiqlAsync(new Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.Wiql() { Query = "select[System.Id] from WorkItems where [System.TeamProject] = 'ScrumStarain2' and [System.WorkItemType] = 'Product Backlog Item' and [System.State] <> ''" }, "ScrumStarain2").Result;

这篇关于将 TFS REST API 与存储查询一起使用时是否会复杂化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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