private void BeforeEvent(EngineBase sender, BeforeReadRecordEventArgs e)
        {
            if (e.RecordLine.StartsWith(" ") || e.RecordLine.StartsWith("-"))
            {
                e.SkipThisRecord = true;
            }

            before++;
        }
示例#2
0
        private static void BeforeReadRecord(EngineBase engine, BeforeReadRecordEventArgs e)
        {
            Console.WriteLine("--> Before read line: " + e.RecordLine);

            if (e.LineNumber == 2)
            {
                e.SkipThisRecord = true;
                Console.WriteLine("-->   skiping line 2");
            }
        }
示例#3
0
        private static void BeforeReadRecord(EngineBase engine, BeforeReadRecordEventArgs e)
        {
            Console.WriteLine("--> Before read line: " + e.RecordLine);

            if (e.LineNumber == 2)
            {
                e.SkipThisRecord = true;
                Console.WriteLine("-->   skiping line 2");
            }
        }
        private bool OnBeforeReadRecord(BeforeReadRecordEventArgs <T> e)
        {
            if (BeforeReadRecord != null)
            {
                BeforeReadRecord(this, e);

                return(e.SkipThisRecord);
            }

            return(false);
        }
        private bool OnBeforeReadRecord(string line)
        {
            if (BeforeReadRecord != null)
            {
                BeforeReadRecordEventArgs <object> e = null;
                e = new BeforeReadRecordEventArgs <object>(line, LineNumber);
                BeforeReadRecord(this, e);

                return(e.SkipThisRecord);
            }

            return(false);
        }
 private static void BeforeEventChange(EngineBase engine, BeforeReadRecordEventArgs e)
 {
     Assert.IsFalse(e.RecordLineChanged);
     e.RecordLine = "11121314901234";
     Assert.IsTrue(e.RecordLineChanged);
 }
 private void BeforeEvent2(EngineBase sender, BeforeReadRecordEventArgs e)
 {
     e.SkipThisRecord = true;
     before++;
 }
        private void ReadNextRecord()
        {
            string currentLine = mAsyncReader.ReadNextLine();

            mLineNumber++;

            bool byPass = false;

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


            LineInfo line = new LineInfo(string.Empty);
            line.mReader = mAsyncReader;

            if (mLastRecordValues == null)
            {
                mLastRecordValues = new object[mRecordInfo.mFieldCount];
            }

            while (true)
            {
                if (currentLine != null)
                {
                    try
                    {
                        mTotalRecords++;
                        line.ReLoad(currentLine);

                        bool skip = false;

#if !MINI
    #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)
                        {
#if !GENERICS
                            mLastRecord = mRecordInfo.StringToRecord(line, mLastRecordValues);
#else
                            mLastRecord = (T)mRecordInfo.StringToRecord(line, mLastRecordValues);
#endif

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

                            if (skip == false && mLastRecord != null)
                            {
                                byPass = true;
                                return;
                            }
                        }
                    }
                    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    = mAsyncReader.LineNumber;
                            err.mExceptionInfo = ex;
                            //							err.mColumnNumber = mColumnNum;
                            err.mRecordString = currentLine;

                            mErrorManager.AddError(err);
                            break;
                        }
                    }
                    finally
                    {
                        if (byPass == false)
                        {
                            currentLine = mAsyncReader.ReadNextLine();
                            mLineNumber = mAsyncReader.LineNumber;
                        }
                    }
                }
                else
                {
                    mLastRecordValues = null;

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


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

                    try
                    {
                        mAsyncReader.Close();
                        //mAsyncReader = null;
                    }
                    catch
                    {
                    }

                    return;
                }
            }
        }
示例#9
0
        private void BeforeEvent2(EngineBase sender, BeforeReadRecordEventArgs<SampleType> e)
		{
			e.SkipThisRecord = true;
			before++;
		}
示例#10
0
		private void BeforeEvent(EngineBase sender, BeforeReadRecordEventArgs<SampleType> e)
		{
			if (e.RecordLine.StartsWith(" ") || e.RecordLine.StartsWith("-"))
				e.SkipThisRecord = true;

			before++;
		}
        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));
        }
示例#12
0
 private static void BeforeEventChange(EngineBase engine, BeforeReadRecordEventArgs<object> e)
 {
     Assert.IsFalse(e.RecordLineChanged);
     e.RecordLine = "11121314901234";
     Assert.IsTrue(e.RecordLineChanged);
 }