Beispiel #1
0
        /// <summary>
        /// Initialzes Excel Parser from Excel Storage Info
        /// </summary>
        /// <param name="info"></param>
        public ExcelParser(ExcelStorageInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            try
            {
                // Gets the Workbook located at passed file path
                m_workBook = OpenWorkbookInReadMode(info.Source);

                StorageInfo = info;
                StorageInfo.PropertyChanged += new PropertyChangedEventHandler(StorageInfo_PropertyChanged);
                RawSourceWorkItems           = new List <ISourceWorkItem>();
                ParsedSourceWorkItems        = new List <ISourceWorkItem>();
                FieldNameToFields            = new Dictionary <string, IWorkItemField>();
            }
            catch (COMException ex)
            {
                throw new WorkItemMigratorException("Unable to load excel workbook",
                                                    ex.Message,
                                                    ex.InnerException != null ? ex.InnerException.Message : string.Empty);
            }
            catch (InvalidCastException icEx)
            {
                throw new WorkItemMigratorException("Unable to load excel workbook",
                                                    icEx.Message,
                                                    icEx.InnerException != null ? icEx.InnerException.Message : string.Empty);
            }
        }
        /// <summary>
        /// Saves the Data Source Information
        /// </summary>
        /// <param name="wizardInfo"></param>
        private void SaveDataSourceInfo()
        {
            if (m_wizardInfo.DataSourceParser == null)
            {
                return;
            }

            m_dataSourceType = m_wizardInfo.DataSourceType;

            switch (m_wizardInfo.DataSourceType)
            {
            case DataSourceType.Excel:
                ExcelStorageInfo sourceInfo = m_wizardInfo.DataSourceParser.StorageInfo as ExcelStorageInfo;
                ExcelStorageInfo dataInfo   = new ExcelStorageInfo(sourceInfo.Source);
                dataInfo.WorkSheetName           = sourceInfo.WorkSheetName;
                dataInfo.RowContainingFieldNames = sourceInfo.RowContainingFieldNames;

                m_dataStorageInfo = dataInfo;
                break;

            case DataSourceType.MHT:
                m_dataStorageInfo = new MHTStorageInfo(m_wizardInfo.DataSourceParser.StorageInfo.Source);
                var fields = new List <SourceField>();
                foreach (SourceField field in m_wizardInfo.DataSourceParser.StorageInfo.FieldNames)
                {
                    fields.Add(field);
                }
                m_dataStorageInfo.FieldNames = fields;
                m_mhtSource = m_wizardInfo.MHTSource;
                break;

            default:
                throw new InvalidEnumArgumentException("Invalid Enum Value");
            }
        }
        public override void Reset()
        {
            Warning = null;
            string exePath          = Path.Combine(Directory.GetCurrentDirectory(), "TestCaseMigratorPlus.exe");
            string reportDirectory  = Path.GetDirectoryName(m_wizardInfo.Reporter.ReportFile);
            string settingsFilePath = m_wizardInfo.OutputSettingsFilePath;

            if (string.IsNullOrEmpty(settingsFilePath))
            {
                settingsFilePath = Path.Combine(reportDirectory, "Settings.xml");
            }

            if (m_wizardInfo.DataSourceType == DataSourceType.Excel)
            {
                ExcelStorageInfo excelInfo = m_wizardInfo.DataSourceParser.StorageInfo as ExcelStorageInfo;
                m_wizardInfo.CommandUsed = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                         @"{0} {1} /{2}:""{3}"" /{4}:""{5}"" /{6}:""{7}"" /{8}:""{9}"" /{10}:""{11}"" /{12}:""{13}"" /{14}:""{15}"" /{16}:""{17}""",
                                                         exePath,
                                                         App.ExcelSwitch,
                                                         App.SourceFileCLISwitch,
                                                         excelInfo.Source,
                                                         App.WorkSheetNameCLISwitch,
                                                         excelInfo.WorkSheetName,
                                                         App.HeaderRowCLISwitch,
                                                         excelInfo.RowContainingFieldNames,
                                                         App.CollectionCLISwitch,
                                                         m_wizardInfo.WorkItemGenerator.Server,
                                                         App.ProjectCLISwitch,
                                                         m_wizardInfo.WorkItemGenerator.Project,
                                                         App.WorkItemTypeCLISwitch,
                                                         m_wizardInfo.WorkItemGenerator.SelectedWorkItemTypeName,
                                                         App.SettingsCLISwitch,
                                                         settingsFilePath,
                                                         App.ReportCLISwitch,
                                                         reportDirectory);
            }
            else if (m_wizardInfo.DataSourceType == DataSourceType.MHT)
            {
                m_wizardInfo.CommandUsed = String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                         @"{0} {1} /{2}:""{3}"" /{4}:""{5}"" /{6}:""{7}"" /{8}:""{9}"" /{10}:""{11}"" /{12}:""{13}""",
                                                         exePath,
                                                         App.MHTSwitch,
                                                         App.SourceFileCLISwitch,
                                                         m_wizardInfo.MHTSource,
                                                         App.CollectionCLISwitch,
                                                         m_wizardInfo.WorkItemGenerator.Server,
                                                         App.ProjectCLISwitch,
                                                         m_wizardInfo.WorkItemGenerator.Project,
                                                         App.WorkItemTypeCLISwitch,
                                                         m_wizardInfo.WorkItemGenerator.SelectedWorkItemTypeName,
                                                         App.SettingsCLISwitch,
                                                         settingsFilePath,
                                                         App.ReportCLISwitch,
                                                         reportDirectory);
            }
        }
        /// <summary>
        /// Is Data Source Changed by SelectDataSourcepart
        /// </summary>
        /// <returns></returns>
        public bool IsDataSourceChanged()
        {
            // Return true if wizard is going to be intialized first time or data source type is changed
            if (m_wizardInfo == null ||
                m_wizardInfo.DataSourceType != m_dataSourceType ||
                m_dataStorageInfo == null)
            {
                return(true);
            }
            else
            {
                switch (m_wizardInfo.DataSourceType)
                {
                case DataSourceType.Excel:
                    ExcelStorageInfo acturalInfo  = m_wizardInfo.DataSourceParser.StorageInfo as ExcelStorageInfo;
                    ExcelStorageInfo expectedInfo = m_dataStorageInfo as ExcelStorageInfo;

                    // if excel source file path is changed or worksheet name is changed or row containg field names is changed then return true
                    if (String.CompareOrdinal(expectedInfo.Source, acturalInfo.Source) != 0 ||
                        String.CompareOrdinal(expectedInfo.WorkSheetName, acturalInfo.WorkSheetName) != 0 ||
                        String.CompareOrdinal(expectedInfo.RowContainingFieldNames, acturalInfo.RowContainingFieldNames) != 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }

                case DataSourceType.MHT:
                    // return true If MHT Source is changed or user have added new fields
                    if (String.CompareOrdinal(m_wizardInfo.MHTSource, m_mhtSource) != 0 ||
                        (m_wizardInfo.DataSourceParser.StorageInfo.FieldNames.Count != m_fields.Count))
                    {
                        return(true);
                    }

                    // return trueif user have modified any field name
                    foreach (SourceField field in m_fields)
                    {
                        if (!m_wizardInfo.DataSourceParser.StorageInfo.FieldNames.Contains(field))
                        {
                            return(true);
                        }
                    }
                    return(false);

                default:
                    return(true);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Update the list of Field names
        /// </summary>
        private void UpdateFields()
        {
            App.CallMethodInUISynchronizationContext(ClearFields, null);
            if (m_wizardInfo == null || m_wizardInfo.DataSourceParser == null || string.IsNullOrEmpty(SelectedExcelSheet))
            {
                return;
            }

            int headerRow = -1;

            int.TryParse(ExcelHeaderRow, out headerRow);
            if (headerRow < 1)
            {
                Fields.Clear();
                return;
            }

            // If Data Source Wizard Part is in valid state and Storage Info is not null
            using (new AutoWaitCursor())
            {
                switch (DataSourceType)
                {
                case DataSourceType.Excel:
                    ExcelStorageInfo xlInfo = m_wizardInfo.DataSourceParser.StorageInfo as ExcelStorageInfo;
                    xlInfo.WorkSheetName           = SelectedExcelSheet;
                    xlInfo.RowContainingFieldNames = ExcelHeaderRow;
                    break;

                case DataSourceType.MHT:
                    break;

                default:
                    throw new InvalidEnumArgumentException("Invalid Enum Value");
                }
                try
                {
                    m_wizardInfo.DataSourceParser.ParseDataSourceFieldNames();

                    if (m_wizardInfo.DataSourceParser.StorageInfo.FieldNames != null)
                    {
                        m_fields.Clear();
                        foreach (SourceField field in m_wizardInfo.DataSourceParser.StorageInfo.FieldNames)
                        {
                            m_fields.Add(field.FieldName);
                        }
                    }
                }
                catch (WorkItemMigratorException)
                { }
            }
        }
        /// <summary>
        /// Is Excel Source Information Modified in Select Data Source Part by the User
        /// </summary>
        /// <param name="excelFilePath"></param>
        /// <param name="workSheetName"></param>
        /// <param name="headerRow"></param>
        /// <returns></returns>
        public bool IsExcelSourceModified(string excelFilePath, string workSheetName, string headerRow)
        {
            ExcelStorageInfo excelInfo = m_dataStorageInfo as ExcelStorageInfo;

            if (excelInfo == null)
            {
                return(true);
            }
            if (excelInfo.Source == excelFilePath &&
                excelInfo.WorkSheetName == workSheetName &&
                excelInfo.RowContainingFieldNames == headerRow)
            {
                return(false);
            }
            return(true);
        }
Beispiel #7
0
        private void InitializeExcelDataSource(Dictionary <CommandLineSwitch, string> arguments)
        {
            WizardInfo.DataSourceType = DataSourceType.Excel;
            ExcelStorageInfo excelInfo = null;

            try
            {
                excelInfo = new ExcelStorageInfo(arguments[CommandLineSwitch.SourcePath]);
            }
            catch (ArgumentException)
            {
                throw new WorkItemMigratorException("Incorrect excel file type", null, null);
            }
            excelInfo.WorkSheetName           = arguments[CommandLineSwitch.WorkSheetName];
            excelInfo.RowContainingFieldNames = arguments[CommandLineSwitch.HeaderRow];
            WizardInfo.DataStorageInfos       = new List <IDataStorageInfo> {
                excelInfo
            };
            WizardInfo.DataSourceParser = new ExcelParser(excelInfo);
            WizardInfo.DataSourceParser.ParseDataSourceFieldNames();
        }
Beispiel #8
0
        /// <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");
                }
            }
        }