OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Parsing / Parser.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.IO;\r
5 \r
6 namespace Handbrake.Parsing\r
7 {\r
8     /// <summary>\r
9     /// A delegate to handle custom events regarding data being parsed from the buffer\r
10     /// </summary>\r
11     /// <param name="Sender">The object which raised this delegate</param>\r
12     /// <param name="Data">The data parsed from the stream</param>\r
13     public delegate void DataReadEventHandler(object Sender, string Data);\r
14 \r
15     /// <summary>\r
16     /// A simple wrapper around a StreamReader to keep track of the entire output from a cli process\r
17     /// </summary>\r
18     internal class Parser : StreamReader\r
19     {\r
20         private string m_buffer;\r
21         /// <summary>\r
22         /// The output from the CLI process\r
23         /// </summary>\r
24         public string Buffer\r
25         {\r
26             get\r
27             {\r
28                 return this.m_buffer;\r
29             }\r
30         }\r
31 \r
32         /// <summary>\r
33         /// Raised upon a new line being read from stdout/stderr\r
34         /// </summary>\r
35         public static event DataReadEventHandler OnReadLine;\r
36 \r
37         /// <summary>\r
38         /// Raised upon the entire stdout/stderr stream being read in a single call\r
39         /// </summary>\r
40         public static event DataReadEventHandler OnReadToEnd;\r
41 \r
42         public Parser(Stream baseStream) : base(baseStream)\r
43         {\r
44             this.m_buffer = string.Empty;\r
45         }\r
46 \r
47         public override string ReadLine()\r
48         {\r
49             string tmp = base.ReadLine();\r
50             this.m_buffer += tmp;\r
51             if (OnReadLine != null)\r
52             {\r
53                 OnReadLine(this, tmp);\r
54             }\r
55             return tmp;\r
56         }\r
57 \r
58         public override string ReadToEnd()\r
59         {\r
60             string tmp = base.ReadToEnd();\r
61             this.m_buffer += tmp;\r
62             if (OnReadToEnd != null)\r
63             {\r
64                 OnReadToEnd(this, tmp);\r
65             }\r
66             return tmp;\r
67         }\r
68     }\r
69 }\r