comparison Implab.Diagnostics.Interactive/TraceForm.cs @ 47:b181f7bcb259 interactive logger

refactoring, interactive tarce log almost complete
author cin
date Thu, 17 Apr 2014 18:49:36 +0400
parents d10034588e38
children d9d794b61bb9
comparison
equal deleted inserted replaced
46:9ce97b262a7a 47:b181f7bcb259
8 using System.Threading.Tasks; 8 using System.Threading.Tasks;
9 using System.Windows.Forms; 9 using System.Windows.Forms;
10 10
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>();
14 readonly Random m_rand = new Random();
15
13 public TraceForm() { 16 public TraceForm() {
14 InitializeComponent(); 17 InitializeComponent();
18
15 } 19 }
16 20
17 protected override void OnFormClosing(FormClosingEventArgs e) { 21 protected override void OnFormClosing(FormClosingEventArgs e) {
18 base.OnFormClosing(e); 22 base.OnFormClosing(e);
19 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) { 23 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) {
20 e.Cancel = true; 24 e.Cancel = true;
21 Hide(); 25 Hide();
22 } 26 }
23 } 27 }
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 }
24 } 57 }
25 } 58 }