# HG changeset patch # User cin # Date 1414072209 -14400 # Node ID a43745f81f1064a48a4a788b9dac24a9a07fa3b1 # Parent dc4942d09e7445620b625df27ccd34a9816b14ba minor fixes diff -r dc4942d09e74 -r a43745f81f10 Implab/Diagnostics/Extensions.cs --- a/Implab/Diagnostics/Extensions.cs Thu Oct 23 01:13:57 2014 +0400 +++ b/Implab/Diagnostics/Extensions.cs Thu Oct 23 17:50:09 2014 +0400 @@ -10,6 +10,17 @@ TraceContext.Instance.Leave(); }); } + + public static IPromise EndLogicalOperation(this IPromise promise) { + Safe.ArgumentNotNull(promise, "promise"); + var op = TraceContext.Instance.DetachLogicalOperation(); + + return promise.Anyway(() => { + TraceContext.Instance.EnterLogicalOperation(op,true); + TraceLog.EndLogicalOperation(); + TraceContext.Instance.Leave(); + }); + } } } diff -r dc4942d09e74 -r a43745f81f10 Implab/Diagnostics/TraceContext.cs --- a/Implab/Diagnostics/TraceContext.cs Thu Oct 23 01:13:57 2014 +0400 +++ b/Implab/Diagnostics/TraceContext.cs Thu Oct 23 17:50:09 2014 +0400 @@ -41,9 +41,10 @@ } public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) { - LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.Attach, String.Format("{0} -> [{1}]", operation.Name, m_threadId))); + 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))); } public void StartLogicalOperation(string name) { @@ -61,15 +62,17 @@ } public LogicalOperation DetachLogicalOperation() { - var op = m_current.DetachLogicalOperation(); - LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("[{0}] -> {1}", m_threadId, op.Name))); - return op; + var prev = m_current.DetachLogicalOperation(); + 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; m_current = m_stack.Pop(); + LogChannel.Default.LogEvent(new TraceEvent(TraceEventType.Leave, String.Format("{0} -> {1}", prev.Name, CurrentOperation.Name))); } else { TraceLog.TraceWarning("Attemtp to leave the last operation context"); m_current = OperationContext.EMPTY; diff -r dc4942d09e74 -r a43745f81f10 Implab/Diagnostics/TraceEventType.cs --- a/Implab/Diagnostics/TraceEventType.cs Thu Oct 23 01:13:57 2014 +0400 +++ b/Implab/Diagnostics/TraceEventType.cs Thu Oct 23 17:50:09 2014 +0400 @@ -13,5 +13,7 @@ OperationCompleted, Attach, Detach, + Enter, + Leave } } diff -r dc4942d09e74 -r a43745f81f10 Implab/IPromiseT.cs --- a/Implab/IPromiseT.cs Thu Oct 23 01:13:57 2014 +0400 +++ b/Implab/IPromiseT.cs Thu Oct 23 17:50:09 2014 +0400 @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace Implab { public interface IPromise : IPromise { diff -r dc4942d09e74 -r a43745f81f10 Implab/Safe.cs --- a/Implab/Safe.cs Thu Oct 23 01:13:57 2014 +0400 +++ b/Implab/Safe.cs Thu Oct 23 17:50:09 2014 +0400 @@ -44,7 +44,7 @@ } [DebuggerStepThrough] - public static IPromise GuargPromise(Func action) { + public static IPromise InvokePromise(Func action) { ArgumentNotNull(action, "action"); var p = new Promise(); @@ -58,11 +58,11 @@ } [DebuggerStepThrough] - public static IPromise GuardPromise(Func> action) { + public static IPromise InvokePromise(Func> action) { ArgumentNotNull(action, "action"); try { - return action(); + return action() ?? Promise.ExceptionToPromise(new Exception("The action returned null")); } catch (Exception err) { return Promise.ExceptionToPromise(err); } diff -r dc4942d09e74 -r a43745f81f10 MonoPlay/Program.cs --- a/MonoPlay/Program.cs Thu Oct 23 01:13:57 2014 +0400 +++ b/MonoPlay/Program.cs Thu Oct 23 17:50:09 2014 +0400 @@ -6,6 +6,9 @@ namespace MonoPlay { class MainClass { public static void Main(string[] args) { + if (args == null) + throw new ArgumentNullException("args"); + var listener = new ConsoleTraceListener(true); listener.Subscribe(); @@ -13,12 +16,10 @@ TraceLog.StartLogicalOperation("program"); - Console.WriteLine("Hello World!"); - TraceLog.StartLogicalOperation("async"); AsyncPool.Invoke(() => { TraceLog.TraceInformation("Hello async"); - TraceLog.StartLogicalOperation(); + TraceLog.StartLogicalOperation("foo"); return 0; }) .EndLogicalOperation()