TFS API - 是有没有办法得到一个工作项类型的转换列表? [英] TFS API - is there a way to get a list of the transitions for a workitem type?

查看:129
本文介绍了TFS API - 是有没有办法得到一个工作项类型的转换列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从国家A到国家X就搞定了。

I am trying to get from State "A" to State "X".

有到位跃迁防止我只是要X.

There are transitions in place that prevent me from just going to X.

我可以导出WorkItemType XML和工作有关的,但在此之前我这样做,我想我会问,如果有一种方法通过API的转换来获得。

I can export the WorkItemType as XML and work on that, but before I do that, I thought I would ask if there is a way to get at the Transitions via the API.

推荐答案

SOOOO .....

Soooo.....

没有多少人需要过渡为WorkItemTypes。

Not many people need the transitions for WorkItemTypes.

好吧,我需要它,所以我写了这样做的方法。这是以防别人以往任何时候都需要这样的:

Well, I needed it so I wrote a method to do it. Here it is in case someone else ever needs this:

// Hold a list of all the transistions we have done.  This will help us not have run them again If we already have.
private static Dictionary<WorkItemType, List<Transition>> _allTransistions = new Dictionary<WorkItemType, List<Transition>>();

/// <summary>
/// Get the transitions for this <see cref="WorkItemType"/>
/// </summary>
/// <param name="workItemType"></param>
/// <returns></returns>
private static List<Transition> GetTransistions(this WorkItemType workItemType)
{
    List<Transition> currentTransistions;

    // See if this WorkItemType has already had it's transistions figured out.
    _allTransistions.TryGetValue(workItemType, out currentTransistions);
    if (currentTransistions != null)
        return currentTransistions;

    // Get this worktype type as xml
    XmlDocument workItemTypeXml = workItemType.Export(false);

    // Create a dictionary to allow us to look up the "to" state using a "from" state.
    var newTransistions = new List<Transition>();

    // get the transistions node.
    XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS");

    // As there is only one transistions item we can just get the first
    XmlNode transitions = transitionsList[0];

    // Iterate all the transitions
    foreach (XmlNode transition in transitions)
    {
        // save off the transistion 
        newTransistions.Add(new Transition
                                {
                                    From = transition.Attributes["from"].Value,
                                    To = transition.Attributes["to"].Value
                                });

    }

    // Save off this transition so we don't do it again if it is needed.
    _allTransistions.Add(workItemType, newTransistions);

    return newTransistions;
}

public class Transition
{
    public string To { get; set; }
    public string From { get; set; }
}

这篇关于TFS API - 是有没有办法得到一个工作项类型的转换列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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