1010
1111namespace  utPLSQL 
1212{ 
13+     //*FUNC: 4*/ extern char *(*SYS_OracleHome)(); 
14+     internal  delegate  IntPtr  SysOracleHome ( ) ; 
15+ 
1316    //*FUNC: 11*/ BOOL (*IDE_Connected)(); 
1417    internal  delegate  bool  IdeConnected ( ) ; 
1518
@@ -23,8 +26,7 @@ namespace utPLSQL
2326    internal  delegate  void  IdeCreatePopupItem ( int  id ,  int  index ,  string  name ,  string  objectType ) ; 
2427
2528    //*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 ) ; 
2830
2931    //*FUNC: 79*/ char *(*IDE_GetObjectSource)(char *ObjectType, char *ObjectOwner, char *ObjectName); 
3032    internal  delegate  IntPtr  IdeGetObjectSource ( string  objectType ,  string  objectOwner ,  string  objectName ) ; 
@@ -44,6 +46,8 @@ public class PlsqlDeveloperUtPlsqlPlugin
4446        private  const  int  PluginPopupIndex  =  1 ; 
4547        private  const  int  PluginPopupIndexWithCoverage  =  2 ; 
4648
49+         private  static   SysOracleHome  sysOracleHome ; 
50+ 
4751        private  static   IdeConnected  connected ; 
4852        private  static   IdeGetConnectionInfo  getConnectionInfo ; 
4953
@@ -59,9 +63,9 @@ public class PlsqlDeveloperUtPlsqlPlugin
5963        private  static   string  password ; 
6064        private  static   string  database ; 
6165        private  static   string  connectAs ; 
66+         private  static   string  oracleHome ; 
6267
6368        private  static   PlsqlDeveloperUtPlsqlPlugin  _plugin ; 
64- 
6569        private  static   readonly  List < TestRunnerWindow >  Windows  =  new  List < TestRunnerWindow > ( ) ; 
6670
6771        #region DLL exported API
@@ -83,7 +87,7 @@ public static void OnActivate()
8387        { 
8488            try 
8589            { 
86-                 ConnectToDatabase ( ) ; 
90+                 getDatabaseInformation ( ) ; 
8791
8892                // Separate streams are needed! 
8993                var  assembly  =  Assembly . GetExecutingAssembly ( ) ; 
@@ -150,6 +154,9 @@ public static void RegisterCallback(int index, IntPtr function)
150154        { 
151155            switch  ( index ) 
152156            { 
157+                 case  4 : 
158+                     sysOracleHome  =  ( SysOracleHome ) Marshal . GetDelegateForFunctionPointer ( function ,  typeof ( SysOracleHome ) ) ; 
159+                     break ; 
153160                case  11 : 
154161                    connected  =  ( IdeConnected ) Marshal . GetDelegateForFunctionPointer ( function ,  typeof ( IdeConnected ) ) ; 
155162                    break ; 
@@ -181,7 +188,7 @@ public static void RegisterCallback(int index, IntPtr function)
181188        [ DllExport ( "OnConnectionChange" ,  CallingConvention  =  CallingConvention . Cdecl ) ] 
182189        public  static   void  OnConnectionChange ( ) 
183190        { 
184-             ConnectToDatabase ( ) ; 
191+             getDatabaseInformation ( ) ; 
185192        } 
186193
187194        [ DllExport ( "CreateMenuItem" ,  CallingConvention  =  CallingConvention . Cdecl ) ] 
@@ -205,48 +212,55 @@ public static string CreateMenuItem(int index)
205212        [ DllExport ( "OnMenuClick" ,  CallingConvention  =  CallingConvention . Cdecl ) ] 
206213        public  static   void  OnMenuClick ( int  index ) 
207214        { 
208-             if   ( index   ==   PluginMenuIndexAllTests ) 
215+             try 
209216            { 
210-                 if  ( connected ( )   &&   ! Sydba ( ) ) 
217+                 if  ( index   ==   PluginMenuIndexAllTests ) 
211218                { 
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+                     } 
215225                } 
216-             } 
217-             else  if  ( index  ==  PluginMenuIndexAllTestsWithCoverage ) 
218-             { 
219-                 if  ( connected ( )  &&  ! Sydba ( ) ) 
226+                 else  if  ( index  ==  PluginMenuIndexAllTestsWithCoverage ) 
220227                { 
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+                     } 
224234                } 
225-             } 
226-             else  if  ( index  ==  PluginPopupIndex ) 
227-             { 
228-                 if  ( connected ( )  &&  ! Sydba ( ) ) 
235+                 else  if  ( index  ==  PluginPopupIndex ) 
229236                { 
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 ) ; 
231240
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+                     } 
236246                } 
237-             } 
238-             else  if  ( index  ==  PluginPopupIndexWithCoverage ) 
239-             { 
240-                 if  ( connected ( )  &&  ! Sydba ( ) ) 
247+                 else  if  ( index  ==  PluginPopupIndexWithCoverage ) 
241248                { 
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 ) ; 
243252
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+                     } 
248258                } 
249259            } 
260+             catch  ( Exception  e ) 
261+             { 
262+                 MessageBox . Show ( $ "{ e . Message } \n \n { e . StackTrace } ",  "Unexpected Error" ,  MessageBoxButtons . OK ,  MessageBoxIcon . Error ) ; 
263+             } 
250264        } 
251265
252266        [ DllExport ( "About" ,  CallingConvention  =  CallingConvention . Cdecl ) ] 
@@ -263,16 +277,27 @@ public void OpenPackageBody(string owner, string name)
263277            var  source  =  getObjectSource ( "PACKAGE BODY" ,  owner ,  name ) ; 
264278            createWindow ( 3 ,  Marshal . PtrToStringAnsi ( source ) ,  false ) ; 
265279        } 
266-         private  static   bool  Sydba ( ) 
280+         private  static   bool  isSydba ( ) 
267281        { 
268-             if  ( connectAs . ToLower ( ) . Equals ( "sysdba" ) )  { 
282+             if  ( connectAs . ToLower ( ) . Equals ( "sysdba" ) ) 
283+             { 
269284                MessageBox . Show ( "You shouldn't run utPLSQL as SYSDBA.\n \n Test will not run." ,  "Connected as SYSDBA" ,  MessageBoxButtons . OK ,  MessageBoxIcon . Error ) ; 
270285                return  true ; 
271286            } 
272287            return  false ; 
273288        } 
274289
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 ( ) 
276301        { 
277302            try 
278303            { 
@@ -287,6 +312,10 @@ private static void ConnectToDatabase()
287312                    IntPtr  ptrConnectAs  =  getConnectAs ( ) ; 
288313
289314                    connectAs  =  Marshal . PtrToStringAnsi ( ptrConnectAs ) ; 
315+ 
316+                     IntPtr  ptrOracleHome  =  sysOracleHome ( ) ; 
317+ 
318+                     oracleHome  =  Marshal . PtrToStringAnsi ( ptrOracleHome ) ; 
290319                } 
291320            } 
292321            catch  ( Exception  e ) 
0 commit comments