-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPlsqlDeveloperUtPlsqlPlugin.cs
More file actions
281 lines (250 loc) · 12.3 KB
/
Copy pathPlsqlDeveloperUtPlsqlPlugin.cs
File metadata and controls
281 lines (250 loc) · 12.3 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
using System;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.IO;
using System.Collections.Generic;
namespace utPLSQL
{
//*FUNC: 11*/ BOOL (*IDE_Connected)();
internal delegate bool IdeConnected();
//*FUNC: 12*/ void (*IDE_GetConnectionInfo)(char **Username, char **Password, char **Database);
internal delegate void IdeGetConnectionInfo(out IntPtr username, out IntPtr password, out IntPtr database);
//*FUNC: 20*/ void (*IDE_CreateWindow)(int WindowType, char *Text, BOOL Execute);
internal delegate void IdeCreateWindow(int windowType, string text, bool execute);
//*FUNC: 69*/ void *(*IDE_CreatePopupItem)(int ID, int Index, char *Name, char *ObjectType);
internal delegate void IdeCreatePopupItem(int id, int index, string name, string objectType);
//*FUNC: 74*/ int (*IDE_GetPopupObject)(char **ObjectType, char **ObjectOwner, char **ObjectName, char **SubObject);
internal delegate int IdeGetPopupObject(out IntPtr objectType, out IntPtr objectOwner, out IntPtr objectName, out IntPtr subObject);
//*FUNC: 79*/ char *(*IDE_GetObjectSource)(char *ObjectType, char *ObjectOwner, char *ObjectName);
internal delegate IntPtr IdeGetObjectSource(string objectType, string objectOwner, string objectName);
//*FUNC: 150*/ void (*IDE_CreateToolButton)(int ID, int Index, char *Name, char *BitmapFile, int BitmapHandle);
internal delegate void IdeCreateToolButton(int id, int index, string name, string bitmapFile, long bitmapHandle);
public class PlsqlDeveloperUtPlsqlPlugin
{
private const string PLUGIN_NAME = "utPLSQL Plugin";
private const int PLUGIN_MENU_INDEX_ALLTESTS = 3;
private const int PLUGIN_MENU_INDEX_ALLTESTS_WITH_COVERAGE = 4;
private const int PLUGIN_POPUP_INDEX = 1;
private const int PLUGIN_POPUP_INDEX_WITH_COVERAGE = 2;
private static PlsqlDeveloperUtPlsqlPlugin plugin;
internal static IdeConnected connected;
internal static IdeGetConnectionInfo getConnectionInfo;
internal static IdeCreateWindow createWindow;
internal static IdeCreatePopupItem createPopupItem;
internal static IdeGetPopupObject getPopupObject;
internal static IdeGetObjectSource getObjectSource;
internal static IdeCreateToolButton createToolButton;
internal static int pluginId;
internal static string username;
internal static string password;
internal static string database;
private static RealTimeTestRunner testRunner;
private static readonly List<TestRunnerWindow> windows = new List<TestRunnerWindow>();
private PlsqlDeveloperUtPlsqlPlugin()
{
testRunner = new RealTimeTestRunner();
}
#region DLL exported API
[DllExport("IdentifyPlugIn", CallingConvention = CallingConvention.Cdecl)]
public static string IdentifyPlugIn(int id)
{
if (plugin == null)
{
plugin = new PlsqlDeveloperUtPlsqlPlugin();
pluginId = id;
}
return PLUGIN_NAME;
}
[DllExport("OnActivate", CallingConvention = CallingConvention.Cdecl)]
public static void OnActivate()
{
try
{
PlsqlDeveloperUtPlsqlPlugin.ConnectToDatabase();
// Seperate streams are needed!
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("utPLSQL.utPLSQL.bmp"))
{
PlsqlDeveloperUtPlsqlPlugin.createToolButton(pluginId, PLUGIN_MENU_INDEX_ALLTESTS, "utPLSQL", "utPLSQL.bmp", new Bitmap(stream).GetHbitmap().ToInt64());
}
using (Stream stream = assembly.GetManifestResourceStream("utPLSQL.utPLSQL_coverage.bmp"))
{
PlsqlDeveloperUtPlsqlPlugin.createToolButton(pluginId, PLUGIN_MENU_INDEX_ALLTESTS_WITH_COVERAGE, "utPLSQL", "utPLSQL_coverage.bmp", new Bitmap(stream).GetHbitmap().ToInt64());
}
using (Stream stream = assembly.GetManifestResourceStream("utPLSQL.utPLSQL.bmp"))
{
PlsqlDeveloperUtPlsqlPlugin.createToolButton(pluginId, PLUGIN_POPUP_INDEX, "utPLSQL", "utPLSQL.bmp", new Bitmap(stream).GetHbitmap().ToInt64());
}
using (Stream stream = assembly.GetManifestResourceStream("utPLSQL.utPLSQL_coverage.bmp"))
{
PlsqlDeveloperUtPlsqlPlugin.createToolButton(pluginId, PLUGIN_POPUP_INDEX_WITH_COVERAGE, "utPLSQL", "utPLSQL_coverage.bmp", new Bitmap(stream).GetHbitmap().ToInt64());
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
PlsqlDeveloperUtPlsqlPlugin.createPopupItem(pluginId, PLUGIN_POPUP_INDEX, "Run utPLSQL Test", "USER");
PlsqlDeveloperUtPlsqlPlugin.createPopupItem(pluginId, PLUGIN_POPUP_INDEX_WITH_COVERAGE, "Run Code Coverage", "USER");
PlsqlDeveloperUtPlsqlPlugin.createPopupItem(pluginId, PLUGIN_POPUP_INDEX, "Run utPLSQL Test", "PACKAGE");
PlsqlDeveloperUtPlsqlPlugin.createPopupItem(pluginId, PLUGIN_POPUP_INDEX_WITH_COVERAGE, "Run Code Coverage", "PACKAGE");
}
[DllExport("CanClose", CallingConvention = CallingConvention.Cdecl)]
public static bool CanClose()
{
foreach (TestRunnerWindow window in windows)
{
if (window.Running)
{
var confirmResult = MessageBox.Show("utPLSQL Tests are still running.\r\n\r\nDo you really want to close PL/SQL Developer?", "Running utPLSQL Tests", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (confirmResult == DialogResult.Yes)
{
return true;
}
else
{
return false;
}
}
}
return true;
}
[DllExport("RegisterCallback", CallingConvention = CallingConvention.Cdecl)]
public static void RegisterCallback(int index, IntPtr function)
{
switch (index)
{
case 11:
PlsqlDeveloperUtPlsqlPlugin.connected = (IdeConnected)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeConnected));
break;
case 12:
PlsqlDeveloperUtPlsqlPlugin.getConnectionInfo = (IdeGetConnectionInfo)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeGetConnectionInfo));
break;
case 20:
PlsqlDeveloperUtPlsqlPlugin.createWindow = (IdeCreateWindow)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeCreateWindow));
break;
case 69:
PlsqlDeveloperUtPlsqlPlugin.createPopupItem = (IdeCreatePopupItem)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeCreatePopupItem));
break;
case 74:
PlsqlDeveloperUtPlsqlPlugin.getPopupObject = (IdeGetPopupObject)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeGetPopupObject));
break;
case 79:
PlsqlDeveloperUtPlsqlPlugin.getObjectSource = (IdeGetObjectSource)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeGetObjectSource));
break;
case 150:
PlsqlDeveloperUtPlsqlPlugin.createToolButton = (IdeCreateToolButton)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeCreateToolButton));
break;
}
}
[DllExport("OnConnectionChange", CallingConvention = CallingConvention.Cdecl)]
public static void OnConnectionChange()
{
PlsqlDeveloperUtPlsqlPlugin.ConnectToDatabase();
}
[DllExport("CreateMenuItem", CallingConvention = CallingConvention.Cdecl)]
public static string CreateMenuItem(int index)
{
switch (index)
{
case 1:
return "TAB=Tools";
case 2:
return "GROUP=utPLSQL";
case PLUGIN_MENU_INDEX_ALLTESTS:
return "LARGEITEM=Run all tests of current user";
case PLUGIN_MENU_INDEX_ALLTESTS_WITH_COVERAGE:
return "LARGEITEM=Run code coverage for current user";
default:
return "";
}
}
[DllExport("OnMenuClick", CallingConvention = CallingConvention.Cdecl)]
public static void OnMenuClick(int index)
{
if (index == PLUGIN_MENU_INDEX_ALLTESTS)
{
if (PlsqlDeveloperUtPlsqlPlugin.connected())
{
var testResultWindow = new TestRunnerWindow(testRunner);
windows.Add(testResultWindow);
testResultWindow.RunTestsAsync("_ALL", username, null, null, false);
}
}
else if (index == PLUGIN_MENU_INDEX_ALLTESTS_WITH_COVERAGE)
{
if (PlsqlDeveloperUtPlsqlPlugin.connected())
{
var testResultWindow = new TestRunnerWindow(testRunner);
windows.Add(testResultWindow);
testResultWindow.RunTestsAsync("_ALL", username, null, null, true);
}
}
else if (index == PLUGIN_POPUP_INDEX)
{
if (PlsqlDeveloperUtPlsqlPlugin.connected())
{
IntPtr type;
IntPtr owner;
IntPtr name;
IntPtr subType;
PlsqlDeveloperUtPlsqlPlugin.getPopupObject(out type, out owner, out name, out subType);
var testResultWindow = new TestRunnerWindow(testRunner);
windows.Add(testResultWindow);
testResultWindow.RunTestsAsync(Marshal.PtrToStringAnsi(type), Marshal.PtrToStringAnsi(owner), Marshal.PtrToStringAnsi(name), Marshal.PtrToStringAnsi(subType), false);
}
}
else if (index == PLUGIN_POPUP_INDEX_WITH_COVERAGE)
{
if (PlsqlDeveloperUtPlsqlPlugin.connected())
{
IntPtr type;
IntPtr owner;
IntPtr name;
IntPtr subType;
PlsqlDeveloperUtPlsqlPlugin.getPopupObject(out type, out owner, out name, out subType);
var testResultWindow = new TestRunnerWindow(testRunner);
windows.Add(testResultWindow);
testResultWindow.RunTestsAsync(Marshal.PtrToStringAnsi(type), Marshal.PtrToStringAnsi(owner), Marshal.PtrToStringAnsi(name), Marshal.PtrToStringAnsi(subType), true);
}
}
}
[DllExport("About", CallingConvention = CallingConvention.Cdecl)]
public static string About()
{
new AboutDialog().Show();
return "";
}
#endregion
internal static void OpenPackageBody(string owner, string name)
{
IntPtr source = getObjectSource("PACKAGE BODY", owner, name);
createWindow(3, Marshal.PtrToStringAnsi(source), false);
}
private static void ConnectToDatabase()
{
try
{
testRunner.Close();
if (PlsqlDeveloperUtPlsqlPlugin.connected())
{
IntPtr ptrUsername;
IntPtr ptrPassword;
IntPtr ptrDatabase;
PlsqlDeveloperUtPlsqlPlugin.getConnectionInfo(out ptrUsername, out ptrPassword, out ptrDatabase);
username = Marshal.PtrToStringAnsi(ptrUsername);
password = Marshal.PtrToStringAnsi(ptrPassword);
database = Marshal.PtrToStringAnsi(ptrDatabase);
testRunner.Connect(username, password, database);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}