API TFS - est-il un moyen d'obtenir une liste des transitions pour un type de workitem?

StackOverflow https://stackoverflow.com/questions/2203506

  •  18-09-2019
  •  | 
  •  

Question

Je suis en train de faire de l'État "A" à l'état "X".

Il y a des transitions en place qui me empêchent de juste aller à X.

Je peux exporter le WORKITEMTYPE comme XML et travailler là-dessus, mais avant de le faire, je pensais que je demande s'il y a un moyen d'obtenir les transitions via l'API.

Était-ce utile?

La solution

Soooo .....

Peu de gens ont besoin des transitions pour WorkItemTypes.

Eh bien, je avais besoin donc je l'ai écrit une méthode pour le faire. Ici, il est au cas où quelqu'un d'autre a besoin jamais ceci:

// 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; }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top