//
// Authors:
// Jonathan Pryor (jonpryor@vt.edu)
+// Atsushi Enomoto (atsushi@ximian.com)
//
// Comments from John R. Hicks <angryjohn69@nc.rr.com> original implementation
// can be found at: /mcs/docs/apidocs/xml/en/System.Diagnostics
//
// (C) 2002 Jonathan Pryor
+// (C) 2007 Novell, Inc.
//
//
using System.IO;
using System.Collections;
using System.Diagnostics;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Threading;
namespace System.Diagnostics {
-
- [ComVisible(false)]
public class DefaultTraceListener : TraceListener {
private static readonly bool OnWin32;
OnWin32 = (Path.DirectorySeparatorChar == '\\');
if (!OnWin32) {
+#if TARGET_JVM
+ string trace = java.lang.System.getProperty("MONO_TRACE");
+#else
// If we're running on Unix, we don't have OutputDebugString.
// Instead, send output to...wherever the MONO_TRACE_LISTENER environment
// variables says to.
String trace = Environment.GetEnvironmentVariable("MONO_TRACE_LISTENER");
+#endif
+
+#if MOBILE
+ if (trace == null)
+ trace = ConsoleOutTrace;
+#endif
if (trace != null) {
string file = null;
{
}
- // It's hard to do anything with a UI when we don't have Windows.Forms...
- [MonoTODO]
+ [MonoTODO ("AssertUiEnabled defaults to False; should follow Environment.UserInteractive.")]
public bool AssertUiEnabled {
- get {return assertUiEnabled;}
- set {/* ignore */}
+ get { return assertUiEnabled; }
+ set { assertUiEnabled = value; }
}
[MonoTODO]
public override void Fail (string message)
{
base.Fail (message);
- WriteLine (new StackTrace().ToString());
}
public override void Fail (string message, string detailMessage)
{
base.Fail (message, detailMessage);
+ if (ProcessUI (message, detailMessage) == DialogResult.Abort)
+ Thread.CurrentThread.Abort ();
WriteLine (new StackTrace().ToString());
}
+ DialogResult ProcessUI (string message, string detailMessage)
+ {
+
+ if (!AssertUiEnabled)
+ return DialogResult.None;
+
+ object messageBoxButtonsAbortRetryIgnore;
+ MethodInfo msgboxShow;
+
+ try {
+ Assembly wfAsm = Assembly.Load (Consts.AssemblySystem_Windows_Forms);
+ if (wfAsm == null)
+ return DialogResult.None;
+
+ Type buttons = wfAsm.GetType ("System.Windows.Forms.MessageBoxButtons");
+ messageBoxButtonsAbortRetryIgnore = Enum.Parse (buttons, "AbortRetryIgnore");
+ msgboxShow = wfAsm.GetType ("System.Windows.Forms.MessageBox").GetMethod (
+ "Show",
+ new Type [] {typeof (string), typeof (string), buttons});
+ } catch {
+ return DialogResult.None;
+ }
+
+ if (msgboxShow == null || messageBoxButtonsAbortRetryIgnore == null)
+ return DialogResult.None;
+
+ string caption = String.Format ("Assertion Failed: {0} to quit, {1} to debug, {2} to continue", "Abort", "Retry", "Ignore");
+ string msg = String.Format ("{0}{1}{2}{1}{1}{3}", message, Environment.NewLine, detailMessage, new StackTrace ());
+
+ switch (msgboxShow.Invoke (null, new object [] {msg, caption, messageBoxButtonsAbortRetryIgnore}).ToString ()) {
+ case "Ignore":
+ return DialogResult.Ignore;
+ case "Abort":
+ return DialogResult.Abort;
+ default:
+ return DialogResult.Retry;
+ }
+ }
+
+ enum DialogResult {
+ None,
+ Retry,
+ Ignore,
+ Abort
+ }
+
+#if TARGET_JVM
+ private void WriteDebugString (string message)
+ {
+#else
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern static void WriteWindowsDebugString (string message);
if (OnWin32)
WriteWindowsDebugString (message);
else
+#endif
WriteMonoTrace (message);
}