private void LoadMHTParser(string source) { using (new AutoWaitCursor()) { try { MHTStorageInfo info = m_wizardInfo.DataSourceParser.StorageInfo as MHTStorageInfo; m_wizardInfo.DataSourceParser.Dispose(); App.CallMethodInUISynchronizationContext(ClearFields, null); MHTStorageInfo newInfo = new MHTStorageInfo(source); newInfo.IsFirstLineTitle = info.IsFirstLineTitle; newInfo.IsFileNameTitle = info.IsFileNameTitle; m_wizardInfo.DataSourceParser = new MHTParser(newInfo); m_wizardInfo.DataSourceParser.ParseDataSourceFieldNames(); foreach (SourceField field in m_wizardInfo.DataSourceParser.StorageInfo.FieldNames) { App.CallMethodInUISynchronizationContext(AddField, field); } } catch (ArgumentException) { } } }
private void GetMHTFiles(string rootDirectory) { try { // First Iterating Files foreach (string mhtFile in Directory.GetFiles(rootDirectory)) { try { if (!IsMHTFolder) { MHTCount = 0; return; } if (IsMHTFile(mhtFile) && !Path.GetFileNameWithoutExtension(mhtFile).StartsWith("~", StringComparison.Ordinal)) { if (m_worker == null || (m_worker != null && m_worker.CancellationPending)) { return; } MHTStorageInfo info = new MHTStorageInfo(mhtFile); m_wizardInfo.DataStorageInfos.Add(info); MHTCount++; } } catch (FileFormatException) { } catch (UnauthorizedAccessException) { } catch (ArgumentException) { } } // Iterating Sub directories foreach (string directory in Directory.GetDirectories(rootDirectory)) { if (!IsMHTFolder) { MHTCount = 0; return; } if (m_worker == null || (m_worker != null && m_worker.CancellationPending)) { return; } GetMHTFiles(directory); } } catch (UnauthorizedAccessException) { MHTCount = 0; } catch (ArgumentException) { MHTCount = 0; } }
private void InitializeMHTDataSource(Dictionary <CommandLineSwitch, string> arguments) { WizardInfo.DataSourceType = DataSourceType.MHT; string sourcePath = arguments[CommandLineSwitch.SourcePath]; WizardInfo.DataStorageInfos = new List <IDataStorageInfo>(); if (File.Exists(sourcePath)) { if (String.CompareOrdinal(Path.GetExtension(sourcePath), ".txt") != 0) { throw new WorkItemMigratorException("MHT Source should be a text file", null, null); } using (var tw = new StreamReader(sourcePath)) { while (!tw.EndOfStream) { string mhtFilePath = tw.ReadLine(); try { var mhtInfo = new MHTStorageInfo(mhtFilePath); WizardInfo.DataStorageInfos.Add(mhtInfo); } catch (ArgumentException) { } } } } else if (Directory.Exists(sourcePath)) { foreach (string mhtFile in Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories)) { try { if (IsMHTFile(mhtFile) && !Path.GetFileNameWithoutExtension(mhtFile).StartsWith("~", StringComparison.Ordinal)) { MHTStorageInfo info = new MHTStorageInfo(mhtFile); WizardInfo.DataStorageInfos.Add(info); } } catch (FileFormatException) { } } } if (WizardInfo.DataStorageInfos.Count == 0) { throw new WorkItemMigratorException("MHT source is not having any valid mht file path", null, null); } WizardInfo.DataSourceParser = new MHTParser(WizardInfo.DataStorageInfos[0] as MHTStorageInfo); }
/// <summary> /// Is User have modifed the field mappings in FieldMappingPart? /// </summary> /// <param name="columnMappingRows"></param> /// <param name="isFirstLineTitle"></param> /// <param name="isFileNameTitle"></param> /// <returns></returns> public bool IsFieldMappingModified(ICollection <FieldMappingRow> columnMappingRows, bool isFirstLineTitle, bool isFileNameTitle) { if (m_dataSourceType == DataSourceType.Excel && (m_fieldMapping == null || m_fieldMapping.Count == 0)) { return(true); } if (m_dataSourceType == DataSourceType.MHT) { MHTStorageInfo info = m_wizardInfo.DataSourceParser.StorageInfo as MHTStorageInfo; if (info.IsFileNameTitle != isFileNameTitle || info.IsFirstLineTitle != isFirstLineTitle) { return(true); } } int fieldMappingCount = 0; foreach (var row in columnMappingRows) { if (row.WIField != null) { if (!m_fieldMapping.ContainsKey(row.DataSourceField) || String.CompareOrdinal(m_fieldMapping[row.DataSourceField], row.WIField.TfsName) != 0) { return(true); } fieldMappingCount++; } } if (m_dataSourceType == DataSourceType.MHT) { if (isFirstLineTitle || isFileNameTitle) { fieldMappingCount++; } } if (fieldMappingCount == m_fieldMapping.Count) { return(false); } else { return(true); } }
/// <summary> /// Constructor /// </summary> /// <param name="info"></param> public MHTParser(MHTStorageInfo info) { try { InitializeStorage(info); RawSourceWorkItems = new List <ISourceWorkItem>(); ParsedSourceWorkItems = new List <ISourceWorkItem>(); FieldNameToFields = new Dictionary <string, IWorkItemField>(); } catch (COMException) { throw new WorkItemMigratorException("Word is not installed", null, null); } }
/// <summary> /// Initializes the Storage Information /// </summary> /// <param name="info"></param> private void InitializeStorage(MHTStorageInfo info) { try { string newMHTFilePath = Path.GetTempFileName() + ".mht"; File.Copy(Path.GetFullPath(info.Source), newMHTFilePath); m_document = Application.Documents.Open(newMHTFilePath); m_isCopied = true; } catch (COMException) { throw new FileFormatException(); } Application.Visible = false; StorageInfo = info; }
private void LoadFieldNames(XmlElement node) { if (ProgressPart != null) { ProgressPart.Text = "Loading Field Names..."; } if (DataSourceType == DataSourceType.MHT) { if (node.Attributes.Count == 1 && String.CompareOrdinal(node.Attributes[0].Name, c_sampleFileAttributeTag) == 0 && File.Exists(node.Attributes[0].Value)) { DataSourceParser = new MHTParser(new MHTStorageInfo(node.Attributes[0].Value)); } DataSourceParser.ParseDataSourceFieldNames(); DataSourceParser.StorageInfo.FieldNames.Clear(); foreach (XmlElement fieldNode in node.ChildNodes) { if (String.CompareOrdinal(fieldNode.Name, c_fieldNodeTag) == 0 && fieldNode.Attributes.Count == 2 && String.CompareOrdinal(fieldNode.Attributes[0].Name, c_nameAttributeTag) == 0 && String.CompareOrdinal(fieldNode.Attributes[1].Name, c_canDeleteFieldNameAttributeTag) == 0) { string fieldName = fieldNode.Attributes[0].Value; bool canDelete = false; if (bool.TryParse(fieldNode.Attributes[1].Value, out canDelete)) { DataSourceParser.StorageInfo.FieldNames.Add(new SourceField(fieldName, canDelete)); } } else if (String.CompareOrdinal(fieldNode.Name, c_stepsFieldNodeTag) == 0 && fieldNode.Attributes.Count == 1 && String.CompareOrdinal(fieldNode.Attributes[0].Name, c_nameAttributeTag) == 0) { MHTStorageInfo info = DataSourceParser.StorageInfo as MHTStorageInfo; info.StepsField = fieldNode.Attributes[0].Value; } } } }
public bool AddFieldName(string fieldName) { if (!string.IsNullOrEmpty(fieldName)) { fieldName = fieldName.Trim(); MHTStorageInfo info = m_wizardInfo.DataSourceParser.StorageInfo as MHTStorageInfo; foreach (var field in Fields) { if (String.CompareOrdinal(field.FieldName, fieldName) == 0) { return(false); } } if (info.PossibleFieldNames.Contains(fieldName)) { App.CallMethodInUISynchronizationContext(AddField, new SourceField(fieldName, true)); return(true); } } return(false); }
/// <summary> /// Initializes the Data Source /// </summary> private void InitializeDataSource() { if (m_wizardInfo.DataSourceParser != null) { m_wizardInfo.DataSourceParser.Dispose(); } if (IsPreviewEnabled) { switch (DataSourceType) { case DataSourceType.Excel: ExcelStorageInfo xlInfo = new ExcelStorageInfo(ExcelFilePath); m_wizardInfo.DataSourceParser = new ExcelParser(xlInfo); break; case DataSourceType.MHT: string mhtFile = m_wizardInfo.DataStorageInfos[0].Source; foreach (IDataStorageInfo info in m_wizardInfo.DataStorageInfos) { DateTime mhtFileDateTime = File.GetLastWriteTime(mhtFile); DateTime currentFileDateTime = File.GetLastWriteTime(info.Source); if (mhtFileDateTime < currentFileDateTime) { mhtFile = info.Source; } } MHTStorageInfo mhtInfo = new MHTStorageInfo(mhtFile); m_wizardInfo.DataSourceParser = new MHTParser(mhtInfo); break; default: throw new InvalidEnumArgumentException("Invalid Enum Value"); } } }
/// <summary> /// Updates the Wizard part with current Configuration /// </summary> /// <returns>Is updation successful?</returns> public override bool UpdateWizardPart() { m_wizardInfo.DataSourceParser.StorageInfo.TestSuiteFieldName = null; if (String.CompareOrdinal(TestSuiteField, Resources.SelectPlaceholder) != 0) { m_wizardInfo.DataSourceParser.StorageInfo.TestSuiteFieldName = TestSuiteField; m_wizardInfo.RelationshipsInfo.TestSuiteField = TestSuiteField; } if (!IsUpdationRequired()) { return(true); } IDictionary <string, IWorkItemField> sourceNameToFieldMapping = new Dictionary <string, IWorkItemField>(); foreach (IWorkItemField field in m_wizardInfo.WorkItemGenerator.TfsNameToFieldMapping.Values) { field.SourceName = string.Empty; } // Filling the Field Mapping foreach (FieldMappingRow row in FieldMappingRows) { if (row.WIField != null) { IWorkItemField wiField = m_wizardInfo.WorkItemGenerator.TfsNameToFieldMapping[row.WIField.TfsName]; wiField.SourceName = row.DataSourceField; sourceNameToFieldMapping[row.DataSourceField] = wiField; if (wiField.IsStepsField && m_wizardInfo.DataSourceType == DataSourceType.MHT) { MHTStorageInfo info = m_wizardInfo.DataSourceParser.StorageInfo as MHTStorageInfo; info.StepsField = row.DataSourceField; } } } foreach (IWorkItemField field in m_wizardInfo.WorkItemGenerator.TfsNameToFieldMapping.Values) { if (m_wizardInfo.DataSourceType == DataSourceType.MHT && field.IsTitleField) { MHTStorageInfo info = m_wizardInfo.DataSourceParser.StorageInfo as MHTStorageInfo; info.IsFirstLineTitle = IsFirstLineTitle; info.IsFileNameTitle = IsFileNameTitle; if (IsFirstLineTitle || IsFileNameTitle) { field.SourceName = MHTParser.TestTitleDefaultTag; sourceNameToFieldMapping.Add(MHTParser.TestTitleDefaultTag, field); } else { info.TitleField = field.SourceName; } } } // finding out whether all mandatory fields are mapped or not foreach (IWorkItemField field in m_wizardInfo.WorkItemGenerator.TfsNameToFieldMapping.Values) { if (field.IsMandatory && !sourceNameToFieldMapping.ContainsKey(field.SourceName)) { Warning = Resources.MandatoryFieldsNotMappedErrorTitle; return(false); } } m_wizardInfo.Migrator.SourceNameToFieldMapping = sourceNameToFieldMapping; m_wizardInfo.DataSourceParser.FieldNameToFields = sourceNameToFieldMapping; m_wizardInfo.WorkItemGenerator.SourceNameToFieldMapping = sourceNameToFieldMapping; if (m_wizardInfo.Reporter != null) { m_wizardInfo.Reporter.Dispose(); } string reportDirectory = Path.Combine(Path.GetDirectoryName(m_wizardInfo.DataSourceParser.StorageInfo.Source), "Report" + DateTime.Now.ToString("g", System.Globalization.CultureInfo.CurrentCulture).Replace(":", "_").Replace(" ", "_").Replace("/", "_")); switch (m_wizardInfo.DataSourceType) { case DataSourceType.Excel: m_wizardInfo.Reporter = new ExcelReporter(m_wizardInfo); string fileNameWithoutExtension = "Report"; string fileExtension = Path.GetExtension(m_wizardInfo.DataSourceParser.StorageInfo.Source); m_wizardInfo.Reporter.ReportFile = Path.Combine(reportDirectory, fileNameWithoutExtension + fileExtension); break; case DataSourceType.MHT: m_wizardInfo.Reporter = new XMLReporter(m_wizardInfo); string fileName = "Report.xml";; m_wizardInfo.Reporter.ReportFile = Path.Combine(reportDirectory, fileName); break; default: throw new InvalidEnumArgumentException("Invalid data source type"); } int count = 0; m_wizardInfo.InitializeProgressView(); if (m_wizardInfo.ProgressPart != null) { m_wizardInfo.ProgressPart.Header = "Parsing..."; m_wizardInfo.ProgressPart.Header = "Initializing Parsing..."; } IList <ISourceWorkItem> sourceWorkItems = new List <ISourceWorkItem>(); IList <ISourceWorkItem> rawSourceWorkItems = new List <ISourceWorkItem>(); // Parse MHT DataSource Files if (m_wizardInfo.DataSourceType == DataSourceType.MHT) { MHTStorageInfo sampleInfo = m_wizardInfo.DataSourceParser.StorageInfo as MHTStorageInfo; IList <IDataStorageInfo> storageInfos = m_wizardInfo.DataStorageInfos; try { foreach (IDataStorageInfo storageInfo in storageInfos) { if (m_wizardInfo.ProgressPart == null) { break; } MHTStorageInfo info = storageInfo as MHTStorageInfo; info.IsFirstLineTitle = sampleInfo.IsFirstLineTitle; info.IsFileNameTitle = sampleInfo.IsFileNameTitle; info.TitleField = sampleInfo.TitleField; info.StepsField = sampleInfo.StepsField; IDataSourceParser parser = new MHTParser(info); parser.ParseDataSourceFieldNames(); info.FieldNames = sampleInfo.FieldNames; parser.FieldNameToFields = sourceNameToFieldMapping; while (parser.GetNextWorkItem() != null) { count++; if (m_wizardInfo.ProgressPart != null) { m_wizardInfo.ProgressPart.Text = "Parsing " + count + " of " + m_wizardInfo.DataStorageInfos.Count + ":\n" + info.Source; m_wizardInfo.ProgressPart.ProgressValue = (count * 100) / m_wizardInfo.DataStorageInfos.Count; } } for (int i = 0; i < parser.ParsedSourceWorkItems.Count; i++) { sourceWorkItems.Add(parser.ParsedSourceWorkItems[i]); rawSourceWorkItems.Add(parser.RawSourceWorkItems[i]); } parser.Dispose(); } } catch (WorkItemMigratorException te) { Warning = te.Args.Title; m_wizardInfo.ProgressPart = null; return(false); } } else if (m_wizardInfo.DataSourceType == DataSourceType.Excel) { var excelInfo = m_wizardInfo.DataSourceParser.StorageInfo as ExcelStorageInfo; m_wizardInfo.DataSourceParser.Dispose(); m_wizardInfo.DataSourceParser = new ExcelParser(excelInfo); m_wizardInfo.DataSourceParser.ParseDataSourceFieldNames(); m_wizardInfo.DataSourceParser.FieldNameToFields = sourceNameToFieldMapping; var parser = m_wizardInfo.DataSourceParser; while (parser.GetNextWorkItem() != null) { if (m_wizardInfo.ProgressPart == null) { break; } count++; m_wizardInfo.ProgressPart.ProgressValue = excelInfo.ProgressPercentage; m_wizardInfo.ProgressPart.Text = "Parsing work item# " + count; } for (int i = 0; i < parser.ParsedSourceWorkItems.Count; i++) { sourceWorkItems.Add(parser.ParsedSourceWorkItems[i]); rawSourceWorkItems.Add(parser.RawSourceWorkItems[i]); } } if (m_wizardInfo.ProgressPart != null) { m_wizardInfo.ProgressPart.Text = "Completing..."; m_wizardInfo.Migrator.RawSourceWorkItems = rawSourceWorkItems; m_wizardInfo.Migrator.SourceWorkItems = sourceWorkItems; } else { Warning = "Parsing is cancelled"; return(false); } m_wizardInfo.ProgressPart = null; m_prerequisite.Save(); return(true); }
/// <summary> /// Resets/ Updates the Field Mapping Wizard part /// </summary> public override void Reset() { m_mandatoryFields = new List <string>(); foreach (var field in WizardInfo.WorkItemGenerator.TfsNameToFieldMapping.Values) { if (field.IsMandatory) { m_mandatoryFields.Add(field.TfsName); } } IList <SourceField> fieldNames = m_wizardInfo.DataSourceParser.StorageInfo.FieldNames; // if Data Source is updated then clear all mapping rows and initialize them if (m_prerequisite.IsDataSourceChanged()) { IsFirstLineTitle = false; IsFileNameTitle = false; App.CallMethodInUISynchronizationContext(ClearFieldMappingRows, null); InitializeFieldMappingRows(m_wizardInfo.WorkItemGenerator.TfsNameToFieldMapping); } // if headers collection is not null if (fieldNames != null) { // then iterate throgh each header foreach (SourceField field in fieldNames) { // getting the Work item field IWorkItemField wiField = null; if (m_wizardInfo.Migrator.SourceNameToFieldMapping != null && m_wizardInfo.Migrator.SourceNameToFieldMapping.ContainsKey(field.FieldName)) { wiField = m_wizardInfo.Migrator.SourceNameToFieldMapping[field.FieldName]; } // Getting Field Mapping Row having data source field equal to header FieldMappingRow row = FieldMappingRows.FirstOrDefault((r) => { return(String.CompareOrdinal(r.DataSourceField, field.FieldName) == 0); }); if (row != null) { // If TFS is Updated then Update the allowed values of WorkitemField in Mapping Row if (m_prerequisite.IsServerConnectionChanged()) { row.ResetAvailableFields(m_wizardInfo.WorkItemGenerator.TfsNameToFieldMapping); } // Setting the Workitemfield in colum mapping row row.SetWorkItemField(wiField); } if (m_wizardInfo.DataSourceType == DataSourceType.MHT) { MHTStorageInfo info = m_wizardInfo.DataSourceParser.StorageInfo as MHTStorageInfo; IsFileNameTitle = info.IsFileNameTitle; IsFirstLineTitle = info.IsFirstLineTitle; } } } ResetTestSuiteFields(); NotifyPropertyChanged("IsTestSuiteVisible"); }
private void ParseDataSource() { IDictionary <string, IWorkItemField> sourceNameToFieldMapping = Migrator.SourceNameToFieldMapping; int count = 0; if (ProgressPart != null) { ProgressPart.Text = "Parsing Source..."; } Console.WriteLine("\nParsing Source...\n"); IList <ISourceWorkItem> sourceWorkItems = new List <ISourceWorkItem>(); IList <ISourceWorkItem> rawSourceWorkItems = new List <ISourceWorkItem>(); if (DataSourceType == DataSourceType.MHT) { MHTStorageInfo sampleInfo = DataSourceParser.StorageInfo as MHTStorageInfo; IList <IDataStorageInfo> storageInfos = DataStorageInfos; foreach (IDataStorageInfo storageInfo in storageInfos) { if (ProgressPart == null) { break; } MHTStorageInfo info = storageInfo as MHTStorageInfo; info.IsFirstLineTitle = sampleInfo.IsFirstLineTitle; info.IsFileNameTitle = sampleInfo.IsFileNameTitle; info.TitleField = sampleInfo.TitleField; info.StepsField = sampleInfo.StepsField; IDataSourceParser parser = new MHTParser(info); info.FieldNames = sampleInfo.FieldNames; parser.FieldNameToFields = sourceNameToFieldMapping; while (parser.GetNextWorkItem() != null) { count++; if (ProgressPart != null) { ProgressPart.Text = "Parsing " + count + " of " + DataStorageInfos.Count + ":\n" + info.Source; Console.Write("\r" + ProgressPart.Text); ProgressPart.ProgressValue = (count * 100) / DataStorageInfos.Count; } } for (int i = 0; i < parser.ParsedSourceWorkItems.Count; i++) { sourceWorkItems.Add(parser.ParsedSourceWorkItems[i]); rawSourceWorkItems.Add(parser.RawSourceWorkItems[i]); } parser.Dispose(); } } else if (DataSourceType == DataSourceType.Excel) { var parser = DataSourceParser; var excelInfo = parser.StorageInfo as ExcelStorageInfo; while (parser.GetNextWorkItem() != null) { if (ProgressPart == null) { break; } count++; ProgressPart.ProgressValue = excelInfo.ProgressPercentage; ProgressPart.Text = "Parsing work item # " + count; Console.Write("\r" + ProgressPart.Text); } for (int i = 0; i < parser.ParsedSourceWorkItems.Count; i++) { sourceWorkItems.Add(parser.ParsedSourceWorkItems[i]); rawSourceWorkItems.Add(parser.RawSourceWorkItems[i]); } } Migrator.RawSourceWorkItems = rawSourceWorkItems; Migrator.SourceWorkItems = sourceWorkItems; if (Reporter != null) { Reporter.Dispose(); } string reportDirectory = Path.Combine(Path.GetDirectoryName(DataSourceParser.StorageInfo.Source), "Report" + DateTime.Now.ToString("g", System.Globalization.CultureInfo.CurrentCulture). Replace(":", "_").Replace(" ", "_").Replace("/", "_")); switch (DataSourceType) { case DataSourceType.Excel: Reporter = new ExcelReporter(this); string fileNameWithoutExtension = "Report"; string fileExtension = Path.GetExtension(DataSourceParser.StorageInfo.Source); Reporter.ReportFile = Path.Combine(reportDirectory, fileNameWithoutExtension + fileExtension); break; case DataSourceType.MHT: Reporter = new XMLReporter(this); string fileName = "Report.xml";; Reporter.ReportFile = Path.Combine(reportDirectory, fileName); break; default: throw new InvalidEnumArgumentException("Invalid Data Source type"); } }
private void LoadFieldMappings(XmlElement root) { if (ProgressPart != null) { ProgressPart.Text = "Loading Field Mapping..."; } foreach (var kvp in WorkItemGenerator.TfsNameToFieldMapping) { kvp.Value.SourceName = string.Empty; } if (DataSourceType == DataSourceType.MHT && root.Attributes != null) { bool isFirstLineTitle = false; bool isFileNameTitle = false; foreach (XmlAttribute attribute in root.Attributes) { if (String.CompareOrdinal(attribute.Name, c_isFileNameTitleAttributeTag) == 0) { bool.TryParse(attribute.Value, out isFileNameTitle); } if (String.CompareOrdinal(attribute.Name, c_isFirstLineTitleAttributeTag) == 0) { bool.TryParse(attribute.Value, out isFirstLineTitle); } } if (isFileNameTitle ^ isFirstLineTitle) { MHTStorageInfo info = DataSourceParser.StorageInfo as MHTStorageInfo; info.TitleField = MHTParser.TestTitleDefaultTag; info.IsFileNameTitle = isFileNameTitle; info.IsFirstLineTitle = isFirstLineTitle; } } var sourceNameToFieldMapping = new Dictionary <string, IWorkItemField>(); foreach (XmlElement node in root.ChildNodes) { if (String.CompareOrdinal(node.Name, c_fieldMappingNodeTag) != 0) { throw new XmlException(); } string dataSourceField = UpdateLTGTChars(node.Attributes[c_dataSourceFieldNameAttributeTag].InnerXml); string wiField = UpdateLTGTChars(node.Attributes[c_wiFieldNameAttributeTag].InnerXml); if (string.IsNullOrEmpty(dataSourceField) || string.IsNullOrEmpty(wiField)) { throw new XmlException(); } if (WorkItemGenerator.TfsNameToFieldMapping.ContainsKey(wiField)) { WorkItemGenerator.TfsNameToFieldMapping[wiField].SourceName = dataSourceField; sourceNameToFieldMapping.Add(dataSourceField, WorkItemGenerator.TfsNameToFieldMapping[wiField]); } } DataSourceParser.FieldNameToFields = sourceNameToFieldMapping; WorkItemGenerator.SourceNameToFieldMapping = sourceNameToFieldMapping; Migrator.SourceNameToFieldMapping = sourceNameToFieldMapping; }
public void SaveSettings(string filePath) { if (string.IsNullOrEmpty(filePath)) { filePath = Path.Combine(Path.GetDirectoryName(Reporter.ReportFile), WorkItemGenerator.SelectedWorkItemTypeName + "-settings.xml"); } // Create XML Document XmlDocument xmlDocument = new XmlDocument(); XmlDeclaration dec = xmlDocument.CreateXmlDeclaration(XMLDeclarationVersion, null, null); xmlDocument.AppendChild(dec); //Creating Root Node XmlElement root = xmlDocument.CreateElement(c_rootNodeTag); // Appending the root node in the XML Documnet xmlDocument.AppendChild(root); if (DataSourceType == DataSourceType.MHT) { var fieldsRootNode = xmlDocument.CreateElement(c_fieldsRootNodeTag); foreach (SourceField field in DataSourceParser.StorageInfo.FieldNames) { var fieldNode = xmlDocument.CreateElement(c_fieldNodeTag); Utilities.AppendAttribute(fieldNode, c_nameAttributeTag, field.FieldName); Utilities.AppendAttribute(fieldNode, c_canDeleteFieldNameAttributeTag, field.CanDelete.ToString()); fieldsRootNode.AppendChild(fieldNode); } MHTStorageInfo info = DataSourceParser.StorageInfo as MHTStorageInfo; var stepsFieldNode = xmlDocument.CreateElement(c_stepsFieldNodeTag); Utilities.AppendAttribute(stepsFieldNode, c_nameAttributeTag, info.StepsField); fieldsRootNode.AppendChild(stepsFieldNode); Utilities.AppendAttribute(fieldsRootNode, c_sampleFileAttributeTag, SampleFileForFields); root.AppendChild(fieldsRootNode); } // Creating Field Mapping node XmlElement fieldMappingRootNode = xmlDocument.CreateElement(c_fieldMappingRootNodeTag); if (DataSourceType == DataSourceType.MHT) { MHTStorageInfo info = DataSourceParser.StorageInfo as MHTStorageInfo; Utilities.AppendAttribute(fieldMappingRootNode, c_isFileNameTitleAttributeTag, info.IsFileNameTitle.ToString()); Utilities.AppendAttribute(fieldMappingRootNode, c_isFirstLineTitleAttributeTag, info.IsFirstLineTitle.ToString()); } // Iterating through each fieid mapping and creating corresponding node foreach (var kvp in Migrator.SourceNameToFieldMapping) { // Creating Field Mapping Row Node XmlNode fieidMappingNode = xmlDocument.CreateElement(c_fieldMappingNodeTag); // Appending Data Source Field Attribute in the fieid mapping Row Node Utilities.AppendAttribute(fieidMappingNode, c_dataSourceFieldNameAttributeTag, kvp.Key); // Appending TFS Workiten Field Attribute in the fieid mapping Row Node Utilities.AppendAttribute(fieidMappingNode, c_wiFieldNameAttributeTag, kvp.Value.TfsName); // Appending Field Mapping Row Node in Field Mapping Node fieldMappingRootNode.AppendChild(fieidMappingNode); } // Appending Field Mapping node in the root node root.AppendChild(fieldMappingRootNode); // Creating RelationShips Node XmlElement relationshipsNode = xmlDocument.CreateElement(c_relationshipsNodeName); Utilities.AppendAttribute(relationshipsNode, c_isLinkingAttributeName, IsLinking.ToString()); if (RelationshipsInfo != null && !string.IsNullOrEmpty(RelationshipsInfo.SourceIdField)) { XmlElement sourceIDFieldNode = xmlDocument.CreateElement(c_sourceIdFieldNodeName); sourceIDFieldNode.InnerXml = RelationshipsInfo.SourceIdField; relationshipsNode.AppendChild(sourceIDFieldNode); if (!string.IsNullOrEmpty(RelationshipsInfo.TestSuiteField)) { XmlElement testSuitesFieldNode = xmlDocument.CreateElement(c_testSuiteFieldNodeName); testSuitesFieldNode.InnerXml = RelationshipsInfo.TestSuiteField; relationshipsNode.AppendChild(testSuitesFieldNode); } XmlElement linksRootNode = xmlDocument.CreateElement(c_linkTypesRootNodeName); foreach (ILinkRule linkTypeInfo in RelationshipsInfo.LinkRules) { XmlElement linkTypeInfoNode = xmlDocument.CreateElement(c_linkTypeNodeName); Utilities.AppendAttribute(linkTypeInfoNode, c_linkSourceFieldAttributeName, linkTypeInfo.SourceFieldNameOfEndWorkItemCategory); Utilities.AppendAttribute(linkTypeInfoNode, c_linkTypeNameAttributeName, linkTypeInfo.LinkTypeReferenceName); Utilities.AppendAttribute(linkTypeInfoNode, c_linkedWorkItemAttributeName, WorkItemGenerator.WorkItemCategoryToDefaultType[linkTypeInfo.EndWorkItemCategory]); Utilities.AppendAttribute(linkTypeInfoNode, c_descriptionAttributeName, linkTypeInfo.Description); linksRootNode.AppendChild(linkTypeInfoNode); } relationshipsNode.AppendChild(linksRootNode); } root.AppendChild(relationshipsNode); // Creating Data Mappping Node XmlElement dataMappingRootNode = xmlDocument.CreateElement(c_dataMappingRootNodeTag); Utilities.AppendAttribute(dataMappingRootNode, c_createAreaIterationPathAttribute, WorkItemGenerator.CreateAreaIterationPath.ToString()); // Iterating throw Data Mappings and Adding Each Data mapping entry into the DataMapping Node foreach (var sourceFieldNameToField in Migrator.SourceNameToFieldMapping) { // Iteration through Each Value Mapping for a Data Source Field foreach (KeyValuePair <string, string> valueMapping in sourceFieldNameToField.Value.ValueMapping) { // Creating data mapping row node XmlNode dataMappingNode = xmlDocument.CreateElement(c_dataMappingNodeTag); // Appending Data Source Field Attribute in the Data mapping Row Node Utilities.AppendAttribute(dataMappingNode, c_dataSourceFieldNameAttributeTag, sourceFieldNameToField.Key); // Appending Data Source Value Attribute in the Data mapping Row Node Utilities.AppendAttribute(dataMappingNode, c_dataSourceValueAttributeTag, valueMapping.Key); // Appending New Value Attribute in the Data mapping Row Node Utilities.AppendAttribute(dataMappingNode, c_newValueAttributeTag, valueMapping.Value); // Appending Data Mapping Row Node in Data Mapping Node dataMappingRootNode.AppendChild(dataMappingNode); } } // Appending Data Mapping Node in Root Node root.AppendChild(dataMappingRootNode); // Creating Parameterization Node XmlNode parameterizationNode = xmlDocument.CreateElement(c_parameterizationNode); Utilities.AppendAttribute(parameterizationNode, c_startParameterizationAttribute, DataSourceParser.StorageInfo.StartParameterizationDelimeter); Utilities.AppendAttribute(parameterizationNode, c_endParameterizationAttribute, DataSourceParser.StorageInfo.EndParameterizationDelimeter); root.AppendChild(parameterizationNode); XmlNode multiLineSenseNode = xmlDocument.CreateElement(c_multiLineSenseNode); multiLineSenseNode.InnerText = DataSourceParser.StorageInfo.IsMultilineSense.ToString(); root.AppendChild(multiLineSenseNode); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } // Writing XML Document in OutputSettingsFilePath using (StreamWriter tr = new StreamWriter(filePath)) { tr.Write(xmlDocument.OuterXml); } }