diff --git a/Implab/Diagnostics/ConsoleTraceListener.cs b/Implab/Diagnostics/ConsoleTraceListener.cs --- a/Implab/Diagnostics/ConsoleTraceListener.cs +++ b/Implab/Diagnostics/ConsoleTraceListener.cs @@ -23,10 +23,10 @@ namespace Implab.Diagnostics { for (int i = 0; i < text.indent; i++) msg.Append(" "); - msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, channel, text.content); + msg.AppendFormat("[{0}]: {1}", args.ThreadId, text.content); lock (_consoleLock) { - //Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1); + Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1); Console.WriteLine(msg); } } diff --git a/Implab/Diagnostics/TraceContext.cs b/Implab/Diagnostics/TraceContext.cs --- a/Implab/Diagnostics/TraceContext.cs +++ b/Implab/Diagnostics/TraceContext.cs @@ -41,10 +41,10 @@ namespace Implab.Diagnostics { } public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) { - var prev = CurrentOperation; + //var prev = CurrentOperation; m_stack.Push(m_current); m_current = new OperationContext(operation, takeOwnership); - LogChannel.Default.LogEvent(new TraceEvent(takeOwnership ? TraceEventType.Attach : TraceEventType.Enter, String.Format("{0} -> {1}",prev.Name, operation.Name))); + //LogChannel.Default.LogEvent(new TraceEvent(takeOwnership ? TraceEventType.Attach : TraceEventType.Enter, String.Format("{0} -> {1}",prev.Name, operation.Name))); } public void StartLogicalOperation(string name) { @@ -63,16 +63,16 @@ namespace Implab.Diagnostics { public LogicalOperation DetachLogicalOperation() { var prev = m_current.DetachLogicalOperation(); - LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("{0} -> {1}",prev.Name, CurrentOperation.Name))); + //LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("{0} -> {1}",prev.Name, CurrentOperation.Name))); return prev; } public void Leave() { if (m_stack.Count > 0) { m_current.Leave(); - var prev = CurrentOperation; + //var prev = CurrentOperation; m_current = m_stack.Pop(); - LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.Leave, String.Format("{0} -> {1}", prev.Name, CurrentOperation.Name))); + //LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.Leave, String.Format("{0} -> {1}", prev.Name, CurrentOperation.Name))); } else { TraceLog.TraceWarning("Attempt to leave the last operation context"); m_current = OperationContext.EMPTY; diff --git a/Implab/Diagnostics/TraceEvent.cs b/Implab/Diagnostics/TraceEvent.cs --- a/Implab/Diagnostics/TraceEvent.cs +++ b/Implab/Diagnostics/TraceEvent.cs @@ -18,7 +18,8 @@ namespace Implab.Diagnostics { } public override string ToString() { - return EventType == TraceEventType.Information ? Message : String.Format("{0}: {1}", EventType, Message); + /*return EventType == TraceEventType.Information ? Message : String.Format("{0}: {1}", EventType, Message);*/ + return Message; } public static TraceEvent Create(TraceEventType type, string format, params object[] args) { diff --git a/Implab/Safe.cs b/Implab/Safe.cs --- a/Implab/Safe.cs +++ b/Implab/Safe.cs @@ -89,15 +89,19 @@ namespace Implab public static IPromise InvokePromise(Func action) { ArgumentNotNull(action, "action"); - var p = new Promise(); try { - action(); - p.Resolve(); + var p = action(); + if (p == null) { + var d = new Promise(); + d.Reject(new Exception("The action returned null")); + p = d; + } + return p; } catch (Exception err) { + var p = new Promise(); p.Reject(err); + return p; } - - return p; } [DebuggerStepThrough]