-
Notifications
You must be signed in to change notification settings - Fork 137
/
ActivityMonitorTab.cs
103 lines (86 loc) · 3.42 KB
/
ActivityMonitorTab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Windows.Forms;
using SwqlStudio.Subscriptions;
namespace SwqlStudio
{
public partial class ActivityMonitorTab : UserControl, IConnectionTab
{
private string subscriptionId;
public ConnectionInfo ConnectionInfo { get; set; }
public SubscriptionManager SubscriptionManager { get; set; }
public bool AllowsChangeConnection
{
get { return false; }
}
public ActivityMonitorTab()
{
InitializeComponent();
Disposed += ActivityMonitorTabDisposed;
}
void ActivityMonitorTabDisposed(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(subscriptionId) && ConnectionInfo.IsConnected)
{
this.SubscriptionManager.Unsubscribe(ConnectionInfo, subscriptionId);
}
}
private void SubscriptionIndicationReceived(IndicationEventArgs e)
{
if (this.IsDisposed)
return;
BeginInvoke(new Action<IndicationEventArgs>(AddIndication), e);
}
private void AddIndication(IndicationEventArgs obj)
{
var item = new ListViewItem(new[]
{
((DateTime)obj.IndicationProperties["IndicationTime"]).ToLongTimeString(),
(string)obj.IndicationProperties["QueryText"],
(string)obj.IndicationProperties["Parameters"],
string.Format("{0} ms", obj.IndicationProperties["ExecutionTimeMS"])
});
listView1.Items.Add(item);
item.EnsureVisible();
}
public void Start()
{
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
backgroundWorker1.ReportProgress(0, "Waiting for subscriber host to be opened...");
backgroundWorker1.ReportProgress(0, "Starting subscription...");
try
{
subscriptionId = this.SubscriptionManager.CreateSubscription(ConnectionInfo, "SUBSCRIBE System.QueryExecuted", SubscriptionIndicationReceived);
backgroundWorker1.ReportProgress(0, "Waiting for notifications");
}
catch (ApplicationException ex)
{
e.Result = ex;
}
}
private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
toolStripStatusLabel1.Text = e.UserState.ToString();
}
private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
if (e.Result is Exception)
{
MessageBox.Show(e.Result.ToString());
}
}
private void CopySelected(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 0)
return;
var text = listView1.SelectedItems[0].SubItems[1].Text;
Clipboard.SetDataObject(text, true);
}
private void ClearContent(object sender, EventArgs e)
{
listView1.Items.Clear();
}
}
}