-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathAaruConsole.cs
261 lines (222 loc) · 13.9 KB
/
AaruConsole.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : AaruConsole.cs
// Author(s) : Natalia Portillo <[email protected]>
//
// Component : Console.
//
// --[ Description ] ----------------------------------------------------------
//
// Handlers for normal, verbose and debug consoles.
//
// --[ License ] --------------------------------------------------------------
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2025 Natalia Portillo
// ****************************************************************************/
using System;
using System.Diagnostics.CodeAnalysis;
namespace Aaru.Console;
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the standard output console using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void WriteLineHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the error output console using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void ErrorWriteLineHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the verbose output console using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void VerboseWriteLineHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the debug output console using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void DebugWriteLineHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, to the standard output console using the
/// specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void WriteHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, to the error output console using the
/// specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void ErrorWriteHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, to the verbose output console using the
/// specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void VerboseWriteHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, to the debug output console using the
/// specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void DebugWriteHandler(string format, params object[] arg);
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the debug output console using the specified format information.
/// </summary>
/// <param name="module">Description of the module writing to the debug console</param>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public delegate void DebugWithModuleWriteLineHandler(string module, string format, params object[] arg);
/// <summary>
/// Writes the exception to the debug output console.
/// </summary>
/// <param name="ex">Exception.</param>
public delegate void WriteExceptionHandler(Exception ex);
/// <summary>
/// Implements a console abstraction that defines four level of messages that can be routed to different consoles:
/// standard, error, verbose and debug.
/// </summary>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class AaruConsole
{
/// <summary>Event to receive writings to the standard output console that should be followed by a line termination.</summary>
public static event WriteLineHandler WriteLineEvent;
/// <summary>Event to receive writings to the error output console that should be followed by a line termination.</summary>
public static event ErrorWriteLineHandler ErrorWriteLineEvent;
/// <summary>Event to receive writings to the verbose output console that should be followed by a line termination.</summary>
public static event VerboseWriteLineHandler VerboseWriteLineEvent;
/// <summary>Event to receive line terminations to the debug output console.</summary>
public static event DebugWriteLineHandler DebugWriteLineEvent;
/// <summary>Event to receive writings to the debug output console that should be followed by a line termination.</summary>
public static event DebugWithModuleWriteLineHandler DebugWithModuleWriteLineEvent;
/// <summary>Event to receive writings to the standard output console.</summary>
public static event WriteHandler WriteEvent;
/// <summary>Event to receive writings to the error output console.</summary>
public static event ErrorWriteHandler ErrorWriteEvent;
/// <summary>Event to receive writings to the verbose output console.</summary>
public static event VerboseWriteHandler VerboseWriteEvent;
/// <summary>Event to receive writings to the debug output console.</summary>
public static event DebugWriteHandler DebugWriteEvent;
/// <summary>Event to receive exceptions to write to the debug output console.</summary>
public static event WriteExceptionHandler WriteExceptionEvent;
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the standard output console using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void WriteLine(string format, params object[] arg) => WriteLineEvent?.Invoke(format, arg);
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the error output console using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void ErrorWriteLine(string format, params object[] arg) => ErrorWriteLineEvent?.Invoke(format, arg);
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the verbose output console using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void VerboseWriteLine(string format, params object[] arg) =>
VerboseWriteLineEvent?.Invoke(format, arg);
/// <summary>
/// Writes the text representation of the specified array of objects, followed by the current line terminator, to
/// the debug output console using the specified format information.
/// </summary>
/// <param name="module">Description of the module writing to the debug console</param>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void DebugWriteLine(string module, string format, params object[] arg)
{
DebugWriteLineEvent?.Invoke("DEBUG (" + module + "): " + format, arg);
DebugWithModuleWriteLineEvent?.Invoke(module, format, arg);
}
/// <summary>Writes the current line terminator to the standard output console.</summary>
public static void WriteLine() => WriteLineEvent?.Invoke("", null);
/// <summary>Writes the current line terminator to the error output console.</summary>
public static void ErrorWriteLine() => ErrorWriteLineEvent?.Invoke("", null);
/// <summary>Writes the current line terminator to the verbose output console.</summary>
public static void VerboseWriteLine() => VerboseWriteLineEvent?.Invoke("", null);
/// <summary>Writes the current line terminator to the debug output console.</summary>
public static void DebugWriteLine() => DebugWriteLineEvent?.Invoke("", null);
/// <summary>
/// Writes the text representation of the specified array of objects to the standard output console using the
/// specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void Write(string format, params object[] arg) => WriteEvent?.Invoke(format, arg);
/// <summary>
/// Writes the text representation of the specified array of objects to the error output console using the
/// specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void ErrorWrite(string format, params object[] arg) => ErrorWriteEvent?.Invoke(format, arg);
/// <summary>
/// Writes the text representation of the specified array of objects to the verbose output console using the
/// specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void VerboseWrite(string format, params object[] arg) => VerboseWriteEvent?.Invoke(format, arg);
/// <summary>
/// Writes the text representation of the specified array of objects to the debug output console using the
/// specified format information.
/// </summary>
/// <param name="module">Description of the module writing to the debug console</param>
/// <param name="format">A composite format string.</param>
/// <param name="arg">An array of objects to write using <paramref name="format" />.</param>
public static void DebugWrite(string module, string format, params object[] arg) =>
DebugWriteEvent?.Invoke("DEBUG (" + module + "): " + format, arg);
/// <summary>Writes the specified string value, followed by the current line terminator, to the standard output console.</summary>
/// <param name="value">The value to write.</param>
public static void WriteLine(string value) => WriteLineEvent?.Invoke("{0}", value);
/// <summary>Writes the specified string value, followed by the current line terminator, to the error output console.</summary>
/// <param name="value">The value to write.</param>
public static void ErrorWriteLine(string value) => ErrorWriteLineEvent?.Invoke("{0}", value);
/// <summary>Writes the specified string value, followed by the current line terminator, to the verbose output console.</summary>
/// <param name="value">The value to write.</param>
public static void VerboseWriteLine(string value) => VerboseWriteLineEvent?.Invoke("{0}", value);
/// <summary>Writes the specified string value, followed by the current line terminator, to the debug output console.</summary>
/// <param name="module">Description of the module writing to the debug console</param>
/// <param name="value">The value to write.</param>
public static void DebugWriteLine(string module, string value) =>
DebugWriteLineEvent?.Invoke("{0}", "DEBUG (" + module + "): " + value);
/// <summary>
/// Writes the exception to the debug output console.
/// </summary>
/// <param name="ex">Exception.</param>
public static void WriteException(Exception ex) => WriteExceptionEvent?.Invoke(ex);
}