10
10
11
11
namespace utPLSQL
12
12
{
13
+ //*FUNC: 4*/ extern char *(*SYS_OracleHome)();
14
+ internal delegate IntPtr SysOracleHome ( ) ;
15
+
13
16
//*FUNC: 11*/ BOOL (*IDE_Connected)();
14
17
internal delegate bool IdeConnected ( ) ;
15
18
@@ -23,8 +26,7 @@ namespace utPLSQL
23
26
internal delegate void IdeCreatePopupItem ( int id , int index , string name , string objectType ) ;
24
27
25
28
//*FUNC: 74*/ int (*IDE_GetPopupObject)(char **ObjectType, char **ObjectOwner, char **ObjectName, char **SubObject);
26
- internal delegate int IdeGetPopupObject ( out IntPtr objectType , out IntPtr objectOwner , out IntPtr objectName ,
27
- out IntPtr subObject ) ;
29
+ internal delegate int IdeGetPopupObject ( out IntPtr objectType , out IntPtr objectOwner , out IntPtr objectName , out IntPtr subObject ) ;
28
30
29
31
//*FUNC: 79*/ char *(*IDE_GetObjectSource)(char *ObjectType, char *ObjectOwner, char *ObjectName);
30
32
internal delegate IntPtr IdeGetObjectSource ( string objectType , string objectOwner , string objectName ) ;
@@ -44,6 +46,8 @@ public class PlsqlDeveloperUtPlsqlPlugin
44
46
private const int PluginPopupIndex = 1 ;
45
47
private const int PluginPopupIndexWithCoverage = 2 ;
46
48
49
+ private static SysOracleHome sysOracleHome ;
50
+
47
51
private static IdeConnected connected ;
48
52
private static IdeGetConnectionInfo getConnectionInfo ;
49
53
@@ -59,9 +63,9 @@ public class PlsqlDeveloperUtPlsqlPlugin
59
63
private static string password ;
60
64
private static string database ;
61
65
private static string connectAs ;
66
+ private static string oracleHome ;
62
67
63
68
private static PlsqlDeveloperUtPlsqlPlugin _plugin ;
64
-
65
69
private static readonly List < TestRunnerWindow > Windows = new List < TestRunnerWindow > ( ) ;
66
70
67
71
#region DLL exported API
@@ -83,7 +87,7 @@ public static void OnActivate()
83
87
{
84
88
try
85
89
{
86
- ConnectToDatabase ( ) ;
90
+ getDatabaseInformation ( ) ;
87
91
88
92
// Separate streams are needed!
89
93
var assembly = Assembly . GetExecutingAssembly ( ) ;
@@ -150,6 +154,9 @@ public static void RegisterCallback(int index, IntPtr function)
150
154
{
151
155
switch ( index )
152
156
{
157
+ case 4 :
158
+ sysOracleHome = ( SysOracleHome ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( SysOracleHome ) ) ;
159
+ break ;
153
160
case 11 :
154
161
connected = ( IdeConnected ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( IdeConnected ) ) ;
155
162
break ;
@@ -181,7 +188,7 @@ public static void RegisterCallback(int index, IntPtr function)
181
188
[ DllExport ( "OnConnectionChange" , CallingConvention = CallingConvention . Cdecl ) ]
182
189
public static void OnConnectionChange ( )
183
190
{
184
- ConnectToDatabase ( ) ;
191
+ getDatabaseInformation ( ) ;
185
192
}
186
193
187
194
[ DllExport ( "CreateMenuItem" , CallingConvention = CallingConvention . Cdecl ) ]
@@ -205,48 +212,55 @@ public static string CreateMenuItem(int index)
205
212
[ DllExport ( "OnMenuClick" , CallingConvention = CallingConvention . Cdecl ) ]
206
213
public static void OnMenuClick ( int index )
207
214
{
208
- if ( index == PluginMenuIndexAllTests )
215
+ try
209
216
{
210
- if ( connected ( ) && ! Sydba ( ) )
217
+ if ( index == PluginMenuIndexAllTests )
211
218
{
212
- var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
213
- Windows . Add ( testResultWindow ) ;
214
- testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , false ) ;
219
+ if ( isConnected ( ) && ! isSydba ( ) )
220
+ {
221
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs , oracleHome ) ;
222
+ Windows . Add ( testResultWindow ) ;
223
+ testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , false ) ;
224
+ }
215
225
}
216
- }
217
- else if ( index == PluginMenuIndexAllTestsWithCoverage )
218
- {
219
- if ( connected ( ) && ! Sydba ( ) )
226
+ else if ( index == PluginMenuIndexAllTestsWithCoverage )
220
227
{
221
- var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
222
- Windows . Add ( testResultWindow ) ;
223
- testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , true ) ;
228
+ if ( isConnected ( ) && ! isSydba ( ) )
229
+ {
230
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs , oracleHome ) ;
231
+ Windows . Add ( testResultWindow ) ;
232
+ testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , true ) ;
233
+ }
224
234
}
225
- }
226
- else if ( index == PluginPopupIndex )
227
- {
228
- if ( connected ( ) && ! Sydba ( ) )
235
+ else if ( index == PluginPopupIndex )
229
236
{
230
- getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
237
+ if ( isConnected ( ) && ! isSydba ( ) )
238
+ {
239
+ getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
231
240
232
- var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
233
- Windows . Add ( testResultWindow ) ;
234
- testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
235
- Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , false ) ;
241
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs , oracleHome ) ;
242
+ Windows . Add ( testResultWindow ) ;
243
+ testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
244
+ Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , false ) ;
245
+ }
236
246
}
237
- }
238
- else if ( index == PluginPopupIndexWithCoverage )
239
- {
240
- if ( connected ( ) && ! Sydba ( ) )
247
+ else if ( index == PluginPopupIndexWithCoverage )
241
248
{
242
- getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
249
+ if ( isConnected ( ) && ! isSydba ( ) )
250
+ {
251
+ getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
243
252
244
- var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
245
- Windows . Add ( testResultWindow ) ;
246
- testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
247
- Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , true ) ;
253
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs , oracleHome ) ;
254
+ Windows . Add ( testResultWindow ) ;
255
+ testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
256
+ Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , true ) ;
257
+ }
248
258
}
249
259
}
260
+ catch ( Exception e )
261
+ {
262
+ MessageBox . Show ( $ "{ e . Message } \n \n { e . StackTrace } ", "Unexpected Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
263
+ }
250
264
}
251
265
252
266
[ DllExport ( "About" , CallingConvention = CallingConvention . Cdecl ) ]
@@ -263,16 +277,27 @@ public void OpenPackageBody(string owner, string name)
263
277
var source = getObjectSource ( "PACKAGE BODY" , owner , name ) ;
264
278
createWindow ( 3 , Marshal . PtrToStringAnsi ( source ) , false ) ;
265
279
}
266
- private static bool Sydba ( )
280
+ private static bool isSydba ( )
267
281
{
268
- if ( connectAs . ToLower ( ) . Equals ( "sysdba" ) ) {
282
+ if ( connectAs . ToLower ( ) . Equals ( "sysdba" ) )
283
+ {
269
284
MessageBox . Show ( "You shouldn't run utPLSQL as SYSDBA.\n \n Test will not run." , "Connected as SYSDBA" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
270
285
return true ;
271
286
}
272
287
return false ;
273
288
}
274
289
275
- private static void ConnectToDatabase ( )
290
+ private static bool isConnected ( )
291
+ {
292
+ if ( ! connected ( ) )
293
+ {
294
+ MessageBox . Show ( "Please connect before running tests!" , "No connection" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
295
+ return false ;
296
+ }
297
+ return true ;
298
+ }
299
+
300
+ private static void getDatabaseInformation ( )
276
301
{
277
302
try
278
303
{
@@ -287,6 +312,10 @@ private static void ConnectToDatabase()
287
312
IntPtr ptrConnectAs = getConnectAs ( ) ;
288
313
289
314
connectAs = Marshal . PtrToStringAnsi ( ptrConnectAs ) ;
315
+
316
+ IntPtr ptrOracleHome = sysOracleHome ( ) ;
317
+
318
+ oracleHome = Marshal . PtrToStringAnsi ( ptrOracleHome ) ;
290
319
}
291
320
}
292
321
catch ( Exception e )
0 commit comments