-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDebuggerEvents.cs
More file actions
103 lines (87 loc) · 3.2 KB
/
Copy pathDebuggerEvents.cs
File metadata and controls
103 lines (87 loc) · 3.2 KB
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.Collections.Generic;
using System.Windows.Forms;
using CodingWithCalvin.BreakpointNotifier.Options;
using CodingWithCalvin.Otel4Vsix;
using Microsoft;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Debugger.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
namespace CodingWithCalvin.BreakpointNotifier
{
public sealed class DebuggerEvents : IVsDebuggerEvents, IDebugEventCallback2
{
private readonly BreakpointNotifierPackage _package;
private DebuggerEvents(BreakpointNotifierPackage package)
{
ThreadHelper.ThrowIfNotOnUIThread();
_package = package;
var debugger = (IVsDebugger)
ServiceProvider.GlobalProvider.GetService(typeof(IVsDebugger));
Assumes.Present(debugger);
debugger.AdviseDebuggerEvents(this, out _);
debugger.AdviseDebugEventCallback(this);
}
public static DebuggerEvents Initialize(BreakpointNotifierPackage package)
{
return new DebuggerEvents(package);
}
public int OnModeChange(DBGMODE dbgmodeNew)
{
VsixTelemetry.LogInformation("Debugger mode changed to {Mode}", dbgmodeNew.ToString());
return VSConstants.S_OK;
}
public int Event(
IDebugEngine2 pEngine,
IDebugProcess2 pProcess,
IDebugProgram2 pProgram,
IDebugThread2 pThread,
IDebugEvent2 pEvent,
ref Guid riidEvent,
uint dwAttrib)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (pEvent is IDebugBreakpointEvent2)
{
using var activity = VsixTelemetry.StartCommandActivity("BreakpointNotifier.BreakpointHit");
try
{
VsixTelemetry.LogInformation("Breakpoint hit detected");
ShowNotification();
}
catch (Exception ex)
{
activity?.RecordError(ex);
VsixTelemetry.TrackException(ex, new Dictionary<string, object>
{
{ "operation.name", "BreakpointHit" }
});
}
}
return VSConstants.S_OK;
}
private void ShowNotification()
{
ThreadHelper.ThrowIfNotOnUIThread();
var style = GetNotificationStyle();
if (style == NotificationStyle.MessageBox || style == NotificationStyle.Both)
{
MessageBox.Show("Breakpoint Hit!");
}
if (style == NotificationStyle.Toast || style == NotificationStyle.Both)
{
new ToastContentBuilder()
.AddText("Breakpoint Hit!")
.Show();
}
}
private NotificationStyle GetNotificationStyle()
{
ThreadHelper.ThrowIfNotOnUIThread();
var options = _package.GetDialogPage(typeof(GeneralOptions)) as GeneralOptions;
return options?.Style ?? NotificationStyle.Toast;
}
}
}