【问题标题】:TFS API - is there a way to get a list of the transitions for a workitem type?TFS API - 有没有办法获取工作项类型的转换列表?
【发布时间】:2011-01-13 07:04:48
【问题描述】:

我正在尝试从状态“A”到状态“X”。

有一些转换阻止我去 X。

我可以将 WorkItemType 导出为 XML 并进行处理,但在此之前,我想我会问是否有办法通过 API 获取转换。

【问题讨论】:

    标签: c# tfs tfs-sdk


    【解决方案1】:

    呜呜呜……

    没有多少人需要 WorkItemTypes 的转换。

    嗯,我需要它,所以我写了一个方法来做到这一点。这是以防其他人需要这个:

    // 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; }
    }
    

    【讨论】:

    • 我想获取所有状态而不是转换,这也非常适合。非常感谢。
    猜你喜欢
    • 2010-09-19
    • 1970-01-01
    • 2018-07-20
    • 2014-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多