Ejemplo n.º 1
0
        /// <summary>
        /// Read a single line from intake. In case of X12, the line means segment (so, CR/LF is not (necessarily) a delimiter).
        /// </summary>
        /// <returns>A tuple consisting of the line sequence number (1-based), source number (1-based) and the line read from intake; or null as EOD mark</returns>
        internal Tuple <int, int, ExternalLine> GetLineFromIntake()
        {
            // linePlus is a Tuple<ExternalLine,int>: Item1 = line, Item2 = source number
            // End-of-data indicators: * non-null linePlus.Item1 means data
            //                         * null linePlus.Item1 means end-of-data for a single source (only if asynchronous)
            //                         * null linePlus means end-of-data for all sources
            Tuple <ExternalLine, int> linePlus;

            do //note that this loop is for consistency with async intake from files where tuple with end-of-data mark denotes end of each source (but not the entire intake)
            {  // (even though in case of synchronous intake, tuples with null contents should not be received from LineFeeder or IntakeSupplier).
              //IOW, this loop should always execute a single iteration.
                linePlus = _intakeFromReader ? _intakeReader.GetNextLine() : _config.IntakeSupplier(_globalCache);
                Debug.Assert(linePlus == null || linePlus.Item1 != null);
            }while (linePlus != null && linePlus.Item1 == null); // ignore tuples with null lines (end-of-data marks for individual sources)

            if (linePlus == null)
            {
                return(null);                                  // EOD mark
            }
            var lineCnt = Interlocked.Increment(ref _lineCnt); // adjustment for header row(s) may be needed

            return(Tuple.Create(lineCnt, linePlus.Item2, linePlus.Item1));
        }