Пример #1
0
        /// <summary>
        /// Creates an observable sequence by reading lines to the end of the specified <paramref name="reader"/> each time
        /// the <paramref name="textAvailable"/> sequence notifies that additional text is available to be read
        /// and advances the position within the reader to the end of the stream.
        /// </summary>
        /// <typeparam name="TOther">The type of elements in the sequence that notifies when text is available to be read.</typeparam>
        /// <param name="reader">The object from which lines are read as they become available.</param>
        /// <param name="textAvailable">An observable sequence that notifies when additional text is available to be read.</param>
        /// <remarks>
        /// <para>
        /// The <paramref name="textAvailable"/> sequence does not have to notify when new lines are available.  It only must notify when
        /// new text is available, which may or may not have new lines.  Characters that are read up to the end of the stream are automatically
        /// buffered until a new line sequence is encountered in a subsequent read.  A consequence of this behavior is that if the stream does
        /// not end with a new line sequence and it's not going to receive any more text, then the last line will not be read until
        /// <paramref name="textAvailable"/> calls <strong>OnCompleted</strong>.
        /// </para>
        /// <para>
        /// The generated sequence is intended to match the underlying stream; however, this behavior
        /// depends on whether the reader is well-behaved and whether the reader is not being shared.  Reading always starts from the
        /// current position of the reader in the underlying stream.  The reader is expected to increment its position in the stream
        /// when it's read.  Each time that the <paramref name="textAvailable"/> sequence notifies that additional text is available,
        /// reading is expected to begin at the previous position in the stream, but if the reader is shared or it's not well-behaved,
        /// then the generated sequence may contain unexpected data.
        /// </para>
        /// </remarks>
        /// <returns>An observable sequence of lines read from the specified <paramref name="reader"/>.</returns>
        public static IObservable <string> ToObservableLines <TOther>(this TextReader reader, IObservable <TOther> textAvailable)
        {
            Contract.Requires(reader != null);
            Contract.Requires(textAvailable != null);
            Contract.Ensures(Contract.Result <IObservable <string> >() != null);

            return(reader.ToObservableLines(textAvailable, Scheduler.CurrentThread));
        }