|
| 1 | +using System; |
| 2 | +using RGiesecke.DllExport; |
| 3 | +using System.Runtime.InteropServices; |
| 4 | +using System.Windows.Forms; |
| 5 | +using System.Drawing; |
| 6 | +using System.Reflection; |
| 7 | +using System.IO; |
| 8 | + |
| 9 | +namespace PlsqlDeveloperUtPlsqlPlugin |
| 10 | +{ |
| 11 | + //*FUNC: 11*/ BOOL (*IDE_Connected)(); |
| 12 | + internal delegate bool IdeConnected(); |
| 13 | + //*FUNC: 12*/ void (*IDE_GetConnectionInfo)(char **Username, char **Password, char **Database); |
| 14 | + internal delegate void IdeGetConnectionInfo(out IntPtr username, out IntPtr password, out IntPtr database); |
| 15 | + |
| 16 | + //*FUNC: 40*/ int (*SQL_Execute)(char *SQL); |
| 17 | + internal delegate int SqlExecute(string sql); |
| 18 | + //*FUNC: 42*/ BOOL (*SQL_Eof)(); |
| 19 | + internal delegate bool SqlEof(); |
| 20 | + //*FUNC: 43*/ int (*SQL_Next)(); |
| 21 | + internal delegate int SqlNext(); |
| 22 | + //*FUNC: 44*/ char *(*SQL_Field)(int Field); |
| 23 | + internal delegate IntPtr SqlField(int field); |
| 24 | + //*FUNC: 48*/ char *(*SQL_ErrorMessage)(); |
| 25 | + internal delegate IntPtr SqlErrorMessage(); |
| 26 | + |
| 27 | + //*FUNC: 69*/ void *(*IDE_CreatePopupItem)(int ID, int Index, char *Name, char *ObjectType); |
| 28 | + internal delegate void IdeCreatePopupItem(int id, int index, string name, string objectType); |
| 29 | + //*FUNC: 74*/ int (*IDE_GetPopupObject)(char **ObjectType, char **ObjectOwner, char **ObjectName, char **SubObject); |
| 30 | + internal delegate int IdeGetPopupObject(out IntPtr objectType, out IntPtr objectOwner, out IntPtr objectName, out IntPtr subObject); |
| 31 | + //*FUNC: 150*/ void (*IDE_CreateToolButton)(int ID, int Index, char *Name, char *BitmapFile, int BitmapHandle); |
| 32 | + internal delegate void IdeCreateToolButton(int id, int index, string name, string bitmapFile, long bitmapHandle); |
| 33 | + |
| 34 | + public class PlsqlDeveloperUtPlsqlPlugin |
| 35 | + { |
| 36 | + private const string PLUGIN_NAME = "utPLSQL Plugin"; |
| 37 | + |
| 38 | + private const int PLUGIN_MENU_INDEX_ALLTESTS = 3; |
| 39 | + private const int PLUGIN_POPUP_INDEX = 1; |
| 40 | + |
| 41 | + private const string ABOUT_TEXT = "utPLSQL Plugin for PL/SQL Developer \r\nby Simon Martinelli, 72® Services LLC"; |
| 42 | + |
| 43 | + private static PlsqlDeveloperUtPlsqlPlugin plugin; |
| 44 | + |
| 45 | + internal static IdeConnected connected; |
| 46 | + internal static IdeGetConnectionInfo getConnectionInfo; |
| 47 | + |
| 48 | + internal static SqlExecute sqlExecute; |
| 49 | + internal static SqlEof sqlEof; |
| 50 | + internal static SqlNext sqlNext; |
| 51 | + internal static SqlField sqlField; |
| 52 | + internal static SqlErrorMessage sqlErrorMessage; |
| 53 | + |
| 54 | + internal static IdeCreatePopupItem createPopupItem; |
| 55 | + internal static IdeGetPopupObject getPopupObject; |
| 56 | + internal static IdeCreateToolButton createToolButton; |
| 57 | + |
| 58 | + internal static int pluginId; |
| 59 | + |
| 60 | + private static TestResultWindow testResultWindow ; |
| 61 | + |
| 62 | + private PlsqlDeveloperUtPlsqlPlugin() |
| 63 | + { |
| 64 | + testResultWindow = new TestResultWindow(); |
| 65 | + } |
| 66 | + |
| 67 | + #region DLL exported API |
| 68 | + [DllExport("IdentifyPlugIn", CallingConvention = CallingConvention.Cdecl)] |
| 69 | + public static string IdentifyPlugIn(int id) |
| 70 | + { |
| 71 | + if (plugin == null) |
| 72 | + { |
| 73 | + plugin = new PlsqlDeveloperUtPlsqlPlugin(); |
| 74 | + pluginId = id; |
| 75 | + } |
| 76 | + return PLUGIN_NAME; |
| 77 | + } |
| 78 | + |
| 79 | + [DllExport("RegisterCallback", CallingConvention = CallingConvention.Cdecl)] |
| 80 | + public static void RegisterCallback(int index, IntPtr function) |
| 81 | + { |
| 82 | + switch (index) |
| 83 | + { |
| 84 | + case 11: |
| 85 | + connected = (IdeConnected)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeConnected)); |
| 86 | + break; |
| 87 | + case 12: |
| 88 | + getConnectionInfo = (IdeGetConnectionInfo)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeGetConnectionInfo)); |
| 89 | + break; |
| 90 | + case 40: |
| 91 | + sqlExecute = (SqlExecute)Marshal.GetDelegateForFunctionPointer(function, typeof(SqlExecute)); |
| 92 | + break; |
| 93 | + case 42: |
| 94 | + sqlEof = (SqlEof)Marshal.GetDelegateForFunctionPointer(function, typeof(SqlEof)); |
| 95 | + break; |
| 96 | + case 43: |
| 97 | + sqlNext = (SqlNext)Marshal.GetDelegateForFunctionPointer(function, typeof(SqlNext)); |
| 98 | + break; |
| 99 | + case 44: |
| 100 | + sqlField = (SqlField)Marshal.GetDelegateForFunctionPointer(function, typeof(SqlField)); |
| 101 | + break; |
| 102 | + case 48: |
| 103 | + sqlErrorMessage = (SqlErrorMessage)Marshal.GetDelegateForFunctionPointer(function, typeof(SqlErrorMessage)); |
| 104 | + break; |
| 105 | + case 69: |
| 106 | + createPopupItem = (IdeCreatePopupItem)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeCreatePopupItem)); |
| 107 | + break; |
| 108 | + case 74: |
| 109 | + getPopupObject = (IdeGetPopupObject)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeGetPopupObject)); |
| 110 | + break; |
| 111 | + case 150: |
| 112 | + createToolButton = (IdeCreateToolButton)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeCreateToolButton)); |
| 113 | + break; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + [DllExport("CreateMenuItem", CallingConvention = CallingConvention.Cdecl)] |
| 118 | + public static string CreateMenuItem(int index) |
| 119 | + { |
| 120 | + switch (index) |
| 121 | + { |
| 122 | + case 1: |
| 123 | + return "TAB=Tools"; |
| 124 | + case 2: |
| 125 | + return "GROUP=utPLSQL"; |
| 126 | + case PLUGIN_MENU_INDEX_ALLTESTS: |
| 127 | + return "LARGEITEM=Run all tests of current user"; |
| 128 | + default: |
| 129 | + return ""; |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + [DllExport("OnActivate", CallingConvention = CallingConvention.Cdecl)] |
| 134 | + public static void OnActivate() |
| 135 | + { |
| 136 | + try |
| 137 | + { |
| 138 | + // Two seperate streams are needed! |
| 139 | + var assembly = Assembly.GetExecutingAssembly(); |
| 140 | + using (Stream stream = assembly.GetManifestResourceStream("PlsqlDeveloperUtPlsqlPlugin.utPLSQL.bmp")) |
| 141 | + { |
| 142 | + createToolButton(pluginId, PLUGIN_MENU_INDEX_ALLTESTS, "utPLSQL", "utPLSQL.bmp", new Bitmap(stream).GetHbitmap().ToInt64()); |
| 143 | + } |
| 144 | + using (Stream stream = assembly.GetManifestResourceStream("PlsqlDeveloperUtPlsqlPlugin.utPLSQL.bmp")) |
| 145 | + { |
| 146 | + createToolButton(pluginId, PLUGIN_POPUP_INDEX, "utPLSQL", "utPLSQL.bmp", new Bitmap(stream).GetHbitmap().ToInt64()); |
| 147 | + } |
| 148 | + } |
| 149 | + catch (Exception e) |
| 150 | + { |
| 151 | + MessageBox.Show(e.Message); |
| 152 | + } |
| 153 | + createPopupItem(pluginId, PLUGIN_POPUP_INDEX, "Run utPLSQL Test", "USER"); |
| 154 | + createPopupItem(pluginId, PLUGIN_POPUP_INDEX, "Run utPLSQL Test", "PACKAGE"); |
| 155 | + } |
| 156 | + |
| 157 | + [DllExport("OnMenuClick", CallingConvention = CallingConvention.Cdecl)] |
| 158 | + public static void OnMenuClick(int index) |
| 159 | + { |
| 160 | + if (index == PLUGIN_MENU_INDEX_ALLTESTS) |
| 161 | + { |
| 162 | + if (PlsqlDeveloperUtPlsqlPlugin.connected()) |
| 163 | + { |
| 164 | + IntPtr username; |
| 165 | + IntPtr password; |
| 166 | + IntPtr database; |
| 167 | + getConnectionInfo(out username, out password, out database); |
| 168 | + |
| 169 | + testResultWindow.RunTests("_ALL", Marshal.PtrToStringAnsi(username), null, null); |
| 170 | + } |
| 171 | + } |
| 172 | + else if (index == PLUGIN_POPUP_INDEX) |
| 173 | + { |
| 174 | + if (PlsqlDeveloperUtPlsqlPlugin.connected()) |
| 175 | + { |
| 176 | + IntPtr type; |
| 177 | + IntPtr owner; |
| 178 | + IntPtr name; |
| 179 | + IntPtr subType; |
| 180 | + getPopupObject(out type, out owner, out name, out subType); |
| 181 | + |
| 182 | + testResultWindow.RunTests(Marshal.PtrToStringAnsi(type), Marshal.PtrToStringAnsi(owner), Marshal.PtrToStringAnsi(name), Marshal.PtrToStringAnsi(subType)); |
| 183 | + } |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + [DllExport("About", CallingConvention = CallingConvention.Cdecl)] |
| 188 | + public static string About() |
| 189 | + { |
| 190 | + MessageBox.Show(ABOUT_TEXT); |
| 191 | + return ""; |
| 192 | + } |
| 193 | + #endregion |
| 194 | + } |
| 195 | +} |
0 commit comments