Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        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");
            }
        }