/* Compare work item type definitions and add fields from source work item types and replace workflow */ public void SetFieldDefinitions(WorkItemTypeCollection workItemTypesSource, Hashtable fieldList) { foreach (WorkItemType workItemTypeSource in workItemTypesSource) { WorkItemType workItemTypeTarget = null; if (workItemTypeSource.Name == "User Story") { workItemTypeTarget = workItemTypes["Product Backlog Item"]; } else if (workItemTypeSource.Name == "Issue") { workItemTypeTarget = workItemTypes["Impediment"]; } else { workItemTypeTarget = workItemTypes[workItemTypeSource.Name]; } XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false); XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false); workItemTypeXmlTarget = AddNewFields(workItemTypeXmlSource, workItemTypeXmlTarget, (List <object>)fieldList[workItemTypeTarget.Name]); try { WorkItemType.Validate(store.Projects[projectName], workItemTypeXmlTarget.InnerXml); store.Projects[projectName].WorkItemTypes.Import(workItemTypeXmlTarget.InnerXml); } catch (XmlException) { logger.Info("XML import falied for " + workItemTypeSource.Name); } } }
public string ReplaceWorkFlow(WorkItemTypeCollection workItemTypesSource, List <object> fieldList) { string error = ""; for (int i = 0; i < fieldList.Count; i++) { object[] list = (object[])fieldList[i]; if ((bool)list[1]) { WorkItemType workItemTypeTarget = workItemTypes[(string)list[0]]; WorkItemType workItemTypeSource = null; if (workItemTypesSource.Contains((string)list[0])) { workItemTypeSource = workItemTypesSource[(string)list[0]]; } else if (workItemTypeTarget.Name == "Product Backlog Item") { workItemTypeSource = workItemTypesSource["User Story"]; } else if (workItemTypeTarget.Name == "Impediment") { workItemTypeSource = workItemTypesSource["Issue"]; } XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false); XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false); XmlNodeList transitionsListSource = workItemTypeXmlSource.GetElementsByTagName("WORKFLOW"); XmlNode transitions = transitionsListSource[0]; XmlNodeList transitionsListTarget = workItemTypeXmlTarget.GetElementsByTagName("WORKFLOW"); XmlNode transitionsTarget = transitionsListTarget[0]; string defTarget = ""; try { string def = workItemTypeXmlTarget.InnerXml; string workflowSource = transitions.OuterXml; string workflowTarget = transitionsTarget.OuterXml; defTarget = def.Replace(workflowTarget, workflowSource); WorkItemType.Validate(store.Projects[projectName], defTarget); store.Projects[projectName].WorkItemTypes.Import(defTarget); fieldList.Remove(list); i--; } catch (Exception ex) { logger.Info("Error Replacing work flow"); error = error + "Error Replacing work flow for " + (string)list[0] + ":" + ex.Message + "\n"; } } } return(error); }
public WorkItemEditorForm(WorkItemType workItemType, WorkItem workItem) { InitializeComponent(); frmWorkItemControl = new WorkItemFormControl(); XmlDocument xmlDocument = workItemType.Export(false); frmWorkItemControl.FormDefinition = xmlDocument.InnerXml; frmWorkItemControl.Dock = DockStyle.Fill; frmWorkItemControl.Item = workItem; this.Controls.Add(frmWorkItemControl); frmWorkItemControl.BringToFront(); }
/// <summary> /// Deprecated /// Get the transitions for this <see cref="WorkItemType"/> /// </summary> /// <param name="workItemType"></param> /// <returns></returns> public static List <Transition> GetTransitions(this WorkItemType workItemType) { List <Transition> currentTransistions; // See if this WorkItemType has already had it's transitions 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 transitions node. XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS"); // As there is only one transitions item we can just get the first XmlNode transitions = transitionsList[0]; // Iterate all the transitions foreach (XmlNode transitionXML in transitions) { // See if we have this from state already. string fromState = transitionXML.Attributes["from"].Value; Transition transition = newTransistions.Find(trans => trans.From == fromState); if (transition != null) { transition.To.Add(transitionXML.Attributes["to"].Value); } // If we could not find this state already then add it. else { // save off the transition (from first so we can look up state progression. newTransistions.Add(new Transition { From = transitionXML.Attributes["from"].Value, To = new List <string> { transitionXML.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 WorkItemState(WorkItemType wit) { this.wit = wit; selectedInProgressState = selectedApprovedState = initialState = wit.NewWorkItem().State; closedStates = new List <string> { "Done", "Inactive", "Closed", "Completed", "Rejected", "Removed" }; witd = wit.Export(true); gatherNextStates(); findDonePath(); }
/// <summary> /// Fill Allowed States at Creation time in Allowed Values /// </summary> /// <param name="wi"></param> private void FillAllowedStatesAtCreationTime(WorkItem wi) { //HasAllowedValues = true; AllowedValues = new List <string>(); WorkItemType wit = wi.Type; XmlDocument witd = wit.Export(true); // retrieve the transitions node XmlNode transitionsNode = witd.SelectSingleNode("descendant::TRANSITIONS"); if (transitionsNode != null) { // Get all the state TRANSITION nodes from the WIT template. XmlNodeList transitionNodes = transitionsNode.SelectNodes("TRANSITION"); if (transitionNodes != null) { // Iterate all the possible transitions and filter those that are valid // transitions from our current state. foreach (XmlNode transitionNode in transitionNodes) { // Get the FROM and TO attributes from the transisitiion node. XmlNode fromAttribute = transitionNode.Attributes.GetNamedItem("from"); XmlNode toAttribute = transitionNode.Attributes.GetNamedItem("to"); if (fromAttribute != null) { // Add this transition to the list of valid transitions if it is a // transition from our current state. string fromValue = fromAttribute.Value; if (string.IsNullOrWhiteSpace(fromValue) && toAttribute != null) { AllowedValues.Add(toAttribute.Value); } } } } } }
public static List <Transition> GetTransistions(this WorkItemType workItemType) { List <Transition> currentTransistions; AllTransistions.TryGetValue(workItemType, out currentTransistions); if (currentTransistions != null) { return(currentTransistions); } XmlDocument workItemTypeXml = workItemType.Export(false); XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS"); XmlNode transitions = transitionsList[0]; var newTransistions = (from XmlNode transition in transitions select new Transition { From = transition.Attributes["from"].Value, To = transition.Attributes["to"].Value }).ToList(); AllTransistions.Add(workItemType, newTransistions); return(newTransistions); }
private List <string> GetStatesForWorkItemType(WorkItemType workItemType) { List <string> states = new List <string>(); // get Work Item type definition XmlDocument witd = workItemType.Export(true); // retrieve the transitions node XmlNode statesNode = witd.SelectSingleNode("descendant::STATES"); // for each state definition (== possible next allowed state) if (statesNode != null) { var nodes = statesNode.SelectNodes("STATE"); if (nodes != null) { foreach (XmlNode stateNode in nodes) { string value = stateNode.Attributes.GetNamedItem("value").Value; states.Add(value); } } } return(states); }
public Hashtable MapFields(WorkItemTypeCollection workItemTypesSource) { Hashtable fieldMap = new Hashtable(); foreach (WorkItemType workItemTypeSource in workItemTypesSource) { List <List <string> > fieldList = new List <List <string> >(); List <string> sourceList = new List <string>(); List <string> targetList = new List <string>(); WorkItemType workItemTypeTarget = null; if (workItemTypes.Contains(workItemTypeSource.Name)) { workItemTypeTarget = workItemTypes[workItemTypeSource.Name]; } else if (workItemTypeSource.Name == "Issue") { workItemTypeTarget = workItemTypes["Impediment"]; } else if (workItemTypeSource.Name == "User Story") { workItemTypeTarget = workItemTypes["Product Backlog Item"]; } else { continue; } XmlDocument workItemTypeXmlSource = workItemTypeSource.Export(false); XmlDocument workItemTypeXmlTarget = workItemTypeTarget.Export(false); XmlNodeList fieldListSource = workItemTypeXmlSource.GetElementsByTagName("FIELD"); XmlNodeList fieldListTarget = workItemTypeXmlTarget.GetElementsByTagName("FIELD"); foreach (XmlNode field in fieldListSource) { if (field.Attributes["name"] != null) { XmlNodeList tempList = workItemTypeXmlTarget.SelectNodes("//FIELD[@name='" + field.Attributes["name"].Value + "']"); if (tempList.Count == 0) { sourceList.Add(field.Attributes["name"].Value); } } } fieldList.Add(sourceList); foreach (XmlNode field in fieldListTarget) { if (field.Attributes["name"] != null) { XmlNodeList tempList = workItemTypeXmlSource.SelectNodes("//FIELD[@name='" + field.Attributes["name"].Value + "']"); if (tempList.Count == 0) { targetList.Add(field.Attributes["name"].Value); } } } fieldList.Add(targetList); fieldMap.Add(workItemTypeTarget.Name, fieldList); } return(fieldMap); }