comparison Implab/Diagnostics/OperationContext.cs @ 92:4c0e5ef99986 v2

rewritten tracing
author cin
date Wed, 22 Oct 2014 18:37:56 +0400
parents
children dc4942d09e74
comparison
equal deleted inserted replaced
91:cdaaf4792c22 92:4c0e5ef99986
1 namespace Implab.Diagnostics {
2 struct OperationContext {
3 readonly LogicalOperation m_initial;
4 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false);
5 LogicalOperation m_current;
6 readonly bool m_ownership;
7
8 public OperationContext(LogicalOperation operation, bool ownership) {
9 Safe.ArgumentNotNull(operation, "operation");
10
11 m_initial = operation;
12 m_current = operation;
13 m_ownership = ownership;
14 }
15
16 public LogicalOperation CurrentOperation {
17 get { return m_current; }
18 }
19
20 public void BeginLogicalOperation(string name) {
21 m_current = new LogicalOperation(name, m_current);
22 }
23
24 public LogicalOperation DetachLogicalOperation() {
25 var detached = m_current;
26 if (m_current != LogicalOperation.EMPTY) {
27 if (m_current != m_initial)
28 m_current = m_current.Parent;
29 else if (m_ownership)
30 m_current = LogicalOperation.EMPTY;
31 else
32 detached = LogicalOperation.EMPTY;
33 }
34 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
35 return detached;
36 }
37
38 public void EndLogicalOperation() {
39 if (m_current != m_initial) {
40 m_current = m_current.Parent;
41 } else if (m_current != null && m_ownership) {
42 m_current = null;
43 } else {
44 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context");
45 }
46 }
47 }
48 }
49