Example #1
0
 /// <summary>
 /// Disposes the Data Source
 /// </summary>
 public void Dispose()
 {
     m_wizardInfo.PropertyChanged -= WizardInfo_PropertyChanged;
     m_wizardInfo.Dispose();
     ExcelParser.Quit();
     MHTParser.Quit();
 }
Example #2
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            MessageHelper.ShowMessageWindow = null;
            if (WizardInfo != null)
            {
                WizardInfo.Dispose();
            }
            ExcelParser.Quit();
            MHTParser.Quit();
        }
Example #3
0
 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;
             }
         }
     }
 }
 /// <summary>
 /// Open MHT file with field name-value pairs in different highlighting
 /// </summary>
 public void Preview()
 {
     Warning = null;
     if (IsMHTFile(SourcePath))
     {
         var fields = new List <string>();
         foreach (var field in Fields)
         {
             fields.Add(field.FieldName);
         }
         try
         {
             MHTParser.Preview(SourcePath, fields);
         }
         catch (WorkItemMigratorException ex)
         {
             Warning = ex.Args.Title;
         }
     }
     else
     {
         Warning = "Invalid MHT file";
     }
 }
Example #5
0
        private void ParseCLIArguments(string[] args)
        {
            Dictionary <CommandLineSwitch, string> arguments;

            SetConsoleMode();

            try
            {
                if (ParseArguments(args, out arguments))
                {
                    VerifyArguments(arguments);

                    WizardInfo = new WizardInfo();

                    Console.Write("Loading Data Source...");

                    if (arguments.ContainsKey(CommandLineSwitch.Excel))
                    {
                        InitializeExcelDataSource(arguments);
                    }
                    else if (arguments.ContainsKey(CommandLineSwitch.MHT))
                    {
                        InitializeMHTDataSource(arguments);
                    }

                    Console.Write("\nInitializing TFS Server Connection...");

                    WizardInfo.WorkItemGenerator = new WorkItemGenerator(arguments[CommandLineSwitch.TFSCollection], arguments[CommandLineSwitch.Project]);
                    if (WizardInfo.DataSourceType == DataSourceType.MHT)
                    {
                        WizardInfo.WorkItemGenerator.AddTestStepsField = false;
                    }
                    else if (WizardInfo.DataSourceType == DataSourceType.Excel)
                    {
                        WizardInfo.WorkItemGenerator.AddTestStepsField = true;
                    }

                    if (!WizardInfo.WorkItemGenerator.WorkItemTypeNames.Contains(arguments[CommandLineSwitch.WorkItemType]))
                    {
                        throw new WorkItemMigratorException("Wrong Type Name:" + arguments[CommandLineSwitch.WorkItemType] + " is given", null, null);
                    }

                    WizardInfo.WorkItemGenerator.SelectedWorkItemTypeName = arguments[CommandLineSwitch.WorkItemType];

                    Console.Write("\nLoading Settings...");
                    WizardInfo.LoadSettings(arguments[CommandLineSwitch.SettingsPath]);


                    if (WizardInfo.DataSourceType == DataSourceType.Excel)
                    {
                        WizardInfo.Reporter.ReportFile = Path.Combine(arguments[CommandLineSwitch.ReportPath], "Report.xls");
                    }
                    else
                    {
                        WizardInfo.Reporter.ReportFile = Path.Combine(arguments[CommandLineSwitch.ReportPath], "Report.xml");
                    }

                    WizardInfo.LinksManager = new LinksManager(WizardInfo);

                    Console.WriteLine("\n\nStarting Migration:\n");

                    WizardInfo.Migrator.PostMigration = ShowMigrationStatus;

                    var resultSourceWorkItems = WizardInfo.Migrator.Migrate(WizardInfo.WorkItemGenerator);
                    WizardInfo.ResultWorkItems = resultSourceWorkItems;

                    Console.Write("\n\nPublishing Report:");

                    foreach (var dsWorkItem in resultSourceWorkItems)
                    {
                        WizardInfo.Reporter.AddEntry(dsWorkItem);
                    }
                    WizardInfo.Reporter.Publish();

                    if (WizardInfo.DataSourceType == DataSourceType.Excel)
                    {
                        ProcessLinks();
                    }
                }
                else
                {
                    if (arguments.Count > 0)
                    {
                        if (arguments.ContainsKey(CommandLineSwitch.MHT))
                        {
                            DisplayMHTUsage();
                        }
                        else if (arguments.ContainsKey(CommandLineSwitch.Excel))
                        {
                            DisplayExcelUsage();
                        }
                        else
                        {
                            DisplayGenericUsage();
                        }
                    }
                    else
                    {
                        DisplayGenericUsage();
                    }
                }
            }
            catch (WorkItemMigratorException te)
            {
                Console.WriteLine(te.Args.Title);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                if (WizardInfo != null)
                {
                    WizardInfo.Dispose();
                }
                MHTParser.Quit();
                ExcelParser.Quit();
            }
            Console.Write("\n\nPress Enter to exit...\n");
        }
Example #6
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);
        }
Example #7
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");
            }
        }