using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Handbrake.Parsing
{
///
/// A delegate to handle custom events regarding data being parsed from the buffer
///
/// The object which raised this delegate
/// The data parsed from the stream
public delegate void DataReadEventHandler(object Sender, string Data);
///
/// A simple wrapper around a StreamReader to keep track of the entire output from a cli process
///
internal class Parser : StreamReader
{
private string m_buffer;
///
/// The output from the CLI process
///
public string Buffer
{
get
{
return this.m_buffer;
}
}
///
/// Raised upon a new line being read from stdout/stderr
///
public static event DataReadEventHandler OnReadLine;
///
/// Raised upon the entire stdout/stderr stream being read in a single call
///
public static event DataReadEventHandler OnReadToEnd;
public Parser(Stream baseStream) : base(baseStream)
{
this.m_buffer = string.Empty;
}
public override string ReadLine()
{
string tmp = base.ReadLine();
this.m_buffer += tmp;
if (OnReadLine != null)
{
OnReadLine(this, tmp);
}
return tmp;
}
public override string ReadToEnd()
{
string tmp = base.ReadToEnd();
this.m_buffer += tmp;
if (OnReadToEnd != null)
{
OnReadToEnd(this, tmp);
}
return tmp;
}
}
}