annotate Implab/Diagnostics/LogicalOperation.cs @ 44:e5ec543feee3

Рефакторинг, журналирование
author cin
date Wed, 16 Apr 2014 19:02:58 +0400
parents 2880242f987a
children 4c0e5ef99986
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
35
2880242f987a initial log capabilities
cin
parents:
diff changeset
1 using System;
2880242f987a initial log capabilities
cin
parents:
diff changeset
2 using System.Collections.Generic;
2880242f987a initial log capabilities
cin
parents:
diff changeset
3 using System.Linq;
2880242f987a initial log capabilities
cin
parents:
diff changeset
4 using System.Text;
2880242f987a initial log capabilities
cin
parents:
diff changeset
5 using System.Threading.Tasks;
2880242f987a initial log capabilities
cin
parents:
diff changeset
6
2880242f987a initial log capabilities
cin
parents:
diff changeset
7 namespace Implab.Diagnostics {
2880242f987a initial log capabilities
cin
parents:
diff changeset
8 public class LogicalOperation {
2880242f987a initial log capabilities
cin
parents:
diff changeset
9 readonly LogicalOperation m_parent;
2880242f987a initial log capabilities
cin
parents:
diff changeset
10 readonly string m_name;
2880242f987a initial log capabilities
cin
parents:
diff changeset
11 readonly int m_level;
2880242f987a initial log capabilities
cin
parents:
diff changeset
12 readonly int m_timestamp;
2880242f987a initial log capabilities
cin
parents:
diff changeset
13
2880242f987a initial log capabilities
cin
parents:
diff changeset
14 public LogicalOperation()
2880242f987a initial log capabilities
cin
parents:
diff changeset
15 : this(null, null) {
2880242f987a initial log capabilities
cin
parents:
diff changeset
16 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
17
2880242f987a initial log capabilities
cin
parents:
diff changeset
18 public LogicalOperation(string name, LogicalOperation parent) {
2880242f987a initial log capabilities
cin
parents:
diff changeset
19 m_name = name ?? String.Empty;
2880242f987a initial log capabilities
cin
parents:
diff changeset
20 m_parent = parent;
2880242f987a initial log capabilities
cin
parents:
diff changeset
21
2880242f987a initial log capabilities
cin
parents:
diff changeset
22 m_level = parent == null ? 0 : parent.Level + 1;
2880242f987a initial log capabilities
cin
parents:
diff changeset
23 m_timestamp = Environment.TickCount;
2880242f987a initial log capabilities
cin
parents:
diff changeset
24 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
25
2880242f987a initial log capabilities
cin
parents:
diff changeset
26 public int Duration {
2880242f987a initial log capabilities
cin
parents:
diff changeset
27 get {
2880242f987a initial log capabilities
cin
parents:
diff changeset
28 var dt = Environment.TickCount - m_timestamp;
2880242f987a initial log capabilities
cin
parents:
diff changeset
29 return dt < 0 ? int.MaxValue + dt : dt; // handle overflow
2880242f987a initial log capabilities
cin
parents:
diff changeset
30 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
31 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
32
2880242f987a initial log capabilities
cin
parents:
diff changeset
33 public LogicalOperation Parent {
2880242f987a initial log capabilities
cin
parents:
diff changeset
34 get {
2880242f987a initial log capabilities
cin
parents:
diff changeset
35 return m_parent;
2880242f987a initial log capabilities
cin
parents:
diff changeset
36 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
37 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
38
2880242f987a initial log capabilities
cin
parents:
diff changeset
39 public int Level {
2880242f987a initial log capabilities
cin
parents:
diff changeset
40 get { return m_level; }
2880242f987a initial log capabilities
cin
parents:
diff changeset
41 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
42
2880242f987a initial log capabilities
cin
parents:
diff changeset
43 public string Name {
2880242f987a initial log capabilities
cin
parents:
diff changeset
44 get { return m_name; }
2880242f987a initial log capabilities
cin
parents:
diff changeset
45 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
46 }
2880242f987a initial log capabilities
cin
parents:
diff changeset
47 }