//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define TRACE

using System;
using System.Reflection;
using System.Diagnostics;

#if !WASM
namespace CommonHelpers {
#else
namespace CommonHelpers.WASM {
#endif

//**************************************************************************************************
/// <summary>
/// </summary>
[HSyncOnlyDisposable]
public partial class HTrace: HDisposable {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public HTrace(string blockName)
{
   if (HAssembly.IsConfiguredForTrace( Assembly.GetCallingAssembly() ))
      _BlockTracer_ = new CodeBlockTracer(false,blockName);
   ValidateDisposable();
}

public HTrace(string blockNameFmt,params object[] parameters)
{
   if (HAssembly.IsConfiguredForTrace( Assembly.GetCallingAssembly() ))
      _BlockTracer_ = new CodeBlockTracer(false,blockNameFmt,parameters);
   ValidateDisposable();
}

public HTrace(MethodBase method)
{
   if (HAssembly.IsConfiguredForTrace( Assembly.GetCallingAssembly() ))
      _BlockTracer_ = new CodeBlockTracer(false,method);
   ValidateDisposable();
}

//==================================================================================================

[Conditional("TRACE")]
public static void Print(string message)
{
   Tracer.Print(message);
}

[Conditional("TRACE")]
public static void Print(string messageFmt,params object[] parameters)
{
   Tracer.Print(messageFmt,parameters);
}

[Conditional("TRACE")]
public static void Print(object obj)
{
   Tracer.Print(obj);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void Print(HTraceMessageCategory messageCategory,string message)
{
   Tracer.Print(messageCategory,message);
}

[Conditional("TRACE")]
public static void Print( HTraceMessageCategory messageCategory,
                          string messageFmt, params object[] parameters )
{
   Tracer.Print(messageCategory,messageFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void PrintInfo(string message)
{
   Tracer.PrintInformation(message);
}

[Conditional("TRACE")]
public static void PrintInfo(string messageFmt,params object[] parameters)
{
   Tracer.PrintInformation(messageFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void PrintWarning(string message)
{
   Tracer.PrintWarning(message);
}

[Conditional("TRACE")]
public static void PrintWarning(string messageFmt,params object[] parameters)
{
   Tracer.PrintWarning(messageFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void PrintError(string message)
{
   Tracer.PrintError(message);
}

[Conditional("TRACE")]
public static void PrintError(string messageFmt,params object[] parameters)
{
   Tracer.PrintError(messageFmt,parameters);
}

[Conditional("TRACE")]
public static void PrintError(Exception e)
{
   Tracer.PrintError(e);
}

//==================================================================================================

[Conditional("TRACE")]
public static void PrintOperation(string message)
{
   Tracer.PrintOperation(message);
}

[Conditional("TRACE")]
public static void PrintOperation(string messageFmt,params object[] parameters)
{
   Tracer.PrintOperation(messageFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void PrintOperation(bool informationCategory,string message)
{
   Tracer.PrintOperation(informationCategory,message);
}

[Conditional("TRACE")]
public static void PrintOperation( bool informationCategory,
                                   string messageFmt,
                                   params object[] parameters )
{
   Tracer.PrintOperation(informationCategory,messageFmt,parameters);
}

//==================================================================================================

[Conditional("TRACE")]
public static void DetailedPrint(string caption,string details)
{
   Tracer.DetailedPrint(caption,details);
}

[Conditional("TRACE")]
public static void DetailedPrint(string caption,string detailsFmt,params object[] parameters)
{
   Tracer.DetailedPrint(caption,detailsFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void DetailedPrint( HTraceMessageCategory messageCategory,
                                  string caption, string details )
{
   Tracer.DetailedPrint(messageCategory,caption,details);
}

[Conditional("TRACE")]
public static void DetailedPrint( HTraceMessageCategory messageCategory, string caption,
                                  string detailsFmt, params object[] parameters )
{
   Tracer.DetailedPrint(messageCategory,caption,detailsFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void DetailedPrintInfo(string caption,string details)
{
   Tracer.DetailedPrintInformation(caption,details);
}

[Conditional("TRACE")]
public static void DetailedPrintInfo( string caption,
                                      string detailsFmt,
                                      params object[] parameters )
{
   Tracer.DetailedPrintInformation(caption,detailsFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void DetailedPrintWarning(string caption,string details)
{
   Tracer.DetailedPrintWarning(caption,details);
}

[Conditional("TRACE")]
public static void DetailedPrintWarning( string caption,
                                         string detailsFmt,
                                         params object[] parameters )
{
   Tracer.DetailedPrintWarning(caption,detailsFmt,parameters);
}

//--------------------------------------------------------------------------------------------------

[Conditional("TRACE")]
public static void DetailedPrintError(string caption,string details)
{
   Tracer.DetailedPrintError(caption,details);
}

[Conditional("TRACE")]
public static void DetailedPrintError( string caption,
                                       string detailsFmt,
                                       params object[] parameters )
{
   Tracer.DetailedPrintError(caption,detailsFmt,parameters);
}

[Conditional("TRACE")]
public static void DetailedPrintError( HTraceMessageCategory messageCategory,
                                       string caption, Exception e )
{
   Tracer.DetailedPrintError(messageCategory,caption,e);
}

//==================================================================================================

protected override void OnDispose(bool synchronous)
{
   CodeBlockTracer.Dispose( _BlockTracer_ );
}

//==================================================================================================

static HTrace()
{
   CommonHelpers_Core.Access();
}

//==================================================================================================

internal static Tracer
   Tracer = new Tracer(false);

//==================================================================================================

CodeBlockTracer
   _BlockTracer_;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HTrace
//**************************************************************************************************

} // CommonHelpers (.WASM)
