/// <summary> /// Update Allowed Values of Data Mapping Row if TFS connection is modified /// </summary> /// <param name="wiField"></param> public void UpdateAllowedValues(IWorkItemField wiField) { if (wiField != m_wiField) { m_wiField = wiField; FillAllowedValues(); NewValue = null; } }
/// <summary> /// Resets the Data mapping Wizard Part /// </summary> public override void Reset() { //Clears Data Mapping Rows App.CallMethodInUISynchronizationContext(ClearDataMappingRows, null); // Add Data Mapping Row's Header App.CallMethodInUISynchronizationContext(AddDataMappingRow, new HeaderDataMappingRow()); // Parsing the DataSource. It will return list of allowed values m_dataValuesByFieldName = new Dictionary <string, IList <string> >(); IsCreateAreaIterationPathVisible = false; foreach (var kvp in m_wizardInfo.Migrator.SourceNameToFieldMapping) { if (kvp.Value.HasAllowedValues && m_wizardInfo.Migrator.FieldToUniqueValues.ContainsKey(kvp.Key)) { m_dataValuesByFieldName.Add(kvp.Key, m_wizardInfo.Migrator.FieldToUniqueValues[kvp.Key]); } if (kvp.Value.IsAreaPath || kvp.Value.IsIterationPath) { IsCreateAreaIterationPathVisible = true; } } // Filling the data mapping rows foreach (KeyValuePair <string, IList <string> > dataValuesbyFieldName in m_dataValuesByFieldName) { string dataSourceFieldName = dataValuesbyFieldName.Key; IWorkItemField workItemField = m_wizardInfo.Migrator.SourceNameToFieldMapping[dataSourceFieldName]; if (workItemField.HasAllowedValues) { foreach (string dataSourceValue in dataValuesbyFieldName.Value) { string newValue = string.Empty; if (workItemField.ValueMapping.ContainsKey(dataSourceValue)) { newValue = workItemField.ValueMapping[dataSourceValue]; } DataMappingRow dataMappingRow = new DataMappingRow(m_wizardInfo, dataSourceFieldName, dataSourceValue, newValue); App.CallMethodInUISynchronizationContext(AddDataMappingRow, dataMappingRow); } } } App.CallMethodInUISynchronizationContext(AddDataMappingRow, new BlankDataMappingRow()); CreateAreaIterationPath = m_wizardInfo.WorkItemGenerator.CreateAreaIterationPath; }
/// <summary> /// Constructor /// </summary> /// <param name="dataSourceField"></param> /// <param name="wiField"></param> /// <param name="workItemFieldByFieldName"></param> public FieldMappingRow(string dataSourceField, IWorkItemField wiField, IDictionary <string, IWorkItemField> workItemFieldByFieldName, bool isMultipleHistoryMappingMode) { DataSourceField = dataSourceField; PreviousTFSField = Resources.IgnoreLabel; AvailableTFSFields = new ObservableCollection <string>(); ResetAvailableFields(workItemFieldByFieldName); m_field = new DisplayWorkItemField(wiField); m_isMultipleHistoryMappingMode = isMultipleHistoryMappingMode; if (wiField == null && m_isMultipleHistoryMappingMode) { foreach (var field in m_workItemFieldByFieldName.Values) { if (field.WIField.IsHtmlField) { TFSField = field.DisplayedName; } } } }
/// <summary> /// The Wizard part state will always be true /// </summary> /// <returns></returns> public override bool ValidatePartState() { Warning = null; if (m_mandatoryFields == null) { Warning = Resources.MandatoryFieldsNotMappedErrorTitle; return(false); } int count = 0; foreach (var row in FieldMappingRows) { if (row.IsValidFieldMapping && m_mandatoryFields.Contains(row.WIField.TfsName)) { count++; } } IWorkItemField titleField = null; foreach (var field in WizardInfo.WorkItemGenerator.TfsNameToFieldMapping.Values) { if (field.IsTitleField) { titleField = field; break; } } if (titleField != null && titleField.IsMandatory && (IsFileNameTitle || IsFirstLineTitle)) { count++; } if (m_mandatoryFields.Count != count) { Warning = Resources.MandatoryFieldsNotMappedErrorTitle; return(false); } return(true); }
/// <summary> /// Updates the Wizard Info with the Data Mappings selected in this Wizard Part /// </summary> /// <returns></returns> public override bool UpdateWizardPart() { foreach (DataMappingRow row in DataMappingRows) { if (row is HeaderDataMappingRow || row is BlankDataMappingRow || row.DataSourceField == null) { continue; } IWorkItemField workItemField = m_wizardInfo.Migrator.SourceNameToFieldMapping[row.DataSourceField]; if (!string.IsNullOrEmpty(row.DataSourceValue) && !string.IsNullOrEmpty(row.NewValue)) { if (workItemField.ValueMapping.ContainsKey(row.DataSourceValue)) { workItemField.ValueMapping[row.DataSourceValue] = row.NewValue; } else { workItemField.ValueMapping.Add(row.DataSourceValue, row.NewValue); } } } m_wizardInfo.WorkItemGenerator.CreateAreaIterationPath = CreateAreaIterationPath; return(true); }
/// <summary> /// Constructor /// </summary> /// <param name="wiField"></param> public DisplayWorkItemField(IWorkItemField wiField) { WIField = wiField; }
/// <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"); }
/// <summary> /// Sets WorkitemField /// </summary> /// <param name="tfsField"></param> public void SetWorkItemField(IWorkItemField tfsField) { m_field.WIField = tfsField; NotifyPropertyChanged("TFSField"); NotifyPropertyChanged("IsValidFieldMapping"); }