andrew4582

DebugMonitorComponent

Aug 21st, 2010
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.ComponentModel;
  3. using System.Windows.Forms;
  4. namespace DbMon.NET {
  5.  
  6.     public partial class DebugMonitorComponent:Component {
  7.         bool _enabled = true;
  8.         bool _started;
  9.         bool _cancelled;
  10.         int _currentFilterPID = 0;
  11.         public Dictionary<int,string> ProcessList { get; set; }
  12.  
  13.         OutputQueue<DebugItem> _output;
  14.  
  15.         public bool Started {
  16.             get {
  17.                 return _started;
  18.             }
  19.             protected set {
  20.                 _started = value;
  21.             }
  22.         }
  23.         public bool Cancelled {
  24.             get {
  25.                 return _cancelled;
  26.             }
  27.             protected set {
  28.                 _cancelled = value;
  29.             }
  30.         }
  31.         public bool IsEnabled {
  32.             get { return _enabled; }
  33.             set { _enabled = value; }
  34.         }
  35.         public int CurrentFilterPID {
  36.             get { return _currentFilterPID; }
  37.             set { _currentFilterPID = value; }
  38.         }
  39.  
  40.         public DebugMonitorComponent() {
  41.             InitializeComponent();
  42.             ProcessList = new Dictionary<int,string>();
  43.         }
  44.         public DebugMonitorComponent(IContainer container) {
  45.             container.Add(this);
  46.             InitializeComponent();
  47.         }
  48.         public virtual void Start(OutputQueue<DebugItem> output) {
  49.             _output = output;
  50.  
  51.             if(this.DesignMode) {
  52.                 MessageBox.Show("Start(); DesignMode=true");
  53.                 return;
  54.             }
  55.  
  56.             Started = true;
  57.             Cancelled = false;
  58.            
  59.             DebugMonitor.OnOutputDebugString -= new OnOutputDebugStringHandler(DebugMonitor_OnOutputDebugString);
  60.             DebugMonitor.OnOutputDebugString += new OnOutputDebugStringHandler(DebugMonitor_OnOutputDebugString);
  61.             DebugMonitor.Start();
  62.         }
  63.         public virtual void Stop() {
  64.             if(this.DesignMode) {
  65.                 MessageBox.Show("Stop(); DesignMode=true");
  66.                 return;
  67.             }
  68.             Cancelled = true;
  69.             Started = false;
  70.             DebugMonitor.Stop();
  71.             DebugMonitor.OnOutputDebugString -= new OnOutputDebugStringHandler(DebugMonitor_OnOutputDebugString);
  72.         }
  73.         void DebugMonitor_OnOutputDebugString(int pid,string text) {
  74.             if(!this._enabled)
  75.                 return;
  76.             if(_currentFilterPID > 0)
  77.                 if(_currentFilterPID != pid)
  78.                     return;
  79.             _output.EnqueueOutput(new DebugItem(pid,text));
  80.         }
  81.         public void RemoveProcess(int[] pids) {
  82.             foreach(var item in pids) {
  83.                 ProcessList.Remove(item);
  84.             }
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment