private Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType GetTfsWorkItemType(BoardMapping boardMapping, WorkItemTypeCollection workItemTypes, long cardTypeId)
 {
     if (boardMapping != null &&
         boardMapping.Types != null &&
         boardMapping.ValidCardTypes != null &&
         boardMapping.Types.Any() &&
         boardMapping.ValidCardTypes.Any())
     {
         var lkType = boardMapping.ValidCardTypes.FirstOrDefault(x => x.Id == cardTypeId);
         if (lkType != null)
         {
             // first check for mapped type
             var mappedType = boardMapping.Types.FirstOrDefault(x => x.LeanKit.ToLowerInvariant() == lkType.Name.ToLowerInvariant());
             if (mappedType != null)
             {
                 if (workItemTypes.Contains(mappedType.Target))
                 {
                     return(workItemTypes[mappedType.Target]);
                 }
             }
             // now check for implicit type
             if (workItemTypes.Contains(lkType.Name))
             {
                 return(workItemTypes[lkType.Name]);
             }
         }
     }
     // else just return the first type from list of types from TFS
     return(workItemTypes[0]);
 }
Exemple #2
0
        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);
        }
        internal List <string> GetWorkItemFields(string wiTypeName, string wiFieldType = "")
        {
            List <string> lst    = new List <string>();
            WorkItemType  wiType = wiTypes[0];

            if (wiTypes.Contains(wiTypeName))
            {
                wiType = wiTypes[wiTypeName];
            }

            foreach (FieldDefinition fld in wiType.FieldDefinitions)
            {
                if (wiFieldType == string.Empty || wiFieldType == fld.FieldType.ToString())
                {
                    lst.Add(fld.ReferenceName);
                }
            }

            return(lst);
        }
        public static WorkItemTypeMap MapTypes(TfsProject source, TfsProject target)
        {
            WorkItemTypeCollection workItemTypes = target.project.WorkItemTypes;
            WorkItemTypeMap        fieldMap      = new WorkItemTypeMap();

            foreach (WorkItemType workItemTypeSource in source.project.WorkItemTypes)
            {
                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 == "User Story")
                {
                    workItemTypeTarget = workItemTypes["Product Backlog Item"];
                }
                else if (workItemTypeSource.Name == "Issue")
                {
                    workItemTypeTarget = workItemTypes["Impediment"];
                }
                else
                {
                    // not automatically mapped
                    continue;
                }

                WorkItemFieldMap m = new WorkItemFieldMap(workItemTypeSource, workItemTypeTarget);
                m.GenerateDefaultMap();
                fieldMap.fieldMapping.Add(m);
                fieldMap.mapping[workItemTypeSource] = workItemTypeTarget;
            }

            return(fieldMap);
        }
