diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -11,3 +11,5 @@ Implab.Fx/bin/ Implab.Fx.Test/bin/ Implab.Fx.Test/obj/ _ReSharper.Implab/ +Implab.Diagnostics.Interactive/bin/ +Implab.Diagnostics.Interactive/obj/ diff --git a/Implab.Diagnostics.Interactive/Implab.Diagnostics.Interactive.csproj b/Implab.Diagnostics.Interactive/Implab.Diagnostics.Interactive.csproj new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/Implab.Diagnostics.Interactive.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {1DB7DB0C-8AA9-484B-A681-33AE94038391} + Library + Properties + Implab.Diagnostics.Interactive + Implab.Diagnostics.Interactive + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + Form + + + TraceForm.cs + + + UserControl + + + TraceViewControl.cs + + + + + + {f550f1f8-8746-4ad0-9614-855f4c4b7f05} + Implab + + + + + TraceForm.cs + + + TraceViewControl.cs + + + + + \ No newline at end of file diff --git a/Implab.Diagnostics.Interactive/InteractiveTracer.cs b/Implab.Diagnostics.Interactive/InteractiveTracer.cs new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/InteractiveTracer.cs @@ -0,0 +1,55 @@ +using Implab.Parallels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Implab.Diagnostics.Interactive +{ + public class InteractiveTracer: Disposable + { + TraceForm m_form; + SynchronizationContext m_syncGuiThread; + readonly IPromiseBase m_completed; + readonly Promise m_started = new Promise(); + + public InteractiveTracer() { + m_completed = AsyncPool.InvokeNewThread(() => { + GuiThread(); + return 0; + }); + + m_started.Join(); + } + + void GuiThread() { + m_form = new TraceForm(); // will create SynchronizationContext + m_syncGuiThread = SynchronizationContext.Current; + m_started.Resolve(); + Application.Run(); + } + + public void ShowForm() { + m_syncGuiThread.Post(x => m_form.Show(), null); + } + + public void HideForm() { + m_syncGuiThread.Post(x => m_form.Hide(), null); + } + + void Terminate() { + m_syncGuiThread.Post(x => Application.ExitThread(), null); + } + + protected override void Dispose(bool disposing) { + if (disposing) { + Terminate(); + m_completed.Join(); + } + base.Dispose(disposing); + } + } +} diff --git a/Implab.Diagnostics.Interactive/Properties/AssemblyInfo.cs b/Implab.Diagnostics.Interactive/Properties/AssemblyInfo.cs new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Implab.Diagnostics.Interactive")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Implab.Diagnostics.Interactive")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1c156c51-4884-43b2-a823-d86313872e82")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Implab.Diagnostics.Interactive/TextStyle.cs b/Implab.Diagnostics.Interactive/TextStyle.cs new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TextStyle.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Implab.Diagnostics.Interactive { + class TextStyle { + public Color TextColor { + get; + set; + } + + public FontStyle FontStyle { + get; + set; + } + + public int PaddingLeft { + get; + set; + } + } +} diff --git a/Implab.Diagnostics.Interactive/TraceForm.Designer.cs b/Implab.Diagnostics.Interactive/TraceForm.Designer.cs new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TraceForm.Designer.cs @@ -0,0 +1,52 @@ +namespace Implab.Diagnostics.Interactive { + partial class TraceForm { + /// + /// 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 Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.traceViewControl1 = new Implab.Diagnostics.Interactive.TraceViewControl(); + this.SuspendLayout(); + // + // traceViewControl1 + // + 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; + // + // 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.Name = "TraceForm"; + this.Text = "TraceForm"; + this.ResumeLayout(false); + + } + + #endregion + + private TraceViewControl traceViewControl1; + } +} \ No newline at end of file diff --git a/Implab.Diagnostics.Interactive/TraceForm.cs b/Implab.Diagnostics.Interactive/TraceForm.cs new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TraceForm.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Implab.Diagnostics.Interactive { + public partial class TraceForm : Form { + public TraceForm() { + InitializeComponent(); + } + + protected override void OnFormClosing(FormClosingEventArgs e) { + base.OnFormClosing(e); + if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) { + e.Cancel = true; + Hide(); + } + } + } +} diff --git a/Implab.Diagnostics.Interactive/TraceForm.resx b/Implab.Diagnostics.Interactive/TraceForm.resx new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TraceForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/TraceViewControl.Designer.cs b/Implab.Diagnostics.Interactive/TraceViewControl.Designer.cs new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TraceViewControl.Designer.cs @@ -0,0 +1,40 @@ +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 new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TraceViewControl.cs @@ -0,0 +1,55 @@ +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 new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TraceViewControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 --- /dev/null +++ b/Implab.Diagnostics.Interactive/TraceViewItem.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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; + } +} diff --git a/Implab/Implab.csproj b/Implab/Implab.csproj --- a/Implab/Implab.csproj +++ b/Implab/Implab.csproj @@ -52,7 +52,6 @@ - diff --git a/Implab/ManagedPromise.cs b/Implab/ManagedPromise.cs deleted file mode 100644 --- a/Implab/ManagedPromise.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Implab { - - /*public class ManagedPromise: Promise, ITaskController, IProgressNotifier { - - }*/ -} diff --git a/Implab/Parallels/AsyncPool.cs b/Implab/Parallels/AsyncPool.cs --- a/Implab/Parallels/AsyncPool.cs +++ b/Implab/Parallels/AsyncPool.cs @@ -12,7 +12,7 @@ namespace Implab.Parallels { /// public static class AsyncPool { - public static Promise Invoke(Func func) { + public static IPromise Invoke(Func func) { var p = new Promise(); var caller = TraceContext.Snapshot(); @@ -28,7 +28,7 @@ namespace Implab.Parallels { return p; } - public static Promise InvokeNewThread(Func func) { + public static IPromise InvokeNewThread(Func func) { var p = new Promise(); var caller = TraceContext.Snapshot();