summaryrefslogtreecommitdiffstats
path: root/win/C#/Parsing/Parser.cs
blob: 7cda4178cedd088d7cc36f27e318b8d2101d99a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Handbrake.Parsing
{
    public delegate void DataReadEventHandler(object Sender, string Data);
    /// <summary>
    /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process
    /// </summary>
    internal class Parser : StreamReader
    {
        /// <summary>
        /// The output from the CLI process
        /// </summary>
        private string m_buffer;
        public string Buffer
        {
            get
            {
                return this.m_buffer;
            }
        }

        public static event DataReadEventHandler OnReadLine;
        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;
        }
    }
}