annotate Implab.Diagnostics.Interactive/TraceForm.cs @ 242:cbe10ac0731e v3

Working on promises
author cin
date Wed, 24 Jan 2018 03:03:21 +0300
parents cbb0bd8fc0d1
children
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
48
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
16 public event EventHandler PauseEvents;
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
17
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
18 public event EventHandler ResumeEvents;
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
19
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
20 public TraceForm() {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
21 InitializeComponent();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
22 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
23
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
24 protected override void OnFormClosing(FormClosingEventArgs e) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
25 base.OnFormClosing(e);
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
26 if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) {
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
27 e.Cancel = true;
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
28 Hide();
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
29 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
30 }
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
31
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
32 public void AddTraceEvent(TraceViewItem item) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
33 traceViewItemBindingSource.Add(item);
204
cbb0bd8fc0d1 Fixed broken Implab.Diagnostics.Interactive
cin
parents: 48
diff changeset
34 if(eventsDataGrid.RowCount > 0)
cbb0bd8fc0d1 Fixed broken Implab.Diagnostics.Interactive
cin
parents: 48
diff changeset
35 eventsDataGrid.FirstDisplayedScrollingRowIndex = eventsDataGrid.RowCount - 1;
47
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 Color GetThreadColor(int thread) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
39 Color result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
40 if (!m_threadColors.TryGetValue(thread, out result)) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
41 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
42 m_threadColors[thread] = result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
43 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
44 return result;
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
45 }
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
46
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
47 private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
48 var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
48
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
49 if (e.ColumnIndex == messageDataGridViewTextBoxColumn.Index)
d9d794b61bb9 Interactive tracing
cin
parents: 47
diff changeset
50 e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
47
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
51 e.CellStyle.ForeColor = GetThreadColor(data.Thread);
b181f7bcb259 refactoring, interactive tarce log almost complete
cin
parents: 45
diff changeset
52 }
45
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
53 }
d10034588e38 initial work on interactive logger
cin
parents:
diff changeset
54 }