Exemple #5
0
        /* Copy work items to project from work item collection */
        public void writeWorkItems(WorkItemStore sourceStore, WorkItemCollection workItemCollection, string sourceProjectName, ProgressBar ProgressBar, Hashtable fieldMapAll)
        {
            ReadItemMap(sourceProjectName);
            int             i        = 1;
            List <WorkItem> newItems = new List <WorkItem>();

            foreach (WorkItem workItem in workItemCollection)
            {
                if (itemMap.ContainsKey(workItem.Id))
                {
                    continue;
                }

                WorkItem  newWorkItem = null;
                Hashtable fieldMap    = ListToTable((List <object>)fieldMapAll[workItem.Type.Name]);
                if (workItemTypes.Contains(workItem.Type.Name))
                {
                    newWorkItem = new WorkItem(workItemTypes[workItem.Type.Name]);
                }
                else if (workItem.Type.Name == "User Story")
                {
                    newWorkItem = new WorkItem(workItemTypes["Product Backlog Item"]);
                }
                else if (workItem.Type.Name == "Issue")
                {
                    newWorkItem = new WorkItem(workItemTypes["Impediment"]);
                }

                else
                {
                    logger.Info(String.Format("Work Item Type {0} does not exist in target TFS", workItem.Type.Name));
                    continue;
                }

                /* assign relevent fields*/
                foreach (Field field in workItem.Fields)
                {
                    if (field.Name.Contains("ID") || field.Name.Contains("State") || field.Name.Contains("Reason"))
                    {
                        continue;
                    }

                    if (newWorkItem.Fields.Contains(field.Name) && newWorkItem.Fields[field.Name].IsEditable)
                    {
                        newWorkItem.Fields[field.Name].Value = field.Value;
                        if (field.Name == "Iteration Path" || field.Name == "Area Path" || field.Name == "Node Name" || field.Name == "Team Project")
                        {
                            try
                            {
                                string itPath    = (string)field.Value;
                                int    length    = sourceProjectName.Length;
                                string itPathNew = destinationProject.Name + itPath.Substring(length);
                                newWorkItem.Fields[field.Name].Value = itPathNew;
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    //Add values to mapped fields
                    else if (fieldMap.ContainsKey(field.Name))
                    {
                        newWorkItem.Fields[(string)fieldMap[field.Name]].Value = field.Value;
                    }
                }

                /* Validate Item Before Save*/
                ArrayList array = newWorkItem.Validate();
                foreach (Field item in array)
                {
                    logger.Info(String.Format("Work item {0} Validation Error in field: {1}  : {2}", workItem.Id, item.Name, newWorkItem.Fields[item.Name].Value));
                }
                //if work item is valid
                if (array.Count == 0)
                {
                    UploadAttachments(newWorkItem, workItem);
                    newWorkItem.Save();
                    itemMap.Add(workItem.Id, newWorkItem.Id);
                    newItems.Add(workItem);
                    //update workitem status
                    updateToLatestStatus(workItem, newWorkItem);
                }
                else
                {
                    logger.Info(String.Format("Work item {0} could not be saved", workItem.Id));
                }

                ProgressBar.Dispatcher.BeginInvoke(new Action(delegate()
                {
                    float progress    = (float)i / (float)workItemCollection.Count;
                    ProgressBar.Value = ((float)i / (float)workItemCollection.Count) * 100;
                }));
                i++;
            }

            WriteMaptoFile(sourceProjectName);
            CreateLinks(newItems, sourceStore);
        }
		private Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType GetTfsWorkItemType(BoardMapping boardMapping, WorkItemTypeCollection workItemTypes, long cardTypeId)
		{			
			if (boardMapping != null && 
				boardMapping.Types != null && 
				boardMapping.ValidCardTypes != null && 
				boardMapping.Types.Any() && 
				boardMapping.ValidCardTypes.Any() )
			{				
				var lkType = boardMapping.ValidCardTypes.FirstOrDefault(x => x.Id == cardTypeId);
				if (lkType != null)
				{
					// first check for mapped type
					var mappedType = boardMapping.Types.FirstOrDefault(x => x.LeanKit.ToLowerInvariant() == lkType.Name.ToLowerInvariant());
					if (mappedType != null) 
					{
						if (workItemTypes.Contains(mappedType.Target))
							return workItemTypes[mappedType.Target];
					}
					// now check for implicit type
					if (workItemTypes.Contains(lkType.Name))
						return workItemTypes[lkType.Name];
				}

			}
			// else just return the first type from list of types from TFS
			return workItemTypes[0];
		}
Exemple #7
0
        /* Copy work items to project from work item collection */
        public void writeWorkItems(WorkItemStore sourceStore, WorkItemCollection workItemCollection, string sourceProjectName, ProgressBar ProgressBar, Hashtable fieldMapAll)
        {
            ReadItemMap(sourceProjectName);
            int             i        = 1;
            List <WorkItem> newItems = new List <WorkItem>();

            foreach (WorkItem workItem in workItemCollection)
            {
                if (itemMap.ContainsKey(workItem.Id))
                {
                    logger.Info("RK: skipping already imported work item #" + workItem.Id);
                    continue;
                }

                WorkItem  newWorkItem = null;
                Hashtable fieldMap    = ListToTable((List <object>)fieldMapAll[workItem.Type.Name]);
                if (workItem.Type.Name == "User Story")
                {
                    logger.Info("RK: changed workitem #" + workItem.Id + " to product backlog item");
                    newWorkItem = new WorkItem(workItemTypes["Product Backlog Item"]);
                }
                else if (workItem.Type.Name == "Issue")
                {
                    logger.Info("RK: changed workitem #" + workItem.Id + " to impediment");
                    newWorkItem = new WorkItem(workItemTypes["Impediment"]);
                }
                else if (workItemTypes.Contains(workItem.Type.Name))
                {
                    newWorkItem = new WorkItem(workItemTypes[workItem.Type.Name]);
                }
                else
                {
                    logger.Info(String.Format("Work Item Type {0} does not exist in target TFS", workItem.Type.Name));
                    continue;
                }

                /* assign relevent fields*/
                foreach (Field field in workItem.Fields)
                {
                    if (field.Name.Contains("ID") || field.Name.Contains("State") || field.Name.Contains("Reason"))
                    {
                        continue;
                    }

                    if (newWorkItem.Fields.Contains(field.Name) && newWorkItem.Fields[field.Name].IsEditable)
                    {
                        newWorkItem.Fields[field.Name].Value = field.Value;
                        if (field.Name == "Iteration Path" || field.Name == "Area Path" || field.Name == "Node Name" || field.Name == "Team Project")
                        {
                            try
                            {
                                string itPath    = (string)field.Value;
                                int    length    = sourceProjectName.Length;
                                string itPathNew = destinationProject.Name + itPath.Substring(length);
                                newWorkItem.Fields[field.Name].Value = itPathNew;
                                logger.Info("RK: updated " + field.Name + " from " + field.Value + " to " + itPathNew + " for workitem #" + workItem.Id);
                            }
                            catch (Exception ex)
                            {
                                logger.Info("RK: exception during path mapping: " + ex);
                            }
                        }
                    }
                    //Add values to mapped fields
                    else if (fieldMap.ContainsKey(field.Name))
                    {
                        logger.Info("RK: workitem #" + workItem.Id + " field " + field.Name + " mapped to " + fieldMap[field.Name]);
                        newWorkItem.Fields[(string)fieldMap[field.Name]].Value = field.Value;
                    }
                    else
                    {
                        logger.Info("RK: unknown field " + field.Name + " for work item #" + workItem.Id);
                    }
                }

                /* Validate Item Before Save*/
                ArrayList array = newWorkItem.Validate();
                foreach (Field item in array)
                {
                    logger.Info(String.Format("Work item {0} Validation Error in field: {1}  : {2} - {3}", workItem.Id, item.Name, newWorkItem.Fields[item.Name].Value, item.Status));
                }
                //if work item is valid
                if (array.Count == 0)
                {
                    SaveWorkItemFinal(newItems, workItem, newWorkItem);
                }
                else
                {
                    foreach (Field field in array)
                    {
                        logger.Info("RK: Setting null to field " + field.Name + " on work item #" + newWorkItem.Id + " (old #" + workItem.Id);
                        newWorkItem.Fields[field.Name].Value = null;
                    }
                    array = newWorkItem.Validate();
                    foreach (Field item in array)
                    {
                        logger.Info(String.Format("Work item {0} Validation Error2 in field: {1}  : {2} - {3}", workItem.Id, item.Name, newWorkItem.Fields[item.Name].Value, item.Status));
                    }

                    if (array.Count != 0)
                    {
                        logger.Info(String.Format("Work item {0} could not be saved", workItem.Id));
                    }
                    else
                    {
                        SaveWorkItemFinal(newItems, workItem, newWorkItem);
                    }
                }

                ProgressBar.Dispatcher.BeginInvoke(new Action(delegate()
                {
                    float progress    = (float)i / (float)workItemCollection.Count;
                    ProgressBar.Value = ((float)i / (float)workItemCollection.Count) * 100;
                }));
                i++;
            }

            WriteMaptoFile(sourceProjectName);
            CreateLinks(newItems, sourceStore);
        }
        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.Error("Error Replacing work flow");
                        error = error + "Error Replacing work flow for " + (string)list[0] + ":" + ex.Message + "\n";
                    }
                }
            }
            return error;
        }