diff 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
line wrap: on
line diff
--- a/Implab.Diagnostics.Interactive/TraceForm.cs	Thu Apr 17 08:49:24 2014 +0400
+++ b/Implab.Diagnostics.Interactive/TraceForm.cs	Thu Apr 17 18:49:36 2014 +0400
@@ -10,8 +10,12 @@
 
 namespace Implab.Diagnostics.Interactive {
     public partial class TraceForm : Form {
+        readonly Dictionary<int, Color> m_threadColors = new Dictionary<int,Color>();
+        readonly Random m_rand = new Random();
+
         public TraceForm() {
             InitializeComponent();
+
         }
 
         protected override void OnFormClosing(FormClosingEventArgs e) {
@@ -21,5 +25,34 @@
                 Hide();
             }
         }
+
+        public void AddTraceEvent(int indent, int thread, string message) {
+            traceViewItemBindingSource.Add(new TraceViewItem {
+                Indent = indent,
+                Thread = thread,
+                Message = message,
+                Timestamp = Environment.TickCount
+            });
+
+        }
+
+        public void AddTraceEvent(TraceViewItem item) {
+            traceViewItemBindingSource.Add(item);
+        }
+
+        Color GetThreadColor(int thread) {
+            Color result;
+            if (!m_threadColors.TryGetValue(thread, out result)) {
+                result = Color.FromArgb(m_rand.Next(4)*64, m_rand.Next(4)*64, m_rand.Next(4)*64);
+                m_threadColors[thread] = result;
+            }
+            return result;
+        }
+
+        private void eventsDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
+            var data = (TraceViewItem)traceViewItemBindingSource[e.RowIndex];
+            e.CellStyle.Padding = new Padding(data.Indent * 10,0,0,0);
+            e.CellStyle.ForeColor = GetThreadColor(data.Thread);
+        }
     }
 }