Пример #1
0
        /// <summary>
        /// Reads the specified string-based data and returns a collection representing the tabular data.
        /// </summary>
        /// <param name='stringDataReader'>
        /// A <see cref="TextReader"/> that reads tabular data, formatted as a string.
        /// </param>
        public virtual TabularData Read(TextReader stringDataReader)
        {
            TabularDataStream readHelper = this.GetDataStream(stringDataReader);
            int currentRow = 1, columnCount = 0;
            TabularDataBuilder output = null;

            try
            {
                foreach (var row in readHelper)
                {
                    if (output == null)
                    {
                        columnCount = row.Count;
                        output      = new TabularDataBuilder(columnCount);
                    }

                    if (row.Count != columnCount &&
                        row.Count == 1 &&
                        this.Format.TolerateEmptyRows)
                    {
                        continue;
                    }
                    else if (row.Count != columnCount)
                    {
                        string message = String.Format("Invalid tabular data; column count does not match first column at row {0}.",
                                                       currentRow);
                        throw new TabularDataReadException(message);
                    }

                    output.AddRow(row);
                    currentRow++;
                }
            }
            catch (TabularDataReadException)
            {
                throw;
            }
            catch (Exception ex)
            {
                string message = String.Format("Invalid tabular data; an error was encountered whilst parsing row {0}.",
                                               currentRow);
                throw new TabularDataReadException(message, ex);
            }

            return(output.Build());
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CSF.IO.TabularDataStreamEnumerator"/> class.
 /// </summary>
 /// <param name='stream'>
 /// Stream.
 /// </param>
 public TabularDataStreamEnumerator(TabularDataStream stream)
 {
     this.Stream        = stream;
     this.AtEndOfStream = false;
 }