2017-05-19 20:28:49 +01:00
// /***************************************************************************
2020-02-27 12:31:23 +00:00
// Aaru Data Preservation Suite
2015-10-18 22:04:03 +01:00
// ----------------------------------------------------------------------------
//
2020-02-27 23:48:40 +00:00
// Filename : AaruConsole.cs
2016-07-28 18:13:49 +01:00
// Author(s) : Natalia Portillo <claunia@claunia.com>
2015-10-18 22:04:03 +01:00
//
2016-07-28 18:13:49 +01:00
// Component : Console.
2015-10-18 22:04:03 +01:00
//
// --[ Description ] ----------------------------------------------------------
//
2016-07-28 18:13:49 +01:00
// Handlers for normal, verbose and debug consoles.
2015-10-18 22:04:03 +01:00
//
// --[ License ] --------------------------------------------------------------
//
2016-07-28 18:13:49 +01:00
// 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
2015-10-18 22:04:03 +01:00
// License, or (at your option) any later version.
//
2016-07-28 18:13:49 +01:00
// 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.
2015-10-18 22:04:03 +01:00
//
2016-07-28 18:13:49 +01:00
// 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/>.
2015-10-18 22:04:03 +01:00
//
// ----------------------------------------------------------------------------
2020-12-31 23:08:22 +00:00
// Copyright © 2011-2021 Natalia Portillo
2015-10-18 22:04:03 +01:00
// ****************************************************************************/
2016-07-28 18:13:49 +01:00
2020-02-27 00:33:24 +00:00
namespace Aaru.Console
2015-10-18 22:04:03 +01:00
{
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void WriteLineHandler ( string format , params object [ ] arg ) ;
2017-12-19 20:33:03 +00:00
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void ErrorWriteLineHandler ( string format , params object [ ] arg ) ;
2017-12-19 20:33:03 +00:00
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void VerboseWriteLineHandler ( string format , params object [ ] arg ) ;
2017-12-19 20:33:03 +00:00
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void DebugWriteLineHandler ( string format , params object [ ] arg ) ;
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void WriteHandler ( string format , params object [ ] arg ) ;
2017-12-19 20:33:03 +00:00
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void ErrorWriteHandler ( string format , params object [ ] arg ) ;
2017-12-19 20:33:03 +00:00
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void VerboseWriteHandler ( string format , params object [ ] arg ) ;
2017-12-19 20:33:03 +00:00
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public delegate void DebugWriteHandler ( string format , params object [ ] arg ) ;
2021-08-17 13:56:04 +01:00
/// <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>
2018-08-27 18:25:11 +01:00
public delegate void DebugWithModuleWriteLineHandler ( string module , string format , params object [ ] arg ) ;
2017-12-23 01:46:08 +00:00
/// <summary>
2017-12-23 16:46:52 +00:00
/// Implements a console abstraction that defines four level of messages that can be routed to different consoles:
/// standard, error, verbose and debug.
2017-12-23 01:46:08 +00:00
/// </summary>
2020-02-27 23:48:40 +00:00
public static class AaruConsole
2015-10-18 22:04:03 +01:00
{
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the standard output console that should be followed by a line termination.</summary>
2018-08-27 18:25:11 +01:00
public static event WriteLineHandler WriteLineEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the error output console that should be followed by a line termination.</summary>
2018-08-27 18:25:11 +01:00
public static event ErrorWriteLineHandler ErrorWriteLineEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the verbose output console that should be followed by a line termination.</summary>
2018-08-27 18:25:11 +01:00
public static event VerboseWriteLineHandler VerboseWriteLineEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive line terminations to the debug output console.</summary>
2018-08-27 18:25:11 +01:00
public static event DebugWriteLineHandler DebugWriteLineEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the debug output console that should be followed by a line termination.</summary>
2018-08-27 18:25:11 +01:00
public static event DebugWithModuleWriteLineHandler DebugWithModuleWriteLineEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the standard output console.</summary>
2018-06-22 08:08:38 +01:00
public static event WriteHandler WriteEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the error output console.</summary>
2018-06-22 08:08:38 +01:00
public static event ErrorWriteHandler ErrorWriteEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the verbose output console.</summary>
2015-10-18 22:04:03 +01:00
public static event VerboseWriteHandler VerboseWriteEvent ;
2021-08-17 13:56:04 +01:00
/// <summary>Event to receive writings to the debug output console.</summary>
2018-06-22 08:08:38 +01:00
public static event DebugWriteHandler DebugWriteEvent ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2019-11-25 00:54:38 +00:00
public static void WriteLine ( string format , params object [ ] arg ) = > WriteLineEvent ? . Invoke ( format , arg ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2019-11-25 00:54:38 +00:00
public static void ErrorWriteLine ( string format , params object [ ] arg ) = >
2017-12-21 20:34:19 +00:00
ErrorWriteLineEvent ? . Invoke ( format , arg ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2019-11-25 00:54:38 +00:00
public static void VerboseWriteLine ( string format , params object [ ] arg ) = >
2017-12-21 20:34:19 +00:00
VerboseWriteLineEvent ? . Invoke ( format , arg ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2015-10-18 22:04:03 +01:00
public static void DebugWriteLine ( string module , string format , params object [ ] arg )
{
2017-12-21 20:34:19 +00:00
DebugWriteLineEvent ? . Invoke ( "DEBUG (" + module + "): " + format , arg ) ;
2018-08-27 18:25:11 +01:00
DebugWithModuleWriteLineEvent ? . Invoke ( module , format , arg ) ;
2015-10-18 22:04:03 +01:00
}
2021-08-17 13:56:04 +01:00
/// <summary>Writes the current line terminator to the standard output console.</summary>
2019-11-25 00:54:38 +00:00
public static void WriteLine ( ) = > WriteLineEvent ? . Invoke ( "" , null ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <summary>Writes the current line terminator to the error output console.</summary>
2019-11-25 00:54:38 +00:00
public static void ErrorWriteLine ( ) = > ErrorWriteLineEvent ? . Invoke ( "" , null ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <summary>Writes the current line terminator to the verbose output console.</summary>
2019-11-25 00:54:38 +00:00
public static void VerboseWriteLine ( ) = > VerboseWriteLineEvent ? . Invoke ( "" , null ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <summary>Writes the current line terminator to the debug output console.</summary>
2019-11-25 00:54:38 +00:00
public static void DebugWriteLine ( ) = > DebugWriteLineEvent ? . Invoke ( "" , null ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2019-11-25 00:54:38 +00:00
public static void Write ( string format , params object [ ] arg ) = > WriteEvent ? . Invoke ( format , arg ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2019-11-25 00:54:38 +00:00
public static void ErrorWrite ( string format , params object [ ] arg ) = > ErrorWriteEvent ? . Invoke ( format , arg ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2019-11-25 00:54:38 +00:00
public static void VerboseWrite ( string format , params object [ ] arg ) = > VerboseWriteEvent ? . Invoke ( format , arg ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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>
2019-11-25 00:54:38 +00:00
public static void DebugWrite ( string module , string format , params object [ ] arg ) = >
2017-12-21 20:34:19 +00:00
DebugWriteEvent ? . Invoke ( "DEBUG (" + module + "): " + format , arg ) ;
2015-10-18 22:04:03 +01:00
2021-08-17 13:56:04 +01:00
/// <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 ) ;
2015-10-18 22:04:03 +01:00
}
2017-12-19 20:33:03 +00:00
}