コード例 #1
0
        /// <summary>
        /// Asynchronously get next line and wait for a task (with a Tuple) to complete, ignoring tuples with nulls at end of each source.
        /// </summary>
        /// <param name="feeder">Feeder to read the line from (should be the 1st level LineFeeder, i.e. with LineFeederForSource as constituent feeders).</param>
        /// <returns>Tuple containing text line and a source number or null at end.</returns>
        internal static Tuple <ExternalLine, int> GetNextLineSynced(this ILineFeeder feeder)
        {
            var retVal = feeder.GetNextLineAsync().Result;

            // retVal here is null at the very end of the entire sequence produced by LineFeeder.
            // At end of each level of LineFeeder nesting (i.e. LineFeederForSource), it is a tuple containing null.
            // Note that this assumes a single level of nesting, where LineFeeder is fed by LineFeederForSource (and not by LineFeeders (recursively)).
            if (retVal == null)
            {
                return(null);
            }
            return(retVal.Item1 == null?GetNextLineSynced(feeder) : retVal);
        }
コード例 #2
0
        /// <summary>
        /// Asynchronously read a single line from intake
        /// </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 async Task <Tuple <int, int, ExternalLine> > GetLineFromIntakeAsync()
        {
            // TBD: Intake is from either text file(s) or IntakeSupplier function
            // 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
            {
                linePlus = _intakeFromReader ? await _intakeReader.GetNextLineAsync() : await _config.AsyncIntakeSupplier(null);
            }while (linePlus != null && linePlus.Item1 == null); // ignore tuples with null lines (which in case of async _intakeFromFile denote end of each file)

            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));
        }