Exemplo n.º 1
0
        /// <summary>
        /// Reads asynchronously from the stream, terminating as soon as the <paramref name="terminator"/> is located.
        /// </summary>
        /// <param name="terminator">The terminator.</param>
        /// <param name="timeout">The maximum time to wait.</param>
        /// <param name="millisecondSpin">The millisecond spin between each read from the stream.</param>
        /// <returns>Any text read from the stream.</returns>
        public async Task <string> TerminatedReadAsync(string terminator, TimeSpan timeout, int millisecondSpin)
        {
            Func <string, bool> isTerminated = (x) => Client.IsTerminatorLocated(terminator, x);
            string s = await this.TerminatedReadAsync(isTerminated, timeout, millisecondSpin);

            if (!isTerminated(s))
            {
                //System.Diagnostics.Debug.WriteLine("Failed to terminate '{0}' with '{1}'", s, terminator);
                s += terminator;
            }
            return(s);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads asynchronously from the stream, terminating as soon as the <paramref name="terminator"/> is located.
        /// </summary>
        /// <param name="terminator">The terminator.</param>
        /// <param name="timeout">The maximum time to wait.</param>
        /// <param name="millisecondSpin">The millisecond spin between each read from the stream.</param>
        /// <returns>Any text read from the stream.</returns>
        public async Task <string> TerminatedReadAsync(string terminator, TimeSpan timeout, int millisecondSpin)
        {
            Func <string, bool> isTerminated = (x) => Client.IsTerminatorLocated(terminator, x);
            string s = await this.TerminatedReadAsync(isTerminated, timeout, millisecondSpin);

            if (!isTerminated(s))
            {
                System.Console.WriteLine($"Failed to terminate '{s}' with '{terminator}'");
            }

            return(s);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads synchronously from the stream, terminating as soon as the <paramref name="terminator"/> is located.
        /// </summary>
        /// <param name="terminator">The terminator.</param>
        /// <param name="timeout">The maximum time to wait.</param>
        /// <param name="millisecondSpin">The millisecond spin between each read from the stream.</param>
        /// <returns>Any text read from the stream.</returns>
        public string TerminatedRead(string terminator, TimeSpan timeout, int millisecondSpin)
        {
            var endTimeout = DateTime.Now.Add(timeout);
            var s          = string.Empty;

            while (!Client.IsTerminatorLocated(terminator, s) && endTimeout >= DateTime.Now)
            {
                s += this.Read(TimeSpan.FromMilliseconds(millisecondSpin));
            }

            if (!Client.IsTerminatorLocated(terminator, s))
            {
                System.Diagnostics.Debug.Print(string.Format("Failed to terminate '{0}' with '{1}'", s, terminator));
            }

            return(s);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reads asynchronously from the stream, terminating as soon as the <paramref name="terminator"/> is located.
        /// </summary>
        /// <param name="terminator">The terminator.</param>
        /// <param name="timeout">The maximum time to wait.</param>
        /// <param name="millisecondSpin">The millisecond spin between each read from the stream.</param>
        /// <returns>Any text read from the stream.</returns>
        public async Task <string> TerminatedReadAsync(string terminator, TimeSpan timeout, int millisecondSpin)
        {
            DateTime endTimeout = DateTime.Now.Add(timeout);
            string   s          = string.Empty;

            while (!Client.IsTerminatorLocated(terminator, s) && endTimeout >= DateTime.Now)
            {
                s += await this.ReadAsync(TimeSpan.FromMilliseconds(millisecondSpin));
            }

            if (!Client.IsTerminatorLocated(terminator, s))
            {
                System.Diagnostics.Debug.Print("Failed to terminate '{0}' with '{1}'", s, terminator);
            }

            return(s);
        }