comparison Implab.Diagnostics.Interactive/TraceForm.cs @ 48:d9d794b61bb9 interactive logger

Interactive tracing Improved working with tracing contexts
author cin
date Fri, 18 Apr 2014 12:34:45 +0400
parents b181f7bcb259
children cbb0bd8fc0d1
comparison
equal deleted inserted replaced
47:b181f7bcb259 48:d9d794b61bb9
11 namespace Implab.Diagnostics.Interactive { 11 namespace Implab.Diagnostics.Interactive {
12 public partial class TraceForm : Form { 12 public partial class TraceForm : Form {
13 readonly Dictionary<int, Color> m_threadColors = new Dictionary<int,Color>(); 13 readonly Dictionary<int, Color> m_threadColors = new Dictionary<int,Color>();
14 readonly Random m_rand = new Random(); 14 readonly Random m_rand = new Random();
15 15
16 public event EventHandler PauseEvents;
17
18 public event EventHandler ResumeEvents;
19
16 public TraceForm() { 20 public TraceForm() {
17 InitializeComponent(); 21 InitializeComponent();
18
19 } 22 }
20 23
21 protected override void OnFormClosing(FormClosingEventArgs e) { 24 protected override void OnFormClosing(FormClosingEventArgs e) {
22 base.OnFormClosing(e); 25 base.OnFormClosing(e);
23 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) { 26 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) {
24 e.Cancel = true; 27 e.Cancel = true;
25 Hide(); 28 Hide();
26 } 29 }
27 } 30 }
28 31
29 public void AddTraceEvent(int indent, int thread, string message) {
30 traceViewItemBindingSource.Add(new TraceViewItem {
31 Indent = indent,
32 Thread = thread,
33 Message = message,
34 Timestamp = Environment.TickCount
35 });
36
37 }
38
39 public void AddTraceEvent(TraceViewItem item) { 32 public void AddTraceEvent(TraceViewItem item) {
40 traceViewItemBindingSource.Add(item); 33 traceViewItemBindingSource.Add(item);
34 eventsDataGrid.FirstDisplayedScrollingRowIndex = eventsDataGrid.RowCount - 1;
41 } 35 }
42 36
43 Color GetThreadColor(int thread) { 37 Color GetThreadColor(int thread) {
44 Color result; 38 Color result;
45 if (!m_threadColors.TryGetValue(thread, out result)) { 39 if (!m_threadColors.TryGetValue(thread, out result)) {
49 return result; 43 return result;
50 } 44 }
51 45
52 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { 46 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
53 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex]; 47 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
54 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0); 48 if (e.ColumnIndex == messageDataGridViewTextBoxColumn.Index)
49 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
55 e.CellStyle.ForeColor = GetThreadColor(data.Thread); 50 e.CellStyle.ForeColor = GetThreadColor(data.Thread);
56 } 51 }
57 } 52 }
58 } 53 }