# HG changeset patch
# User cin
# Date 2014-04-17 14:49:36
# Node ID b181f7bcb259c134156b4e5f51d6ae0ad636f201
# Parent 9ce97b262a7a0e6e9ee64b45efa4c8e7417e1a57
refactoring, interactive tarce log almost complete
diff --git a/Implab.Diagnostics.Interactive/Implab.Diagnostics.Interactive.csproj b/Implab.Diagnostics.Interactive/Implab.Diagnostics.Interactive.csproj
--- a/Implab.Diagnostics.Interactive/Implab.Diagnostics.Interactive.csproj
+++ b/Implab.Diagnostics.Interactive/Implab.Diagnostics.Interactive.csproj
@@ -41,7 +41,7 @@
-
+
@@ -50,16 +50,10 @@
TraceForm.cs
-
- UserControl
-
-
- TraceViewControl.cs
-
-
+
{f550f1f8-8746-4ad0-9614-855f4c4b7f05}
Implab
@@ -68,9 +62,9 @@
TraceForm.cs
-
- TraceViewControl.cs
-
+
+
+
+
+ Implab.Diagnostics.Interactive.TraceViewItem, Implab.Diagnostics.Interactive
+
\ No newline at end of file
diff --git a/Implab.Diagnostics.Interactive/TraceForm.Designer.cs b/Implab.Diagnostics.Interactive/TraceForm.Designer.cs
--- a/Implab.Diagnostics.Interactive/TraceForm.Designer.cs
+++ b/Implab.Diagnostics.Interactive/TraceForm.Designer.cs
@@ -23,30 +23,100 @@
/// the contents of this method with the code editor.
///
private void InitializeComponent() {
- this.traceViewControl1 = new Implab.Diagnostics.Interactive.TraceViewControl();
+ this.components = new System.ComponentModel.Container();
+ System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
+ System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
+ System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
+ this.eventsDataGrid = new System.Windows.Forms.DataGridView();
+ this.traceViewItemBindingSource = new System.Windows.Forms.BindingSource(this.components);
+ this.threadDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.messageDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ ((System.ComponentModel.ISupportInitialize)(this.eventsDataGrid)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.traceViewItemBindingSource)).BeginInit();
this.SuspendLayout();
//
- // traceViewControl1
+ // eventsDataGrid
//
- this.traceViewControl1.Location = new System.Drawing.Point(13, 13);
- this.traceViewControl1.Name = "traceViewControl1";
- this.traceViewControl1.Size = new System.Drawing.Size(267, 248);
- this.traceViewControl1.TabIndex = 0;
+ this.eventsDataGrid.AllowUserToAddRows = false;
+ this.eventsDataGrid.AllowUserToDeleteRows = false;
+ this.eventsDataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.eventsDataGrid.AutoGenerateColumns = false;
+ this.eventsDataGrid.BackgroundColor = System.Drawing.SystemColors.Window;
+ dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+ dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
+ dataGridViewCellStyle1.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+ dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
+ dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+ dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+ dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
+ this.eventsDataGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
+ this.eventsDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.eventsDataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.threadDataGridViewTextBoxColumn,
+ this.messageDataGridViewTextBoxColumn});
+ this.eventsDataGrid.DataSource = this.traceViewItemBindingSource;
+ dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
+ dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Window;
+ dataGridViewCellStyle3.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+ dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.ControlText;
+ dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
+ dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
+ dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
+ this.eventsDataGrid.DefaultCellStyle = dataGridViewCellStyle3;
+ this.eventsDataGrid.Location = new System.Drawing.Point(12, 12);
+ this.eventsDataGrid.Name = "eventsDataGrid";
+ this.eventsDataGrid.ReadOnly = true;
+ this.eventsDataGrid.RowHeadersWidth = 17;
+ this.eventsDataGrid.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.False;
+ this.eventsDataGrid.Size = new System.Drawing.Size(939, 480);
+ this.eventsDataGrid.TabIndex = 1;
+ this.eventsDataGrid.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.eventsDataGrid_CellFormatting);
+ //
+ // traceViewItemBindingSource
+ //
+ this.traceViewItemBindingSource.DataSource = typeof(Implab.Diagnostics.Interactive.TraceViewItem);
+ //
+ // threadDataGridViewTextBoxColumn
+ //
+ this.threadDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
+ this.threadDataGridViewTextBoxColumn.DataPropertyName = "Thread";
+ this.threadDataGridViewTextBoxColumn.HeaderText = "TID";
+ this.threadDataGridViewTextBoxColumn.Name = "threadDataGridViewTextBoxColumn";
+ this.threadDataGridViewTextBoxColumn.ReadOnly = true;
+ this.threadDataGridViewTextBoxColumn.Width = 5;
+ //
+ // messageDataGridViewTextBoxColumn
+ //
+ this.messageDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.messageDataGridViewTextBoxColumn.DataPropertyName = "FormattedMessage";
+ dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
+ this.messageDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2;
+ this.messageDataGridViewTextBoxColumn.HeaderText = "Message";
+ this.messageDataGridViewTextBoxColumn.Name = "messageDataGridViewTextBoxColumn";
+ this.messageDataGridViewTextBoxColumn.ReadOnly = true;
//
// TraceForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(292, 273);
- this.Controls.Add(this.traceViewControl1);
+ this.ClientSize = new System.Drawing.Size(963, 504);
+ this.Controls.Add(this.eventsDataGrid);
this.Name = "TraceForm";
this.Text = "TraceForm";
+ ((System.ComponentModel.ISupportInitialize)(this.eventsDataGrid)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.traceViewItemBindingSource)).EndInit();
this.ResumeLayout(false);
}
#endregion
- private TraceViewControl traceViewControl1;
+ private System.Windows.Forms.DataGridView eventsDataGrid;
+ private System.Windows.Forms.BindingSource traceViewItemBindingSource;
+ private System.Windows.Forms.DataGridViewTextBoxColumn threadDataGridViewTextBoxColumn;
+ private System.Windows.Forms.DataGridViewTextBoxColumn messageDataGridViewTextBoxColumn;
+
}
}
\ No newline at end of file
diff --git a/Implab.Diagnostics.Interactive/TraceForm.cs b/Implab.Diagnostics.Interactive/TraceForm.cs
--- a/Implab.Diagnostics.Interactive/TraceForm.cs
+++ b/Implab.Diagnostics.Interactive/TraceForm.cs
@@ -10,8 +10,12 @@ using System.Windows.Forms;
namespace Implab.Diagnostics.Interactive {
public partial class TraceForm : Form {
+ readonly Dictionary m_threadColors = new Dictionary();
+ readonly Random m_rand = new Random();
+
public TraceForm() {
InitializeComponent();
+
}
protected override void OnFormClosing(FormClosingEventArgs e) {
@@ -21,5 +25,34 @@ namespace Implab.Diagnostics.Interactive
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);
+ }
}
}
diff --git a/Implab.Diagnostics.Interactive/TraceForm.resx b/Implab.Diagnostics.Interactive/TraceForm.resx
--- a/Implab.Diagnostics.Interactive/TraceForm.resx
+++ b/Implab.Diagnostics.Interactive/TraceForm.resx
@@ -117,4 +117,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
\ No newline at end of file
diff --git a/Implab.Diagnostics.Interactive/TraceViewControl.Designer.cs b/Implab.Diagnostics.Interactive/TraceViewControl.Designer.cs
deleted file mode 100644
--- a/Implab.Diagnostics.Interactive/TraceViewControl.Designer.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-namespace Implab.Diagnostics.Interactive {
- partial class TraceViewControl {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing) {
- if (disposing && (components != null)) {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Component Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent() {
- this.SuspendLayout();
- //
- // TraceViewControl
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BackColor = System.Drawing.SystemColors.Window;
- this.Name = "TraceViewControl";
- this.ResumeLayout(false);
-
- }
-
- #endregion
- }
-}
diff --git a/Implab.Diagnostics.Interactive/TraceViewControl.cs b/Implab.Diagnostics.Interactive/TraceViewControl.cs
deleted file mode 100644
--- a/Implab.Diagnostics.Interactive/TraceViewControl.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.Data;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace Implab.Diagnostics.Interactive {
- public partial class TraceViewControl : UserControl {
- int m_maxEvents = 1000;
-
- string m_status = "ready";
-
- readonly LinkedList m_events = new LinkedList();
- public TraceViewControl() {
- InitializeComponent();
-
- var ticks = Environment.TickCount;
-
- for (int i = 0; i < 1333; i++) {
- AddViewItem(new TraceViewItem {
- indent = i % 4,
- message = String.Format("Auto generated {0}", i),
- thread = 2,
- timestamp = ticks + i*10
- });
- }
- }
-
- public void AddViewItem(TraceViewItem item) {
- m_events.AddLast(item);
- if (m_events.Count > m_maxEvents)
- m_events.RemoveFirst();
- }
-
- protected override void OnPaint(PaintEventArgs e) {
- base.OnPaint(e);
-
- if (m_status != null)
- e.Graphics.DrawString(m_status, DefaultFont, Brushes.Black, 0, 0);
-
- }
-
- protected override void OnMouseMove(MouseEventArgs e) {
- base.OnMouseMove(e);
-
- m_status = String.Format("({0},{1})", e.X, e.Y);
- Invalidate();
- }
-
- }
-}
diff --git a/Implab.Diagnostics.Interactive/TraceViewControl.resx b/Implab.Diagnostics.Interactive/TraceViewControl.resx
deleted file mode 100644
--- a/Implab.Diagnostics.Interactive/TraceViewControl.resx
+++ /dev/null
@@ -1,120 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
\ No newline at end of file
diff --git a/Implab.Diagnostics.Interactive/TraceViewItem.cs b/Implab.Diagnostics.Interactive/TraceViewItem.cs
--- a/Implab.Diagnostics.Interactive/TraceViewItem.cs
+++ b/Implab.Diagnostics.Interactive/TraceViewItem.cs
@@ -5,10 +5,21 @@ using System.Text;
using System.Threading.Tasks;
namespace Implab.Diagnostics.Interactive {
- public struct TraceViewItem {
- public string message;
- public int timestamp;
- public int indent;
- public int thread;
+ public class TraceViewItem {
+ string m_formattedValue;
+
+ public string Message { get; set; }
+ public int Timestamp { get; set; }
+ public int Indent { get; set; }
+ public int Thread { get; set; }
+
+ public string FormattedMessage {
+ get {
+ if (m_formattedValue == null) {
+ m_formattedValue = Message.Replace("\r",String.Empty).Replace("\n", " | ");
+ }
+ return m_formattedValue;
+ }
+ }
}
}
diff --git a/Implab/Diagnostics/TextFileListener.cs b/Implab/Diagnostics/TextFileListener.cs
--- a/Implab/Diagnostics/TextFileListener.cs
+++ b/Implab/Diagnostics/TextFileListener.cs
@@ -23,6 +23,7 @@ namespace Implab.Diagnostics {
lock (m_textWriter) {
if (!IsDisposed) {
+ // тут гарантировано еще не освобожден m_textWriter
m_textWriter.WriteLine(msg.ToString());
m_textWriter.Flush();
}
@@ -33,6 +34,7 @@ namespace Implab.Diagnostics {
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
if (disposing) {
+ // IsDisposed = true
lock (m_textWriter) {
Safe.Dispose(m_textWriter);
}
diff --git a/Implab/Diagnostics/TextListenerBase.cs b/Implab/Diagnostics/TextListenerBase.cs
--- a/Implab/Diagnostics/TextListenerBase.cs
+++ b/Implab/Diagnostics/TextListenerBase.cs
@@ -89,6 +89,15 @@ namespace Implab.Diagnostics {
}
}
+ ///
+ /// Вызывается для записи текста сообщения, в журнал.
+ ///
+ ///
+ /// Данный метод может вызваться из разных потоков одновременно. Возможна ситуация, когда
+ /// данный метод вызывается уже после освобождения ообъекта методом .
+ ///
+ /// Контекст трассировки.
+ /// Текст сообщения.
protected abstract void WriteEntry(TraceContext context, EventText text);
public EventText Format(TraceContext context, object data) {
@@ -110,10 +119,10 @@ namespace Implab.Diagnostics {
}
protected override void Dispose(bool disposing) {
+ base.Dispose(disposing);
if (disposing) {
UnsubscribeAll();
}
- base.Dispose(disposing);
}
}
}