Mercurial > pub > ImplabNet
changeset 94:a43745f81f10 v2
minor fixes
author | cin |
---|---|
date | Thu, 23 Oct 2014 17:50:09 +0400 |
parents | dc4942d09e74 |
children | 0141a165d032 |
files | Implab/Diagnostics/Extensions.cs Implab/Diagnostics/TraceContext.cs Implab/Diagnostics/TraceEventType.cs Implab/IPromiseT.cs Implab/Safe.cs MonoPlay/Program.cs |
diffstat | 6 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- 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(); + }); + } } }
--- 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<TraceEvent>.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<TraceEvent>.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<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("[{0}] -> {1}", m_threadId, op.Name))); - return op; + var prev = m_current.DetachLogicalOperation(); + LogChannel<TraceEvent>.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<TraceEvent>.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;
--- 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 } }
--- 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<T> : IPromise {
--- 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<T> GuargPromise<T>(Func<T> action) { + public static IPromise<T> InvokePromise<T>(Func<T> action) { ArgumentNotNull(action, "action"); var p = new Promise<T>(); @@ -58,11 +58,11 @@ } [DebuggerStepThrough] - public static IPromise<T> GuardPromise<T>(Func<IPromise<T>> action) { + public static IPromise<T> InvokePromise<T>(Func<IPromise<T>> action) { ArgumentNotNull(action, "action"); try { - return action(); + return action() ?? Promise<T>.ExceptionToPromise(new Exception("The action returned null")); } catch (Exception err) { return Promise<T>.ExceptionToPromise(err); }
--- 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<TraceEvent>(); @@ -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()