Mercurial > pub > ImplabNet
comparison Implab/Diagnostics/OperationContext.cs @ 134:04d4c92d0f28 v2
Improved logging
author | cin |
---|---|
date | Wed, 11 Feb 2015 02:12:15 +0300 |
parents | dc4942d09e74 |
children | ea485487a424 |
comparison
equal
deleted
inserted
replaced
133:6c49d02a9a05 | 134:04d4c92d0f28 |
---|---|
1 namespace Implab.Diagnostics { | 1 namespace Implab.Diagnostics { |
2 struct OperationContext { | 2 struct OperationContext { |
3 readonly LogicalOperation m_initial; | |
4 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false); | 3 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false); |
4 | |
5 LogicalOperation m_initial; | |
5 LogicalOperation m_current; | 6 LogicalOperation m_current; |
6 readonly bool m_ownership; | 7 bool m_ownership; |
7 | 8 |
8 public OperationContext(LogicalOperation operation, bool ownership) { | 9 public OperationContext(LogicalOperation operation, bool ownership) { |
9 Safe.ArgumentNotNull(operation, "operation"); | 10 Safe.ArgumentNotNull(operation, "operation"); |
10 | 11 |
11 m_initial = operation; | 12 m_initial = operation; |
37 } | 38 } |
38 | 39 |
39 return detached; | 40 return detached; |
40 } | 41 } |
41 | 42 |
42 public void EndLogicalOperation() { | 43 public LogicalOperation EndLogicalOperation() { |
43 if (m_current != m_initial) { | 44 var current = m_current; |
45 if (m_current != LogicalOperation.EMPTY && (m_current != m_initial || m_ownership)) { | |
44 m_current = m_current.Parent; | 46 m_current = m_current.Parent; |
45 } else if (m_current != LogicalOperation.EMPTY && m_ownership) { | 47 if (current == m_initial) { |
46 m_current = LogicalOperation.EMPTY; | 48 // we have complete the owned operation |
49 m_initial = m_current; | |
50 m_ownership = false; | |
51 } | |
47 } else { | 52 } else { |
48 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context"); | 53 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context"); |
49 } | 54 } |
55 return current; | |
50 } | 56 } |
51 | 57 |
52 public void Leave() { | 58 public void Leave() { |
53 | 59 |
54 if ((m_ownership && m_current != LogicalOperation.EMPTY) || (!m_ownership && m_current != m_initial) ) | 60 if ((m_ownership && m_current != LogicalOperation.EMPTY) || (!m_ownership && m_current != m_initial) ) |