annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
1 using System;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
2 using System.Collections.Generic;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
3 using System.ComponentModel;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
4 using System.Data;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
5 using System.Drawing;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
6 using System.Linq;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
7 using System.Text;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
8 using System.Threading.Tasks;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
9 using System.Windows.Forms;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
10
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
11 namespace Implab.Diagnostics.Interactive {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
12 public partial class TraceForm : Form {
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
13 readonly Dictionary<int, Color> m_threadColors = new Dictionary<int,Color>();
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
14 readonly Random m_rand = new Random();
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
15
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
16 public TraceForm() {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
17 InitializeComponent();
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
18
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
19 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
20
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
21 protected override void OnFormClosing(FormClosingEventArgs e) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
22 base.OnFormClosing(e);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
23 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
24 e.Cancel = true;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
25 Hide();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
26 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
27 }
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
28
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
29 public void AddTraceEvent(int indent, int thread, string message) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
30 traceViewItemBindingSource.Add(new TraceViewItem {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
31 Indent = indent,
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
32 Thread = thread,
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
33 Message = message,
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
34 Timestamp = Environment.TickCount
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
35 });
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
36
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
37 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
38
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
39 public void AddTraceEvent(TraceViewItem item) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
40 traceViewItemBindingSource.Add(item);
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
41 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
42
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
43 Color GetThreadColor(int thread) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
44 Color result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
45 if (!m_threadColors.TryGetValue(thread, out result)) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
46 result = Color.FromArgb(m_rand.Next(4)*64, m_rand.Next(4)*64, m_rand.Next(4)*64);
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
47 m_threadColors[thread] = result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
48 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
49 return result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
50 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
51
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
52 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
53 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
54 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
55 e.CellStyle.ForeColor = GetThreadColor(data.Thread);
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
56 }
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
57 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
58 }