45
|
1 using System;
|
|
2 using System.Collections.Generic;
|
|
3 using System.ComponentModel;
|
|
4 using System.Data;
|
|
5 using System.Drawing;
|
|
6 using System.Linq;
|
|
7 using System.Text;
|
|
8 using System.Threading.Tasks;
|
|
9 using System.Windows.Forms;
|
|
10
|
|
11 namespace Implab.Diagnostics.Interactive {
|
|
12 public partial class TraceForm : Form {
|
47
|
13 readonly Dictionary<int, Color> m_threadColors = new Dictionary<int,Color>();
|
|
14 readonly Random m_rand = new Random();
|
|
15
|
45
|
16 public TraceForm() {
|
|
17 InitializeComponent();
|
47
|
18
|
45
|
19 }
|
|
20
|
|
21 protected override void OnFormClosing(FormClosingEventArgs e) {
|
|
22 base.OnFormClosing(e);
|
|
23 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) {
|
|
24 e.Cancel = true;
|
|
25 Hide();
|
|
26 }
|
|
27 }
|
47
|
28
|
|
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) {
|
|
40 traceViewItemBindingSource.Add(item);
|
|
41 }
|
|
42
|
|
43 Color GetThreadColor(int thread) {
|
|
44 Color result;
|
|
45 if (!m_threadColors.TryGetValue(thread, out result)) {
|
|
46 result = Color.FromArgb(m_rand.Next(4)*64, m_rand.Next(4)*64, m_rand.Next(4)*64);
|
|
47 m_threadColors[thread] = result;
|
|
48 }
|
|
49 return result;
|
|
50 }
|
|
51
|
|
52 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
|
|
53 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
|
|
54 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
|
|
55 e.CellStyle.ForeColor = GetThreadColor(data.Thread);
|
|
56 }
|
45
|
57 }
|
|
58 }
|