/// <summary> /// Creates Workitem from Source Workitem /// </summary> /// <param name="sourceWorkItem"></param> /// <returns></returns> public IWorkItem CreateWorkItem(ISourceWorkItem sourceWorkItem) { if (sourceWorkItem == null) { throw new ArgumentNullException("sourceWorkItem", "source work item"); } // Initializing the variables IWorkItem workItem = null; // Initializing the Workitem switch (WorkItemTypeToCategoryMapping[SelectedWorkItemTypeName]) { case TestCaseCategory: TestCase testCase = new TestCase(m_teamProject, SelectedWorkItemTypeName, IsTFS2012); workItem = testCase; break; default: workItem = new WorkItemBase(m_teamProject.WitProject, SelectedWorkItemTypeName); break; } workItem.Create(); // iterating through each field-value pair foreach (KeyValuePair <string, object> kvp in sourceWorkItem.FieldValuePairs) { // Refernce Name of the field which is to be updated string fieldName = kvp.Key; // value of the field which has to assigned object fieldValue = kvp.Value; // Gets the correct field reference name if (SourceNameToFieldMapping.ContainsKey(kvp.Key)) { fieldName = SourceNameToFieldMapping[kvp.Key].TfsName; if (CreateAreaIterationPath && SourceNameToFieldMapping[kvp.Key].IsAreaPath) { // Create area path if it does not already exist. fieldValue = m_areaAndIterationPathCreator.Create(Node.TreeType.Area, fieldValue as string); SourceNameToFieldMapping[kvp.Key].ValueMapping.Clear(); } if (CreateAreaIterationPath && SourceNameToFieldMapping[kvp.Key].IsIterationPath) { // Create area path if it does not already exist. fieldValue = m_areaAndIterationPathCreator.Create(Node.TreeType.Iteration, fieldValue as string); SourceNameToFieldMapping[kvp.Key].ValueMapping.Clear(); } // If it is autogenerated value then just ignore the assignment of value and continue to next iteration if (SourceNameToFieldMapping[kvp.Key].IsAutoGenerated) { continue; } } string value = kvp.Value as string; // value to assign is of type string and it is not null if (value != null) { // If this value is dataMapped if (SourceNameToFieldMapping.ContainsKey(kvp.Key) && SourceNameToFieldMapping[kvp.Key].ValueMapping.ContainsKey(value)) { if (String.Compare(SourceNameToFieldMapping[kvp.Key].ValueMapping[value], Resources.IgnoreLabel, StringComparison.CurrentCulture) == 0) { continue; } else { // else sets the correct data value fieldValue = SourceNameToFieldMapping[kvp.Key].ValueMapping[value]; } } } // Update the workitem with field-value workItem.UpdateField(fieldName, fieldValue); } // return the workitem return(workItem); }