Mercurial > pub > ImplabNet
comparison Implab/Diagnostics/TraceContext.cs @ 52:edf0bc558596
improved trace system
| author | cin |
|---|---|
| date | Mon, 05 May 2014 07:35:48 +0400 |
| parents | d9d794b61bb9 |
| children | 790e8a997d30 |
comparison
equal
deleted
inserted
replaced
| 51:2c332a9c64c0 | 52:edf0bc558596 |
|---|---|
| 114 /// <summary> | 114 /// <summary> |
| 115 /// Создает постоянную копию текущего контекста, данную копию можно хранить и использовать для передачи через <see cref="Fork(TraceContext)"/> | 115 /// Создает постоянную копию текущего контекста, данную копию можно хранить и использовать для передачи через <see cref="Fork(TraceContext)"/> |
| 116 /// </summary> | 116 /// </summary> |
| 117 /// <returns>Копия текущего контекста трассировки.</returns> | 117 /// <returns>Копия текущего контекста трассировки.</returns> |
| 118 public static TraceContext Snapshot() { | 118 public static TraceContext Snapshot() { |
| 119 return _current == null ? new TraceContext() : new TraceContext(_current); | 119 return _current == null ? new TraceContext() : new TraceContext(_current,false); |
| 120 } | 120 } |
| 121 | 121 |
| 122 /// <summary> | 122 /// <summary> |
| 123 /// Выполняет переданное действие в указанном контексте трассировки, по окончании восстанавливает предыдущий контекст трассировки потока. | 123 /// Выполняет переданное действие в указанном контексте трассировки, по окончании восстанавливает предыдущий контекст трассировки потока. |
| 124 /// </summary> | 124 /// </summary> |
| 129 var old = _current; | 129 var old = _current; |
| 130 Fork(this); | 130 Fork(this); |
| 131 try { | 131 try { |
| 132 action(); | 132 action(); |
| 133 } finally { | 133 } finally { |
| 134 _current.EndAllOperations(); | 134 if(_current != null) |
| 135 _current.EndAllOperations(); | |
| 135 _current = old; | 136 _current = old; |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 | 139 |
| 139 /// <summary> | 140 /// <summary> |
| 195 m_currentOperation = m_currentOperation.Parent; | 196 m_currentOperation = m_currentOperation.Parent; |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 | 199 |
| 199 /// <summary> | 200 /// <summary> |
| 201 /// Создает копию контекста и возвращается на предыдущую операцию в текущем контексте, это позволяет начать операцию в одном потоке, а завершить - в другом. | |
| 202 /// </summary> | |
| 203 /// <returns>Контекст трассировки, который можно присоединить к другому потоку.</returns> | |
| 204 public TraceContext DetachLogicalOperation() { | |
| 205 if (m_bound == m_currentOperation) { | |
| 206 return new TraceContext(); | |
| 207 } else { | |
| 208 var detached = new TraceContext(this, true); | |
| 209 m_currentOperation = m_currentOperation.Parent; | |
| 210 return detached; | |
| 211 } | |
| 212 } | |
| 213 | |
| 214 public void BindLogicalOperationToPromise(IPromiseBase promise) { | |
| 215 Safe.ArgumentNotNull(promise, "promise"); | |
| 216 | |
| 217 var ctx = DetachLogicalOperation(); | |
| 218 promise.Finally(() => { | |
| 219 var old = _current; | |
| 220 TraceContext.Attach(ctx); | |
| 221 TraceContext.Current.EndLogicalOperation(); | |
| 222 _current = old; | |
| 223 }); | |
| 224 } | |
| 225 | |
| 226 /// <summary> | |
| 200 /// Заврешает все начатые в этом контексте операции | 227 /// Заврешает все начатые в этом контексте операции |
| 201 /// </summary> | 228 /// </summary> |
| 202 public void EndAllOperations() { | 229 public void EndAllOperations() { |
| 203 while (m_bound != m_currentOperation) | 230 while (m_bound != m_currentOperation) |
| 204 EndLogicalOperation(); | 231 EndLogicalOperation(); |
