-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPlsqlDeveloperUtPlsqlPlugin.cs
More file actions
198 lines (173 loc) · 7.95 KB
/
Copy pathPlsqlDeveloperUtPlsqlPlugin.cs
File metadata and controls
198 lines (173 loc) · 7.95 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
using System;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.IO;
using utPLSQL;
namespace PlsqlDeveloperUtPlsqlPlugin
{
//*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: 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: 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_POPUP_INDEX = 1;
private static PlsqlDeveloperUtPlsqlPlugin plugin;
internal static IdeConnected connected;
internal static IdeGetConnectionInfo getConnectionInfo;
internal static IdeCreatePopupItem createPopupItem;
internal static IdeGetPopupObject getPopupObject;
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 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();
// Two seperate streams are needed!
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("PlsqlDeveloperUtPlsqlPlugin.utPLSQL.bmp"))
{
PlsqlDeveloperUtPlsqlPlugin.createToolButton(pluginId, PLUGIN_MENU_INDEX_ALLTESTS, "utPLSQL", "utPLSQL.bmp", new Bitmap(stream).GetHbitmap().ToInt64());
}
using (Stream stream = assembly.GetManifestResourceStream("PlsqlDeveloperUtPlsqlPlugin.utPLSQL.bmp"))
{
PlsqlDeveloperUtPlsqlPlugin.createToolButton(pluginId, PLUGIN_POPUP_INDEX, "utPLSQL", "utPLSQL.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, "Run utPLSQL Test", "PACKAGE");
}
[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 69:
PlsqlDeveloperUtPlsqlPlugin.createPopupItem = (IdeCreatePopupItem)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeCreatePopupItem));
break;
case 74:
PlsqlDeveloperUtPlsqlPlugin.getPopupObject = (IdeGetPopupObject)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeGetPopupObject));
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";
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 RealTimeTestResultWindow(testRunner);
testResultWindow.RunTests("_ALL", username, null, null);
}
}
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 RealTimeTestResultWindow(testRunner);
testResultWindow.RunTests(Marshal.PtrToStringAnsi(type), Marshal.PtrToStringAnsi(owner), Marshal.PtrToStringAnsi(name), Marshal.PtrToStringAnsi(subType));
}
}
}
[DllExport("About", CallingConvention = CallingConvention.Cdecl)]
public static string About()
{
new AboutDialog().Show();
return "";
}
#endregion
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);
}
}
}
}