5
5
using System . Linq ;
6
6
using System . Reflection ;
7
7
using System . Runtime . InteropServices ;
8
+ using System . Threading . Tasks ;
8
9
using System . Windows . Forms ;
9
10
10
11
namespace utPLSQL
@@ -28,6 +29,9 @@ internal delegate int IdeGetPopupObject(out IntPtr objectType, out IntPtr object
28
29
//*FUNC: 79*/ char *(*IDE_GetObjectSource)(char *ObjectType, char *ObjectOwner, char *ObjectName);
29
30
internal delegate IntPtr IdeGetObjectSource ( string objectType , string objectOwner , string objectName ) ;
30
31
32
+ //*FUNC: 97*/ extern char *(*IDE_GetConnectAs)();
33
+ internal delegate IntPtr IdeGetConnectAs ( ) ;
34
+
31
35
//*FUNC: 150*/ void (*IDE_CreateToolButton)(int ID, int Index, char *Name, char *BitmapFile, int BitmapHandle);
32
36
internal delegate void IdeCreateToolButton ( int id , int index , string name , string bitmapFile , long bitmapHandle ) ;
33
37
@@ -40,30 +44,26 @@ public class PlsqlDeveloperUtPlsqlPlugin
40
44
private const int PluginPopupIndex = 1 ;
41
45
private const int PluginPopupIndexWithCoverage = 2 ;
42
46
43
- internal static IdeConnected connected ;
44
- internal static IdeGetConnectionInfo getConnectionInfo ;
47
+ private static IdeConnected connected ;
48
+ private static IdeGetConnectionInfo getConnectionInfo ;
45
49
46
- internal static IdeCreateWindow createWindow ;
47
- internal static IdeCreatePopupItem createPopupItem ;
48
- internal static IdeGetPopupObject getPopupObject ;
49
- internal static IdeGetObjectSource getObjectSource ;
50
- internal static IdeCreateToolButton createToolButton ;
50
+ private static IdeCreateWindow createWindow ;
51
+ private static IdeCreatePopupItem createPopupItem ;
52
+ private static IdeGetPopupObject getPopupObject ;
53
+ private static IdeGetObjectSource getObjectSource ;
54
+ private static IdeGetConnectAs getConnectAs ;
55
+ private static IdeCreateToolButton createToolButton ;
51
56
52
- internal static int pluginId ;
53
- internal static string username ;
54
- internal static string password ;
55
- internal static string database ;
57
+ private static int pluginId ;
58
+ private static string username ;
59
+ private static string password ;
60
+ private static string database ;
61
+ private static string connectAs ;
56
62
57
63
private static PlsqlDeveloperUtPlsqlPlugin _plugin ;
58
- private static RealTimeTestRunner _testRunner ;
59
64
60
65
private static readonly List < TestRunnerWindow > Windows = new List < TestRunnerWindow > ( ) ;
61
66
62
- private PlsqlDeveloperUtPlsqlPlugin ( )
63
- {
64
- _testRunner = new RealTimeTestRunner ( ) ;
65
- }
66
-
67
67
#region DLL exported API
68
68
69
69
[ DllExport ( "IdentifyPlugIn" , CallingConvention = CallingConvention . Cdecl ) ]
@@ -169,6 +169,9 @@ public static void RegisterCallback(int index, IntPtr function)
169
169
case 79 :
170
170
getObjectSource = ( IdeGetObjectSource ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( IdeGetObjectSource ) ) ;
171
171
break ;
172
+ case 97 :
173
+ getConnectAs = ( IdeGetConnectAs ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( IdeGetConnectAs ) ) ;
174
+ break ;
172
175
case 150 :
173
176
createToolButton = ( IdeCreateToolButton ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( IdeCreateToolButton ) ) ;
174
177
break ;
@@ -204,41 +207,41 @@ public static void OnMenuClick(int index)
204
207
{
205
208
if ( index == PluginMenuIndexAllTests )
206
209
{
207
- if ( connected ( ) )
210
+ if ( connected ( ) && ! Sydba ( ) )
208
211
{
209
- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
212
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
210
213
Windows . Add ( testResultWindow ) ;
211
214
testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , false ) ;
212
215
}
213
216
}
214
217
else if ( index == PluginMenuIndexAllTestsWithCoverage )
215
218
{
216
- if ( connected ( ) )
219
+ if ( connected ( ) && ! Sydba ( ) )
217
220
{
218
- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
221
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
219
222
Windows . Add ( testResultWindow ) ;
220
223
testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , true ) ;
221
224
}
222
225
}
223
226
else if ( index == PluginPopupIndex )
224
227
{
225
- if ( connected ( ) )
228
+ if ( connected ( ) && ! Sydba ( ) )
226
229
{
227
230
getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
228
231
229
- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
232
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
230
233
Windows . Add ( testResultWindow ) ;
231
234
testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
232
235
Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , false ) ;
233
236
}
234
237
}
235
238
else if ( index == PluginPopupIndexWithCoverage )
236
239
{
237
- if ( connected ( ) )
240
+ if ( connected ( ) && ! Sydba ( ) )
238
241
{
239
242
getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
240
243
241
- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
244
+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
242
245
Windows . Add ( testResultWindow ) ;
243
246
testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
244
247
Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , true ) ;
@@ -260,13 +263,19 @@ public void OpenPackageBody(string owner, string name)
260
263
var source = getObjectSource ( "PACKAGE BODY" , owner , name ) ;
261
264
createWindow ( 3 , Marshal . PtrToStringAnsi ( source ) , false ) ;
262
265
}
266
+ private static bool Sydba ( )
267
+ {
268
+ if ( connectAs . ToLower ( ) . Equals ( "sysdba" ) ) {
269
+ MessageBox . Show ( "You shouldn't run utPLSQL as SYSDBA.\n \n Test will not run." , "Connected as SYSDBA" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
270
+ return true ;
271
+ }
272
+ return false ;
273
+ }
263
274
264
275
private static void ConnectToDatabase ( )
265
276
{
266
277
try
267
278
{
268
- _testRunner . Close ( ) ;
269
-
270
279
if ( connected ( ) )
271
280
{
272
281
getConnectionInfo ( out IntPtr ptrUsername , out IntPtr ptrPassword , out IntPtr ptrDatabase ) ;
@@ -275,7 +284,9 @@ private static void ConnectToDatabase()
275
284
password = Marshal . PtrToStringAnsi ( ptrPassword ) ;
276
285
database = Marshal . PtrToStringAnsi ( ptrDatabase ) ;
277
286
278
- _testRunner . Connect ( username , password , database ) ;
287
+ IntPtr ptrConnectAs = getConnectAs ( ) ;
288
+
289
+ connectAs = Marshal . PtrToStringAnsi ( ptrConnectAs ) ;
279
290
}
280
291
}
281
292
catch ( Exception e )
0 commit comments