public void ReadMultipleDataRowsAndBlankLastRow()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("1,1,1,1\r\n2,2,2,2\r\n3,3,3,3\r\n4,4,4,4\r\n");
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");

            parser.SkipInitialRows(reader);
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "1", "1", "1", "1" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "2", "2", "2", "2" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "3", "3", "3", "3" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "4", "4", "4", "4" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[0]);
        }
        public void ReadSingleColumnRows3()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("\"ABC\"\r\n\"DE\"F\r\n\"G\"HI");
            DelimitedFileParser parser = new DelimitedFileParser(string.Empty, "\r\n");
            parser.TextQualifier = "\"";

            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "ABC" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "DEF" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "GHI" });
        }
        public void ReadMultipleDataRowsAfterHeader()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader text\r\n1,1,1,1\r\n2,2,2,2\r\n3,3,3,3\r\n4,4,4,4");
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");
            parser.HeaderRowDelimiter = "\r\n";
            parser.HeaderRowsToSkip = 3;

            parser.SkipHeaderRows(reader);
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "1", "1", "1", "1" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "2", "2", "2", "2" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "3", "3", "3", "3" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "4", "4", "4", "4" });
        }
        public void ReadSingleColumnRows()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("1,2,3");
            DelimitedFileParser parser = new DelimitedFileParser(string.Empty, ",");

            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "1" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "2" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "3" });
        }
        public void ReadSingleColumnRows2()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("ABC\r\nDEF\r\nGHI");
            DelimitedFileParser parser = new DelimitedFileParser(string.Empty, "\r\n");

            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "ABC" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "DEF" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "GHI" });
        }
        public void ReadMultipleDataRowsAfterHeaderWithMessyParsing()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader text\r\n A)::-)brr\"-:-)\r\n-\r\nasdfghj\"-\"\"-\":-)\"-\":-)\"-\"\"-\"\"-\":--\r");
            DelimitedFileParser parser = new DelimitedFileParser(":-)", "-\r\n");
            parser.HeaderRowDelimiter = "\r\n";
            parser.HeaderRowsToSkip = 3;
            parser.TextQualifier = "\"-\"";

            parser.SkipHeaderRows(reader);
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { " A):", "brr\"-", "\r\n" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "asdfghj\"-\"\"-\"", ":-)\"-\":-" });
        }
        public override void PrimeOutput(int outputs, int[] outputIDs, PipelineBuffer[] buffers)
        {
            PipelineBuffer mainBuffer  = null;
            PipelineBuffer errorBuffer = null;
            IDTSOutput100  mainOutput  = null;

            int errorOutID    = 0;
            int errorOutIndex = 0;

            // If there is an error output, figure out which output is the main
            // and which is the error
            if (outputs == 2)
            {
                GetErrorOutputInfo(ref errorOutID, ref errorOutIndex);

                if (outputIDs[0] == errorOutID)
                {
                    mainBuffer  = buffers[1];
                    errorBuffer = buffers[0];
                    mainOutput  = this.ComponentMetaData.OutputCollection[1];
                }
                else
                {
                    mainBuffer  = buffers[0];
                    errorBuffer = buffers[1];
                    mainOutput  = this.ComponentMetaData.OutputCollection[0];
                }
            }
            else
            {
                mainBuffer = buffers[0];
                mainOutput = this.ComponentMetaData.OutputCollection[0];
            }

            bool firstRowColumnNames = (bool)this.GetComponentPropertyValue(PropertiesManager.ColumnNamesInFirstRowPropName);
            bool treatNulls          = (bool)this.GetComponentPropertyValue(PropertiesManager.TreatEmptyStringsAsNullPropName);

            FileReader             reader        = new FileReader(this.fileName, this.GetEncoding());
            DelimitedFileParser    parser        = this.CreateParser();
            ComponentBufferService bufferService = new ComponentBufferService(mainBuffer, errorBuffer);

            BufferSink bufferSink = new BufferSink(bufferService, mainOutput, treatNulls);

            bufferSink.CurrentRowCount = parser.HeaderRowsToSkip + parser.DataRowsToSkip + (firstRowColumnNames ? 1 : 0);

            try
            {
                parser.SkipInitialRows(reader);

                RowData rowData = new RowData();
                while (!reader.IsEOF)
                {
                    parser.ParseNextRow(reader, rowData);
                    if (rowData.ColumnCount == 0)
                    {
                        // Last row with no data will be ignored.
                        break;
                    }
                    bufferSink.AddRow(rowData);
                }
            }
            catch (ParsingBufferOverflowException ex)
            {
                this.PostErrorAndThrow(MessageStrings.ParsingBufferOverflow(bufferSink.CurrentRowCount + 1, ex.ColumnIndex + 1, FieldParser.ParsingBufferMaxSize));
            }
            catch (RowColumnNumberOverflow)
            {
                this.PostErrorAndThrow(MessageStrings.MaximumColumnNumberOverflow(bufferSink.CurrentRowCount + 1, RowParser.MaxColumnNumber));
            }
            finally
            {
                reader.Close();
            }

            foreach (PipelineBuffer buffer in buffers)
            {
                buffer.SetEndOfRowset();
            }
        }
        public void SkipHeaderRowsArgumentTest()
        {
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");

            parser.SkipHeaderRows(null);
        }
        public void ReadColumnNamesTest()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("A,B,C\r\n1,2,3");
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");
            parser.ColumnNameInFirstRow = true;

            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "A", "B", "C" });
        }
 public void ColumnNameInFirstRowTest()
 {
     DelimitedFileParser target = new DelimitedFileParser(",", "\r\n");
     bool expected = false;
     bool actual;
     target.ColumnNameInFirstRow = expected;
     actual = target.ColumnNameInFirstRow;
     Assert.AreEqual(expected, actual);
 }
        public void ParseNExtRowArgumentTest()
        {
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");

            parser.ParseNextRow(null, null);
        }
 public void HeaderRowDelimiterTest()
 {
     DelimitedFileParser target = new DelimitedFileParser(",", "\r\n");
     string expected = "\r\n";
     string actual;
     target.HeaderRowDelimiter = expected;
     actual = target.HeaderRowDelimiter;
     Assert.AreEqual(expected, actual);
 }
 public void DataRowsToSkipTest()
 {
     DelimitedFileParser target = new DelimitedFileParser(",", "\r\n");
     int expected = 17;
     int actual;
     target.DataRowsToSkip = expected;
     actual = target.DataRowsToSkip;
     Assert.AreEqual(expected, actual);
 }
 public void TextQualifierTest()
 {
     DelimitedFileParser target = new DelimitedFileParser(",", "\r\n");
     string expected = "\"";
     string actual;
     target.TextQualifier = expected;
     actual = target.TextQualifier;
     Assert.AreEqual(expected, actual);
 }
        public void TestSkippingRows()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader\r\nA,B,C,D\r\n1,1,1,1\r\n2,2,2,2\r\n3,3,3,3\r\n4,4,4,4\r\n");
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");
            parser.HeaderRowDelimiter = "\r\n";
            parser.HeaderRowsToSkip = 3;
            parser.DataRowsToSkip = 3;
            parser.ColumnNameInFirstRow = true;

            parser.SkipInitialRows(reader);
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "4", "4", "4", "4" });
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[0]);

            Assert.AreEqual<bool>(true, reader.IsEOF);
        }
        public void ReadQualifiedColumnNamesAfterHeaderTest()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader text\r\n\"A\",B,\"C\"\r\n1,2,3");
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");
            parser.ColumnNameInFirstRow = true;
            parser.HeaderRowDelimiter = "\r\n";
            parser.HeaderRowsToSkip = 3;
            parser.TextQualifier = "\"";

            parser.SkipHeaderRows(reader);
            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "A", "B", "C" });
        }
        public void TestSkippingTooManyHeaderRows()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("\r\n\r\nHeader\r\nA,B,C,D\r\n1,1,1,1\r\n2,2,2,2\r\n3,3,3,3\r\n4,4,4,4\r\n");
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");
            parser.HeaderRowDelimiter = "\r\n";
            parser.HeaderRowsToSkip = 12;
            parser.DataRowsToSkip = 15;
            parser.ColumnNameInFirstRow = true;

            parser.SkipInitialRows(reader);

            Assert.AreEqual<bool>(true, reader.IsEOF);
        }
        public void ReadSingleDataRow()
        {
            RowData rowData = new RowData();
            IFileReader reader = FileReaderTest.GetReader("1,2,3");
            DelimitedFileParser parser = new DelimitedFileParser(",", "\r\n");

            parser.ParseNextRow(reader, rowData);
            RowDataTest.VerifyParsedRow(rowData, new string[] { "1", "2", "3" });
        }
 public void DelimitedFileParserConstructorTest3()
 {
     DelimitedFileParser target = new DelimitedFileParser(",", string.Empty);
 }
        private DelimitedFileParser CreateParser()
        {
            string columnDelimiter = (string)this.GetComponentPropertyValue(PropertiesManager.ColumnDelimiterPropName);
            string rowDelimiter = (string)this.GetComponentPropertyValue(PropertiesManager.RowDelimiterPropName);
            string textQualifier = (string)this.GetComponentPropertyValue(PropertiesManager.TextQualifierPropName);
            string headerRowDelimiter = (string)this.GetComponentPropertyValue(PropertiesManager.HeaderRowDelimiterPropName);
            int headerRowsToSkip = (int)this.GetComponentPropertyValue(PropertiesManager.HeaderRowsToSkipPropName);
            int dataRowsToSkip = (int)this.GetComponentPropertyValue(PropertiesManager.DataRowsToSkipPropName);
            bool columnNamesInFirstRow = (bool)this.GetComponentPropertyValue(PropertiesManager.ColumnNamesInFirstRowPropName);

            DelimitedFileParser parser = new DelimitedFileParser(columnDelimiter, rowDelimiter);
            parser.HeaderRowDelimiter = headerRowDelimiter;
            parser.HeaderRowsToSkip = headerRowsToSkip;
            parser.DataRowsToSkip = dataRowsToSkip;
            parser.TextQualifier = textQualifier;
            parser.ColumnNameInFirstRow = columnNamesInFirstRow;

            return parser;
        }