annotate Implab/Diagnostics/Extensions.cs @ 109:1b7ebcc52e5a v2

minor fixes
author cin
date Fri, 14 Nov 2014 14:04:24 +0300
parents a43745f81f10
children 2573b562e328
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
1 namespace Implab.Diagnostics {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
2 public static class Extensions {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
3 public static IPromise<T> EndLogicalOperation<T>(this IPromise<T> promise) {
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
4 Safe.ArgumentNotNull(promise, "promise");
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
5 var op = TraceContext.Instance.DetachLogicalOperation();
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
6
109
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
7 return promise.Then<T>(
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
8 x => {
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
9 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
10 TraceLog.TraceInformation("promise = {0}", x);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
11 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
12 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
13 return x;
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
14 },
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
15 err =>{
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
16 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
17 TraceLog.TraceError("promise died {0}", err);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
18 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
19 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
20 throw new TransientPromiseException(err);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
21 },
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
22 () => {
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
23 TraceContext.Instance.EnterLogicalOperation(op,true);
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
24 TraceLog.TraceInformation("promise cancelled");
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
25 TraceLog.EndLogicalOperation();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
26 TraceContext.Instance.Leave();
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
27 }
1b7ebcc52e5a minor fixes
cin
parents: 94
diff changeset
28 );
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
29 }
94
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
30
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
31 public static IPromise EndLogicalOperation(this IPromise promise) {
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
32 Safe.ArgumentNotNull(promise, "promise");
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
33 var op = TraceContext.Instance.DetachLogicalOperation();
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
34
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
35 return promise.Anyway(() => {
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
36 TraceContext.Instance.EnterLogicalOperation(op,true);
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
37 TraceLog.EndLogicalOperation();
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
38 TraceContext.Instance.Leave();
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
39 });
a43745f81f10 minor fixes
cin
parents: 92
diff changeset
40 }
92
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
41 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
42 }
4c0e5ef99986 rewritten tracing
cin
parents:
diff changeset
43