Exemplo n.º 1
0
        /// <summary>
        /// Close the underlining Readers and Writers. (if any)
        /// </summary>
        public void Close()
        {
            try {
                if (mAsyncReader != null)
                {
                    mAsyncReader.Close();
                }

                mAsyncReader = null;
            }
            catch {}

            try {
                if (mAsyncWriter != null)
                {
                    if (!string.IsNullOrEmpty(mFooterText))
                    {
                        if (mFooterText.EndsWith(StringHelper.NewLine))
                        {
                            mAsyncWriter.Write(mFooterText);
                        }
                        else
                        {
                            mAsyncWriter.WriteLine(mFooterText);
                        }
                    }

                    mAsyncWriter.Close();
                    mAsyncWriter = null;
                }
            }
            catch {}
        }
Exemplo n.º 2
0
 //static readonly char[] mEmptyChars = new char[] {};
 /// <summary>
 /// Create a line info with data from line
 /// </summary>
 /// <param name="line"></param>
 public LineInfo(string line)
 {
     mReader = null;
     mLineStr = line;
     //mLine = line == null ? mEmptyChars : line.ToCharArray();
     mCurrentPos = 0;
 }
Exemplo n.º 3
0
        public void BeginReadStream(IRecordReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("The TextReader can´t be null.");
            }

            ResetFields();
            mHeaderText = String.Empty;
            mFooterText = String.Empty;

            if (RecordInfo.IgnoreFirst > 0)
            {
                for (int i = 0; i < RecordInfo.IgnoreFirst; i++)
                {
                    string temp = reader.ReadRecordString();
                    mLineNumber++;
                    if (temp != null)
                    {
                        mHeaderText += temp + StringHelper.NewLine;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            mAsyncReader = new ForwardReader(reader, RecordInfo.IgnoreLast, mLineNumber)
            {
                DiscardForward = true
            };
        }
Exemplo n.º 4
0
        /// <summary>
        /// Close the underlining Readers and Writers. (if any)
        /// </summary>
        public void Close()
        {
            try
            {
                if (mAsyncReader != null)
                {
                    mAsyncReader.Close();
                }

                mAsyncReader = null;
            }
            catch { }

            try
            {
                if (mAsyncWriter != null)
                {
                    WriteFooter(mAsyncWriter);

                    mAsyncWriter.Close();
                    mAsyncWriter = null;
                }
            }
            catch { }
        }
Exemplo n.º 5
0
        public void BasicProperties()
        {
            var reader = new ForwardReader(new NewLineDelimitedRecordReader(new StreamReader(FileTest.Good.CustomersTab.Path)), 0, 0);
            reader.DiscardForward.AssertEqualTo(false);
            reader.FowardLines.AssertEqualTo(0);
            reader.LineNumber.AssertEqualTo(0);

            reader.ReadNextLine();

            reader.LineNumber.AssertEqualTo(1);
        }
Exemplo n.º 6
0
//		public ConverterBase ConvertProvider
//		{
//			get { return mConvertProvider; }
//			set { mConvertProvider = value; }
//		}
//
//		#endregion



//		#region "  TrimMode  "
//
//		public TrimMode TrimMode
//		{
//			get { return mTrimMode; }
//		}
//
//		#endregion
//
//		#region "  TrimChars  "
//
//		public char[] TrimChars
//		{
//			get { return mTrimChars; }
//		}
//
//		#endregion
//
//		#region "  IsOptional  "
//
//		public bool IsOptional
//		{
//			get { return mIsOptional; }
//		}
//
//		#endregion
//
//		#region "  NextIsOptional  "
//
//		internal bool NextIsOptional
//		{
//			get { return mNextIsOptional; }
//			set { mNextIsOptional = value; }
//		}
//
//		#endregion

//		#region "  InNewLine  "

//		public bool InNewLine
//		{
//			get { return mInNewLine; }
//		}
//
//		#endregion
//
//

//		#region "  FieldType  "
//
//		public Type FieldType
//		{
//			get { return mFieldType; }
//		}
//
//		#endregion

        #region "  ExtractAndAssignFromString  "

        internal string ExtractAndAssignFromString(string buffer, object record, ForwardReader reader)
        {
            //-> extract only what I need

            if (this.mInNewLine == true)
            {
                if (buffer.Trim() != String.Empty)
                {
                    throw new BadUsageException("Text '" + buffer + "' found before the new line of the field: " + mFieldInfo.Name + " (this is not allowed when you use [FieldInNewLine])");
                }

                buffer = reader.ReadNextLine();

                if (buffer == null)
                {
                    throw new BadUsageException("End of stream found parsing the field " + mFieldInfo.Name + ". Please check the class record.");
                }
            }

            ExtractedInfo info = ExtractFieldString(buffer, reader);

            AssignFromString(info.ExtractedString, record);

            //-> discard the part that I use


            if (info.NewRestOfLine != null)
            {
                if (info.NewRestOfLine.Length < CharsToDiscard())
                {
                    return(info.NewRestOfLine);
                }
                else
                {
                    return(info.NewRestOfLine.Substring(CharsToDiscard()));
                }
            }
            else
            {
                int total;
                if (info.CharsRemoved >= buffer.Length)
                {
                    total = buffer.Length;
                }
                else
                {
                    total = info.CharsRemoved + CharsToDiscard();
                }

                return(buffer.Substring(total));
            }
        }
        /// <include file='FileHelperAsyncEngine.docs.xml' path='doc/EndsRead/*'/>
        public void EndsRead()
        {
            try
            {
                if (mAsyncReader != null)
                {
                    mAsyncReader.Close();
                }

                mAsyncReader = null;
            }
            catch
            {
            }
        }
Exemplo n.º 8
0
        internal object StringToRecord(string line, ForwardReader reader)
        {
            if (line == string.Empty && mIgnoreEmptyLines)
            {
                return(null);
            }

            object record = CreateRecordObject();

            for (int i = 0; i < mFieldCount; i++)
            {
                line = mFields[i].ExtractAndAssignFromString(line, record, reader);
            }

            return(record);
        }
        /// <include file='FileHelperAsyncEngine.docs.xml' path='doc/Close/*'/>
        public void Close()
        {
            mState = EngineState.Closed;

            try
            {
                mLastRecordValues = null;
#if !GENERICS
                mLastRecord = null;
#else
                mLastRecord = default(T);
#endif

                if (mAsyncReader != null)
                {
                    mAsyncReader.Close();
                }

                mAsyncReader = null;
            }
            catch
            { }

            try
            {
                if (mAsyncWriter != null)
                {
                    if (mFooterText != null && mFooterText != string.Empty)
                    {
                        if (mFooterText.EndsWith(StringHelper.NewLine))
                        {
                            mAsyncWriter.Write(mFooterText);
                        }
                        else
                        {
                            mAsyncWriter.WriteLine(mFooterText);
                        }
                    }

                    mAsyncWriter.Close();
                    mAsyncWriter = null;
                }
            }
            catch
            { }
        }
Exemplo n.º 10
0
        protected override ExtractedInfo ExtractFieldString(string from, ForwardReader reader)
        {
            if (mIsOptional && from.Length == 0)
            {
                return(ExtractedInfo.Empty);
            }

            ExtractedInfo res;

            if (from.Length < this.mLength)
            {
                throw new FileHelperException("The string '" + from + "' (length " + from.Length.ToString() + ") don´t match the length of the field " + mFieldInfo.Name + " (" + mLength.ToString() + ")");
            }
            else
            {
                res = new ExtractedInfo(from.Substring(0, this.mLength));
            }

            return(res);
        }
        /// <include file='FileHelperAsyncEngine.docs.xml' path='doc/BeginReadStream/*'/>
        public void BeginReadStream(TextReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "The TextReader can´t be null.");
            }

            if (mAsyncWriter != null)
            {
                throw new BadUsageException("You can't start to read while you are writing.");
            }

            NewLineDelimitedRecordReader recordReader = new NewLineDelimitedRecordReader(reader);

            ResetFields();
            mHeaderText = String.Empty;
            mFooterText = String.Empty;

            if (mRecordInfo.mIgnoreFirst > 0)
            {
                for (int i = 0; i < mRecordInfo.mIgnoreFirst; i++)
                {
                    string temp = recordReader.ReadRecord();
                    mLineNumber++;
                    if (temp != null)
                    {
                        mHeaderText += temp + StringHelper.NewLine;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            mAsyncReader = new ForwardReader(recordReader, mRecordInfo.mIgnoreLast, mLineNumber);
            mAsyncReader.DiscardForward = true;
            mState = EngineState.Reading;
        }
Exemplo n.º 12
0
        /// <include file='MultiRecordEngine.docs.xml' path='doc/ReadStream/*'/>
        public object[] ReadStream(IRecordReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader), "The reader of the Stream can't be null");
            }

            if (mRecordSelector == null)
            {
                throw new BadUsageException(
                          "The RecordSelector can't be null, please pass a non-null Selector in the constructor.");
            }

            ResetFields();
            HeaderText  = string.Empty;
            mFooterText = string.Empty;

            var resArray = new ArrayList();

            using (var freader = new ForwardReader(reader, mMultiRecordInfo[0].IgnoreLast))
            {
                freader.DiscardForward = true;

                mLineNumber = 1;

                var completeLine = freader.ReadNextLine();
                var currentLine  = completeLine;

                if (MustNotifyProgress) // Avoid object creation
                {
                    OnProgress(new ProgressEventArgs(0, -1));
                }

                int currentRecord = 0;

                if (mMultiRecordInfo[0].IgnoreFirst > 0)
                {
                    for (int i = 0; i < mMultiRecordInfo[0].IgnoreFirst && currentLine != null; i++)
                    {
                        HeaderText += currentLine + Environment.NewLine;
                        currentLine = freader.ReadNextLine();
                        mLineNumber++;
                    }
                }

                bool byPass = false;

                var line = new LineInfo(currentLine)
                {
                    mReader = freader
                };

                while (currentLine != null)
                {
                    try
                    {
                        mTotalRecords++;
                        currentRecord++;

                        line.ReLoad(currentLine);

                        Type currentType;
                        try
                        {
                            currentType = mRecordSelector(this, currentLine);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Selector failed to process correctly", ex);
                        }

                        if (currentType != null)
                        {
                            mRecordInfoTable.TryGetValue(currentType, out IRecordInfo info);
                            if (info == null)
                            {
                                throw new BadUsageException("A record is of type '" + currentType.Name +
                                                            "' which this engine is not configured to handle. Try adding this type to the constructor.");
                            }

                            object record = ReadRecord(info, currentRecord, line);
                            if (record != null)
                            {
                                resArray.Add(record);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        switch (mErrorManager.ErrorMode)
                        {
                        case ErrorMode.ThrowException:
                            byPass = true;
                            throw;

                        case ErrorMode.IgnoreAndContinue:
                            break;

                        case ErrorMode.SaveAndContinue:
                            var err = new ErrorInfo
                            {
                                mLineNumber     = freader.LineNumber,
                                mExceptionInfo  = ex,
                                mRecordString   = completeLine,
                                mRecordTypeName = RecordInfo.RecordType.Name
                            };

                            mErrorManager.AddError(err);
                            break;
                        }
                    }
                    finally
                    {
                        if (byPass == false)
                        {
                            currentLine  = freader.ReadNextLine();
                            completeLine = currentLine;
                            mLineNumber  = freader.LineNumber;
                        }
                    }
                }

                if (mMultiRecordInfo[0].IgnoreLast > 0)
                {
                    mFooterText = freader.RemainingText;
                }
            }
            return(resArray.ToArray());
        }
Exemplo n.º 13
0
        /// <include file='MultiRecordEngine.docs.xml' path='doc/ReadStream/*'/>
        public object[] ReadStream(IRecordReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "The reader of the Stream can´t be null");
            }

            if (mRecordSelector == null)
            {
                throw new BadUsageException("The Recordselector can´t be null, please pass a not null Selector in the constructor.");
            }

            ResetFields();
            mHeaderText = String.Empty;
            mFooterText = String.Empty;

            var resArray = new ArrayList();

            using (var freader = new ForwardReader(reader, mMultiRecordInfo[0].IgnoreLast))
            {
                freader.DiscardForward = true;

                string currentLine, completeLine;

                mLineNumber = 1;

                completeLine = freader.ReadNextLine();
                currentLine  = completeLine;

#if !MINI
                if (MustNotifyProgress) // Avoid object creation
                {
                    OnProgress(new ProgressEventArgs(0, -1));
                }
#endif
                int currentRecord = 0;

                if (mMultiRecordInfo[0].IgnoreFirst > 0)
                {
                    for (int i = 0; i < mMultiRecordInfo[0].IgnoreFirst && currentLine != null; i++)
                    {
                        mHeaderText += currentLine + StringHelper.NewLine;
                        currentLine  = freader.ReadNextLine();
                        mLineNumber++;
                    }
                }


                bool byPass = false;

                var line = new LineInfo(currentLine)
                {
                    mReader = freader
                };

                while (currentLine != null)
                {
                    try
                    {
                        mTotalRecords++;
                        currentRecord++;

                        line.ReLoad(currentLine);

                        var  skip     = false;
                        Type currType = null;
                        try
                        {
                            currType = mRecordSelector(this, currentLine);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Selector failed to process correctly", ex);
                        }

                        if (currType != null)
                        {
                            var info = (RecordInfo)mRecordInfoHash[currType];
                            if (info == null)
                            {
                                throw new BadUsageException("A record is of type '" + currType.Name +
                                                            "' which this engine is not configured to handle. Try adding this type to the constructor.");
                            }

                            var record = info.Operations.CreateRecordHandler();

#if !MINI
                            if (MustNotifyProgress) // Avoid object creation
                            {
                                OnProgress(new ProgressEventArgs(currentRecord, -1));
                            }

                            BeforeReadEventArgs <object> e = null;
                            if (MustNotifyRead) // Avoid object creation
                            {
                                e    = new BeforeReadEventArgs <object>(this, record, currentLine, LineNumber);
                                skip = OnBeforeReadRecord(e);
                                if (e.RecordLineChanged)
                                {
                                    line.ReLoad(e.RecordLine);
                                }
                            }
#endif

                            if (skip == false)
                            {
                                var values = new object[info.FieldCount];
                                if (info.Operations.StringToRecord(record, line, values))
                                {
#if !MINI
                                    if (MustNotifyRead) // Avoid object creation
                                    {
                                        skip = OnAfterReadRecord(currentLine, record, e.RecordLineChanged, LineNumber);
                                    }
#endif

                                    if (skip == false)
                                    {
                                        resArray.Add(record);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        switch (mErrorManager.ErrorMode)
                        {
                        case ErrorMode.ThrowException:
                            byPass = true;
                            throw;

                        case ErrorMode.IgnoreAndContinue:
                            break;

                        case ErrorMode.SaveAndContinue:
                            var err = new ErrorInfo
                            {
                                mLineNumber    = freader.LineNumber,
                                mExceptionInfo = ex,
                                mRecordString  = completeLine
                            };
                            //							err.mColumnNumber = mColumnNum;

                            mErrorManager.AddError(err);
                            break;
                        }
                    }
                    finally
                    {
                        if (byPass == false)
                        {
                            currentLine  = freader.ReadNextLine();
                            completeLine = currentLine;
                            mLineNumber  = freader.LineNumber;
                        }
                    }
                }

                if (mMultiRecordInfo[0].IgnoreLast > 0)
                {
                    mFooterText = freader.RemainingText;
                }
            }
            return(resArray.ToArray());
        }
Exemplo n.º 14
0
        protected override ExtractedInfo ExtractFieldString(string from, ForwardReader reader)
        {
            if (mIsOptional && from.Length == 0)
            {
                return(ExtractedInfo.Empty);
            }

            ExtractedInfo res;

            if (mQuoteChar == '\0')
            {
                if (mIsLast)
                {
                    res = new ExtractedInfo(from);
                }
                else
                {
                    int sepPos = from.IndexOf(this.mSeparator);

                    if (sepPos == -1)
                    {
                        if (this.mNextIsOptional == false)
                        {
                            throw new FileHelperException("The separator '" + this.mSeparator + "' can´t be found after the field '" + this.mFieldInfo.Name + "' (the record has less fields, the separator is wrong or the next field must be marked as optional).");
                        }
                        else
                        {
                            sepPos = from.Length;
                        }
                    }

                    res = new ExtractedInfo(from.Substring(0, sepPos));
                }
            }
            else
            {
                string quotedStr = mQuoteChar.ToString();
                res = new ExtractedInfo();
                res.CharsRemoved = 0;

                string from2 = from;
                if (mTrimMode == TrimMode.Both || mTrimMode == TrimMode.Left)
                {
                    from2            = from.TrimStart(mTrimChars);
                    res.CharsRemoved = from2.Length - from.Length;
                }

                if (from2.StartsWith(quotedStr))
                {
                    if (mQuoteMultiline == MultilineMode.AllowForBoth || mQuoteMultiline == MultilineMode.AllowForRead)
                    {
                        ExtractedInfo ei = StringHelper.ExtractQuotedString(from2, reader, mQuoteChar);
                        res.ExtractedString = ei.ExtractedString;
                        res.CharsRemoved   += ei.CharsRemoved;
                        res.ExtraLines      = ei.ExtraLines;
                        res.NewRestOfLine   = ei.NewRestOfLine;
                    }
                    else
                    {
                        int index = 0;

                        res.ExtractedString = StringHelper.ExtractQuotedString(from2, mQuoteChar, out index);
                        res.CharsRemoved   += index;
                    }
                }
                else
                {
                    if (mQuoteMode == QuoteMode.OptionalForBoth || mQuoteMode == QuoteMode.OptionalForRead)
                    {
                        if (mIsLast)
                        {
                            res = new ExtractedInfo(from);
                        }
                        else
                        {
                            int sepPos = from.IndexOf(this.mSeparator);

                            if (sepPos == -1)
                            {
                                if (this.mNextIsOptional == false)
                                {
                                    throw new FileHelperException("The separator '" + this.mSeparator + "' can´t be found after the field '" + this.mFieldInfo.Name + "' (the record has less fields, the separator is wrong or the next field must be marked as optional).");
                                }
                                else
                                {
                                    sepPos = from.Length;
                                }
                            }

                            res = new ExtractedInfo(from.Substring(0, sepPos));
                        }
                    }
                    else if (from.Trim().StartsWith(quotedStr))
                    {
                        throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' has spaces before the QuotedChar in the data use the TrimAttribute to by pass this error. Field String: " + from);
                    }
                    else
                    {
                        throw new BadUsageException("The field '" + this.mFieldInfo.Name + "' not begin with the QuotedChar in the data. You can use FieldQuoted(QuoteMode.OptionalForRead) to allow optional quoted field.. Field String: " + from);
                    }
                }
            }


            return(res);
        }
        /// <include file='MultiRecordEngine.docs.xml' path='doc/ReadStream/*'/>
        public object[] ReadStream(IRecordReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "The reader of the Stream can´t be null");
            }

            if (mRecordSelector == null)
            {
                throw new BadUsageException("The Recordselector can´t be null, please pass a not null Selector in the constructor.");
            }

            ResetFields();
            mHeaderText = String.Empty;
            mFooterText = String.Empty;

            ArrayList resArray = new ArrayList();

            using (ForwardReader freader = new ForwardReader(reader, mMultiRecordInfo[0].mIgnoreLast))
            {
                freader.DiscardForward = true;

                string currentLine, completeLine;

                mLineNumber = 1;

                completeLine = freader.ReadNextLine();
                currentLine  = completeLine;

#if !MINI
                ProgressHelper.Notify(mNotifyHandler, mProgressMode, 0, -1);
#endif
                int currentRecord = 0;

                if (mMultiRecordInfo[0].mIgnoreFirst > 0)
                {
                    for (int i = 0; i < mMultiRecordInfo[0].mIgnoreFirst && currentLine != null; i++)
                    {
                        mHeaderText += currentLine + StringHelper.NewLine;
                        currentLine  = freader.ReadNextLine();
                        mLineNumber++;
                    }
                }


                bool byPass = false;

                //			MasterDetails record = null;
                ArrayList tmpDetails = new ArrayList();

                LineInfo line = new LineInfo(currentLine);
                line.mReader = freader;

                while (currentLine != null)
                {
                    try
                    {
                        mTotalRecords++;
                        currentRecord++;

                        line.ReLoad(currentLine);

                        bool skip = false;
#if !MINI
                        ProgressHelper.Notify(mNotifyHandler, mProgressMode, currentRecord, -1);
                        skip = OnBeforeReadRecord(currentLine);
#endif

                        Type currType = mRecordSelector(this, currentLine);

                        if (currType != null)
                        {
                            RecordInfo info = (RecordInfo)mRecordInfoHash[currType];

                            if (skip == false)
                            {
                                object[] values = new object[info.mFieldCount];
                                object   record = info.StringToRecord(line, values);

#if !MINI
                                skip = OnAfterReadRecord(currentLine, record);
#endif

                                if (skip == false && record != null)
                                {
                                    resArray.Add(record);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        switch (mErrorManager.ErrorMode)
                        {
                        case ErrorMode.ThrowException:
                            byPass = true;
                            throw;

                        case ErrorMode.IgnoreAndContinue:
                            break;

                        case ErrorMode.SaveAndContinue:
                            ErrorInfo err = new ErrorInfo();
                            err.mLineNumber    = freader.LineNumber;
                            err.mExceptionInfo = ex;
                            //							err.mColumnNumber = mColumnNum;
                            err.mRecordString = completeLine;

                            mErrorManager.AddError(err);
                            break;
                        }
                    }
                    finally
                    {
                        if (byPass == false)
                        {
                            currentLine  = freader.ReadNextLine();
                            completeLine = currentLine;
                            mLineNumber  = freader.LineNumber;
                        }
                    }
                }

                if (mMultiRecordInfo[0].mIgnoreLast > 0)
                {
                    mFooterText = freader.RemainingText;
                }
            }
            return(resArray.ToArray());
        }
Exemplo n.º 16
0
 protected abstract ExtractedInfo ExtractFieldString(string from, ForwardReader reader);
Exemplo n.º 17
0
        internal static ExtractedInfo ExtractQuotedString(string source, ForwardReader reader, char quoteChar)
        {
            StringBuilder res   = new StringBuilder(32);
            int           lines = 0;

            bool beginEscape = false;

            if (reader == null)
            {
                throw new BadUsageException("The reader can´t be null");
            }

            if (source == null || source.Length == 0)
            {
                throw new BadUsageException("An empty String found and can be parsed like a QuotedString try to use SafeExtractQuotedString");
            }


            if (source[0] != quoteChar)
            {
                throw new BadUsageException("The source string not begins with the quote char: " + quoteChar);
            }

            int  i            = 1;
            bool mustContinue = true;

            while (mustContinue && source != null)
            {
                while (i < source.Length)
                {
                    if (source[i] == quoteChar)
                    {
                        if (beginEscape == true)
                        {
                            beginEscape = false;
                            res.Append(quoteChar);
                        }
                        else
                        {
                            beginEscape = true;
                        }
                    }
                    else
                    {
                        if (beginEscape)
                        {
                            // End of the String
                            ExtractedInfo ei = new ExtractedInfo(res.ToString(), i, lines);
                            if (lines != 0)
                            {
                                ei.NewRestOfLine = source.Substring(i);
                            }
                            return(ei);
                        }
                        else
                        {
                            res.Append(source[i]);
                        }
                    }
                    i++;
                }


                if (beginEscape)
                {
                    return(new ExtractedInfo(res.ToString(), i + 1, lines));
                }
                else
                {
                    source = reader.ReadNextLine();
                    res.Append(StringHelper.NewLine);
                    lines++;
                    i = 0;
                }
            }

            throw new BadUsageException("The current field has an UnClosed quoted string. Complete Filed String: " + res.ToString());
        }
Exemplo n.º 18
0
        public T[] ReadStream(TextReader reader)
#endif
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "The reader of the Stream can´t be null");
            }

            ResetFields();
            mHeaderText = String.Empty;
            mFooterText = String.Empty;

            ArrayList resArray      = new ArrayList();
            int       currentRecord = 0;

            ForwardReader freader = new ForwardReader(reader, mRecordInfo.mIgnoreLast);

            freader.DiscardForward = true;

            string currentLine, completeLine;

            mLineNumber = 1;

            completeLine = freader.ReadNextLine();
            currentLine  = completeLine;

                        #if !MINI
            ProgressHelper.Notify(mNotifyHandler, mProgressMode, 0, -1);
                        #endif

            if (mRecordInfo.mIgnoreFirst > 0)
            {
                for (int i = 0; i < mRecordInfo.mIgnoreFirst && currentLine != null; i++)
                {
                    mHeaderText += currentLine + StringHelper.NewLine;
                    currentLine  = freader.ReadNextLine();
                    mLineNumber++;
                }
            }

            bool byPass = false;

            while (currentLine != null)
            {
                try
                {
                    mTotalRecords++;
                    currentRecord++;

                                        #if !MINI
                    ProgressHelper.Notify(mNotifyHandler, mProgressMode, currentRecord, -1);
                                        #endif

                    object record = mRecordInfo.StringToRecord(currentLine, freader);

                    if (record != null)
                    {
                        resArray.Add(record);
                    }
                }
                catch (Exception ex)
                {
                    switch (mErrorManager.ErrorMode)
                    {
                    case ErrorMode.ThrowException:
                        byPass = true;
                        throw;

                    case ErrorMode.IgnoreAndContinue:
                        break;

                    case ErrorMode.SaveAndContinue:
                        ErrorInfo err = new ErrorInfo();
                        err.mLineNumber    = freader.LineNumber;
                        err.mExceptionInfo = ex;
//							err.mColumnNumber = mColumnNum;
                        err.mRecordString = completeLine;

                        mErrorManager.AddError(err);
                        break;
                    }
                }
                finally
                {
                    if (byPass == false)
                    {
                        currentLine  = freader.ReadNextLine();
                        completeLine = currentLine;
                        mLineNumber++;
                    }
                }
            }

            if (mRecordInfo.mIgnoreLast > 0)
            {
                mFooterText = freader.RemainingText;
            }

#if !GENERICS
            return((object[])
#else
            return (T[])
#endif
                   resArray.ToArray(RecordType));
        }
        private T[] ReadStream(TextReader reader, int maxRecords, DataTable dt)
#endif
        {
#endif
            if (reader == null)
            {
                throw new ArgumentNullException("reader", "The reader of the Stream can´t be null");
            }
            NewLineDelimitedRecordReader recordReader = new NewLineDelimitedRecordReader(reader);

            ResetFields();
            mHeaderText = String.Empty;
            mFooterText = String.Empty;

            ArrayList resArray      = new ArrayList();
            int       currentRecord = 0;

            using (ForwardReader freader = new ForwardReader(recordReader, mRecordInfo.mIgnoreLast))
            {
                freader.DiscardForward = true;


                string currentLine, completeLine;

                mLineNumber = 1;

                completeLine = freader.ReadNextLine();
                currentLine  = completeLine;

#if !MINI
                ProgressHelper.Notify(mNotifyHandler, mProgressMode, 0, -1);
#endif

                if (mRecordInfo.mIgnoreFirst > 0)
                {
                    for (int i = 0; i < mRecordInfo.mIgnoreFirst && currentLine != null; i++)
                    {
                        mHeaderText += currentLine + StringHelper.NewLine;
                        currentLine  = freader.ReadNextLine();
                        mLineNumber++;
                    }
                }

                bool byPass = false;

                if (maxRecords < 0)
                {
                    maxRecords = int.MaxValue;
                }

                LineInfo line = new LineInfo(currentLine);
                line.mReader = freader;

                object[] values = new object[mRecordInfo.mFieldCount];
                while (currentLine != null && currentRecord < maxRecords)
                {
                    try
                    {
                        mTotalRecords++;
                        currentRecord++;

                        line.ReLoad(currentLine);

                        bool skip = false;
#if !MINI
                        ProgressHelper.Notify(mNotifyHandler, mProgressMode, currentRecord, -1);
#if !GENERICS
                        BeforeReadRecordEventArgs e = new BeforeReadRecordEventArgs(currentLine, LineNumber);
#else
                        BeforeReadRecordEventArgs <T> e = new BeforeReadRecordEventArgs <T>(currentLine, LineNumber);
#endif
                        skip = OnBeforeReadRecord(e);
                        if (e.RecordLineChanged)
                        {
                            line.ReLoad(e.RecordLine);
                        }
#endif

                        if (skip == false)
                        {
                            object record = mRecordInfo.StringToRecord(line, values);

#if !MINI
#if !GENERICS
                            skip = OnAfterReadRecord(currentLine, record);
#else
                            skip = OnAfterReadRecord(currentLine, (T)record);
#endif
#endif

                            if (skip == false && record != null)
                            {
#if MINI
                                resArray.Add(record);
#else
                                if (dt == null)
                                {
                                    resArray.Add(record);
                                }
                                else
                                {
                                    dt.Rows.Add(mRecordInfo.RecordToValues(record));
                                }
#endif
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        switch (mErrorManager.ErrorMode)
                        {
                        case ErrorMode.ThrowException:
                            byPass = true;
                            throw;

                        case ErrorMode.IgnoreAndContinue:
                            break;

                        case ErrorMode.SaveAndContinue:
                            ErrorInfo err = new ErrorInfo();
                            err.mLineNumber    = freader.LineNumber;
                            err.mExceptionInfo = ex;
                            //							err.mColumnNumber = mColumnNum;
                            err.mRecordString = completeLine;

                            mErrorManager.AddError(err);
                            break;
                        }
                    }
                    finally
                    {
                        if (byPass == false)
                        {
                            currentLine  = freader.ReadNextLine();
                            completeLine = currentLine;
                            mLineNumber++;
                        }
                    }
                }

                if (mRecordInfo.mIgnoreLast > 0)
                {
                    mFooterText = freader.RemainingText;
                }
            }

#if !GENERICS
            return((object[])
#else
            return (T[])
#endif
                   resArray.ToArray(RecordType));
        }