Mercurial > pub > ImplabNet
comparison Implab/Diagnostics/OperationContext.cs @ 192:f1da3afc3521 release v2.1
Слияние с v2
author | cin |
---|---|
date | Fri, 22 Apr 2016 13:10:34 +0300 |
parents | 04d4c92d0f28 |
children | ea485487a424 |
comparison
equal
deleted
inserted
replaced
71:1714fd8678ef | 192:f1da3afc3521 |
---|---|
1 namespace Implab.Diagnostics { | |
2 struct OperationContext { | |
3 public readonly static OperationContext EMPTY = new OperationContext(LogicalOperation.EMPTY, false); | |
4 | |
5 LogicalOperation m_initial; | |
6 LogicalOperation m_current; | |
7 bool m_ownership; | |
8 | |
9 public OperationContext(LogicalOperation operation, bool ownership) { | |
10 Safe.ArgumentNotNull(operation, "operation"); | |
11 | |
12 m_initial = operation; | |
13 m_current = operation; | |
14 m_ownership = ownership; | |
15 } | |
16 | |
17 public LogicalOperation CurrentOperation { | |
18 get { return m_current; } | |
19 } | |
20 | |
21 public void BeginLogicalOperation(string name) { | |
22 m_current = new LogicalOperation(name, m_current); | |
23 } | |
24 | |
25 public LogicalOperation DetachLogicalOperation() { | |
26 var detached = m_current; | |
27 if (m_current != LogicalOperation.EMPTY) { | |
28 if (m_current != m_initial) | |
29 m_current = m_current.Parent; | |
30 else if (m_ownership) | |
31 m_current = LogicalOperation.EMPTY; | |
32 else { | |
33 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context"); | |
34 detached = LogicalOperation.EMPTY; | |
35 } | |
36 } else { | |
37 TraceLog.TraceWarning("DetachLogicalOperation can't be applied in the current context"); | |
38 } | |
39 | |
40 return detached; | |
41 } | |
42 | |
43 public LogicalOperation EndLogicalOperation() { | |
44 var current = m_current; | |
45 if (m_current != LogicalOperation.EMPTY && (m_current != m_initial || m_ownership)) { | |
46 m_current = m_current.Parent; | |
47 if (current == m_initial) { | |
48 // we have complete the owned operation | |
49 m_initial = m_current; | |
50 m_ownership = false; | |
51 } | |
52 } else { | |
53 TraceLog.TraceWarning("EndLogicalOperation can't be applied in the current context"); | |
54 } | |
55 return current; | |
56 } | |
57 | |
58 public void Leave() { | |
59 | |
60 if ((m_ownership && m_current != LogicalOperation.EMPTY) || (!m_ownership && m_current != m_initial) ) | |
61 TraceLog.TraceWarning("Trying to leave unfinished logical operation {0}", m_current.Name); | |
62 } | |
63 } | |
64 } | |
65 |