55using System . Linq ;
66using System . Reflection ;
77using System . Runtime . InteropServices ;
8+ using System . Threading . Tasks ;
89using System . Windows . Forms ;
910
1011namespace utPLSQL
@@ -28,6 +29,9 @@ internal delegate int IdeGetPopupObject(out IntPtr objectType, out IntPtr object
2829 //*FUNC: 79*/ char *(*IDE_GetObjectSource)(char *ObjectType, char *ObjectOwner, char *ObjectName);
2930 internal delegate IntPtr IdeGetObjectSource ( string objectType , string objectOwner , string objectName ) ;
3031
32+ //*FUNC: 97*/ extern char *(*IDE_GetConnectAs)();
33+ internal delegate IntPtr IdeGetConnectAs ( ) ;
34+
3135 //*FUNC: 150*/ void (*IDE_CreateToolButton)(int ID, int Index, char *Name, char *BitmapFile, int BitmapHandle);
3236 internal delegate void IdeCreateToolButton ( int id , int index , string name , string bitmapFile , long bitmapHandle ) ;
3337
@@ -40,30 +44,26 @@ public class PlsqlDeveloperUtPlsqlPlugin
4044 private const int PluginPopupIndex = 1 ;
4145 private const int PluginPopupIndexWithCoverage = 2 ;
4246
43- internal static IdeConnected connected ;
44- internal static IdeGetConnectionInfo getConnectionInfo ;
47+ private static IdeConnected connected ;
48+ private static IdeGetConnectionInfo getConnectionInfo ;
4549
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 ;
5156
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 ;
5662
5763 private static PlsqlDeveloperUtPlsqlPlugin _plugin ;
58- private static RealTimeTestRunner _testRunner ;
5964
6065 private static readonly List < TestRunnerWindow > Windows = new List < TestRunnerWindow > ( ) ;
6166
62- private PlsqlDeveloperUtPlsqlPlugin ( )
63- {
64- _testRunner = new RealTimeTestRunner ( ) ;
65- }
66-
6767 #region DLL exported API
6868
6969 [ DllExport ( "IdentifyPlugIn" , CallingConvention = CallingConvention . Cdecl ) ]
@@ -169,6 +169,9 @@ public static void RegisterCallback(int index, IntPtr function)
169169 case 79 :
170170 getObjectSource = ( IdeGetObjectSource ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( IdeGetObjectSource ) ) ;
171171 break ;
172+ case 97 :
173+ getConnectAs = ( IdeGetConnectAs ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( IdeGetConnectAs ) ) ;
174+ break ;
172175 case 150 :
173176 createToolButton = ( IdeCreateToolButton ) Marshal . GetDelegateForFunctionPointer ( function , typeof ( IdeCreateToolButton ) ) ;
174177 break ;
@@ -204,41 +207,41 @@ public static void OnMenuClick(int index)
204207 {
205208 if ( index == PluginMenuIndexAllTests )
206209 {
207- if ( connected ( ) )
210+ if ( connected ( ) && ! Sydba ( ) )
208211 {
209- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
212+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
210213 Windows . Add ( testResultWindow ) ;
211214 testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , false ) ;
212215 }
213216 }
214217 else if ( index == PluginMenuIndexAllTestsWithCoverage )
215218 {
216- if ( connected ( ) )
219+ if ( connected ( ) && ! Sydba ( ) )
217220 {
218- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
221+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
219222 Windows . Add ( testResultWindow ) ;
220223 testResultWindow . RunTestsAsync ( "_ALL" , username , null , null , true ) ;
221224 }
222225 }
223226 else if ( index == PluginPopupIndex )
224227 {
225- if ( connected ( ) )
228+ if ( connected ( ) && ! Sydba ( ) )
226229 {
227230 getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
228231
229- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
232+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
230233 Windows . Add ( testResultWindow ) ;
231234 testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
232235 Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , false ) ;
233236 }
234237 }
235238 else if ( index == PluginPopupIndexWithCoverage )
236239 {
237- if ( connected ( ) )
240+ if ( connected ( ) && ! Sydba ( ) )
238241 {
239242 getPopupObject ( out IntPtr type , out IntPtr owner , out IntPtr name , out IntPtr subType ) ;
240243
241- var testResultWindow = new TestRunnerWindow ( _testRunner , _plugin ) ;
244+ var testResultWindow = new TestRunnerWindow ( _plugin , username , password , database , connectAs ) ;
242245 Windows . Add ( testResultWindow ) ;
243246 testResultWindow . RunTestsAsync ( Marshal . PtrToStringAnsi ( type ) , Marshal . PtrToStringAnsi ( owner ) ,
244247 Marshal . PtrToStringAnsi ( name ) , Marshal . PtrToStringAnsi ( subType ) , true ) ;
@@ -260,13 +263,19 @@ public void OpenPackageBody(string owner, string name)
260263 var source = getObjectSource ( "PACKAGE BODY" , owner , name ) ;
261264 createWindow ( 3 , Marshal . PtrToStringAnsi ( source ) , false ) ;
262265 }
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+ }
263274
264275 private static void ConnectToDatabase ( )
265276 {
266277 try
267278 {
268- _testRunner . Close ( ) ;
269-
270279 if ( connected ( ) )
271280 {
272281 getConnectionInfo ( out IntPtr ptrUsername , out IntPtr ptrPassword , out IntPtr ptrDatabase ) ;
@@ -275,7 +284,9 @@ private static void ConnectToDatabase()
275284 password = Marshal . PtrToStringAnsi ( ptrPassword ) ;
276285 database = Marshal . PtrToStringAnsi ( ptrDatabase ) ;
277286
278- _testRunner . Connect ( username , password , database ) ;
287+ IntPtr ptrConnectAs = getConnectAs ( ) ;
288+
289+ connectAs = Marshal . PtrToStringAnsi ( ptrConnectAs ) ;
279290 }
280291 }
281292 catch ( Exception e )
0 commit comments