2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2015-10-18 22:04:03 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : DicConsole.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-01-03 17:51:29 +00:00
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2015-10-18 22:04:03 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
namespace DiscImageChef.Console
|
|
|
|
|
{
|
|
|
|
|
public delegate void WriteLineHandler(string format, params object[] arg);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
public delegate void DebugWriteLineHandler(string format, params object[] arg);
|
|
|
|
|
|
|
|
|
|
public delegate void WriteHandler(string format, params object[] arg);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2015-10-18 22:04:03 +01:00
|
|
|
public delegate void DebugWriteHandler(string format, params object[] arg);
|
|
|
|
|
|
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>
|
2015-10-18 22:04:03 +01:00
|
|
|
public static class DicConsole
|
|
|
|
|
{
|
2018-08-27 18:25:11 +01:00
|
|
|
public static event WriteLineHandler WriteLineEvent;
|
|
|
|
|
public static event ErrorWriteLineHandler ErrorWriteLineEvent;
|
|
|
|
|
public static event VerboseWriteLineHandler VerboseWriteLineEvent;
|
|
|
|
|
public static event DebugWriteLineHandler DebugWriteLineEvent;
|
|
|
|
|
public static event DebugWithModuleWriteLineHandler DebugWithModuleWriteLineEvent;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
public static event WriteHandler WriteEvent;
|
|
|
|
|
public static event ErrorWriteHandler ErrorWriteEvent;
|
2015-10-18 22:04:03 +01:00
|
|
|
public static event VerboseWriteHandler VerboseWriteEvent;
|
2018-06-22 08:08:38 +01:00
|
|
|
public static event DebugWriteHandler DebugWriteEvent;
|
2015-10-18 22:04:03 +01:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void WriteLine() => WriteLineEvent?.Invoke("", null);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void ErrorWriteLine() => ErrorWriteLineEvent?.Invoke("", null);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void VerboseWriteLine() => VerboseWriteLineEvent?.Invoke("", null);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void DebugWriteLine() => DebugWriteLineEvent?.Invoke("", null);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void Write() => WriteEvent?.Invoke("", null);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void ErrorWrite() => ErrorWriteEvent?.Invoke("", null);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void VerboseWrite() => VerboseWriteEvent?.Invoke("", null);
|
2015-10-18 22:04:03 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void DebugWrite() => DebugWriteEvent?.Invoke("", null);
|
2015-10-19 01:37:23 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void WriteLine(string format) => WriteLineEvent?.Invoke("{0}", format);
|
2015-10-19 01:37:23 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void ErrorWriteLine(string format) => ErrorWriteLineEvent?.Invoke("{0}", format);
|
2015-10-19 01:37:23 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void VerboseWriteLine(string format) => VerboseWriteLineEvent?.Invoke("{0}", format);
|
2015-10-19 01:37:23 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
public static void DebugWriteLine(string module, string format) =>
|
2017-12-21 20:34:19 +00:00
|
|
|
DebugWriteLineEvent?.Invoke("{0}", "DEBUG (" + module + "): " + format);
|
2015-10-18 22:04:03 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|