将旧TeamFoundation客户端中的RelatedLink替换为新的基于Rest的WebApi模型

问题描述 投票:0回答:1

我正在尝试找到一种方法使该代码段再次工作,但我找不到一个好的替代品来获取与特定工作项匹配的链接。它应该找到相关的工作项(这是它的一部分)

for (int i = 0; i < it.Links.Count; i++)
{
    if (it.Links.[i].BaseType == BaseLinkType.RelatedLink)
    {
        RelatedLink ln = (RelatedLink)it.Links[i];
        if (!ln.LinkTypeEnd.ImmutableName.Contains("Hierarchy") && ln.LinkTypeEnd.Name == "Related")
        {
            if (ln.RelatedWorkItemId == id)
            {
                try
                {
                    WorkItem susp = wis.GetWorkItem(id);
                    if ((string)it.Fields["System.TeamProject"] == (string)susp.Fields["System.TeamProject"])
                        root = susp;
                }
                catch (System.Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
                break;
            }
        }

    }
}

我尝试使用这个:

var result = awaithttpClient.GetReportingLinksByLinkTypeAsync(project).ConfigureAwait(false);
但它只能按项目获取链接,我似乎找不到应用它的方法。

c# rest azure-devops
1个回答
0
投票

我可以使用此 REST API 来获取项目中具有

LinkType
Related
的工作项。这是一个c#示例供您参考。

using Newtonsoft.Json;
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Xml;
using Formatting = Newtonsoft.Json.Formatting;

namespace GetWIT
{
    class Program
    {
        static void Main()
        {
            string org = "OrgName";
            string project = "ProjectName";
            string personalAccessToken = "xxxxxx";
            string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken)));

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri($"https://dev.azure.com/{org}/{project}");

                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);

                //List Projects in a collection
                var linkType = "System.LinkTypes.Related";
                var startDateTime = "2024-04-30T07:00:00.00Z";

                HttpResponseMessage response = client.GetAsync($"_apis/wit/reporting/workitemlinks?linkTypes={linkType}&startDateTime={startDateTime}&api-version=7.1-preview.3").Result;

                response.EnsureSuccessStatusCode();

                string json = response.Content.ReadAsStringAsync().Result;
                dynamic parsedJson = JsonConvert.DeserializeObject(json);
                Console.WriteLine(JsonConvert.SerializeObject(parsedJson, Formatting.Indented));

            }
        }
    }
}

Image

© www.soinside.com 2019 - 2024. All rights reserved.