Esempio n. 1
0
        /// <summary>
        /// Find the entry point of the plugin module, initialize it, and execute its Run method.
        /// </summary>
        /// <param name="assembly">The plugin assembly containing the entry point.</param>
        /// <param name="paramArray">The parameters passed to the plugin Run method.</param>
        /// <param name="helperPipeName">Pipe name used to notify the host about the state of the plugin initialization.</param>
        private static PluginInitializationState LoadPlugin(Assembly assembly, object[] paramArray, string helperPipeName)
        {
            Type entryPoint = FindEntryPoint(assembly);

            MethodInfo runMethod = FindMatchingMethod(entryPoint, EntryPointMethodName, paramArray);

            if (runMethod == null)
            {
                throw new MissingMethodException($"Failed to find the function 'Run' in {assembly.FullName}");
            }

            var instance = InitializeInstance(entryPoint, paramArray);

            if (instance == null)
            {
                throw new MissingMethodException($"Failed to find the constructor {entryPoint.Name} in {assembly.FullName}");
            }

            if (NotificationHelper.SendInjectionComplete(helperPipeName, Process.GetCurrentProcess().Id))
            {
                try
                {
                    // Execute the CoreHook plugin entry point
                    runMethod.Invoke(instance, BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding |
                                     BindingFlags.InvokeMethod, null, paramArray, null);
                }
                catch
                {
                }
                return(PluginInitializationState.Initialized);
            }
            return(PluginInitializationState.Failed);
        }
Esempio n. 2
0
        /// <summary>
        /// Find the entry point of the plugin module, initialize it, and execute its Run method.
        /// </summary>
        /// <param name="assembly">The plugin assembly containing the entry point.</param>
        /// <param name="paramArray">The parameters passed to the plugin Run method.</param>
        /// <param name="hostNotifier">Used to notify the host about the state of the plugin initialization.</param>
        private static PluginInitializationState LoadPlugin(Assembly assembly, object[] paramArray, NotificationHelper hostNotifier)
        {
            Type entryPoint = FindEntryPoint(assembly);

            MethodInfo runMethod = FindMatchingMethod(entryPoint, EntryPointMethodName, paramArray);

            if (runMethod == null)
            {
                Log(hostNotifier,
                    new MissingMethodException(
                        $"Failed to find the 'Run' function with {paramArray.Length} parameter(s) in {assembly.FullName}."));
            }

            hostNotifier.Log("Found entry point, initializing plugin class.");

            var instance = InitializeInstance(entryPoint, paramArray);

            if (instance == null)
            {
                Log(hostNotifier,
                    new MissingMethodException(
                        $"Failed to find the constructor {entryPoint.Name} in {assembly.FullName}"));
            }
            hostNotifier.Log("Plugin successfully initialized. Executing the plugin entry point.");

            if (hostNotifier.SendInjectionComplete(Process.GetCurrentProcess().Id))
            {
                // Close the plugin loading message channel.
                hostNotifier.Dispose();

                try
                {
                    // Execute the plugin 'Run' entry point.
                    runMethod?.Invoke(instance, BindingFlags.Public | BindingFlags.Instance | BindingFlags.ExactBinding |
                                      BindingFlags.InvokeMethod, null, paramArray, null);
                }
                catch
                {
                }
                return(PluginInitializationState.Initialized);
            }
            return(PluginInitializationState.Failed);
        }