Exemple #1
0
        /// <summary>
        /// Initialize the plugin dependencies and execute its entry point.
        /// </summary>
        /// <param name="remoteParameters">Parameters containing the plugin to load
        /// and the parameters to pass to it's entry point.</param>
        /// <returns></returns>
        public static int Load(IntPtr remoteParameters)
        {
            try
            {
                if (remoteParameters == IntPtr.Zero)
                {
                    throw new ArgumentOutOfRangeException(nameof(remoteParameters),
                                                          "Remote arguments address was zero");
                }

                // Extract the plugin initialization information
                // from the remote host loader arguments.
                var remoteInfoFormatter = new UserDataBinaryFormatter();

                var pluginConfig =
                    PluginConfiguration <RemoteEntryInfo, ManagedRemoteInfo> .LoadData(
                        remoteParameters, remoteInfoFormatter
                        );

                IDependencyResolver resolver = CreateDependencyResolver(
                    pluginConfig.RemoteInfo.UserLibrary);

                // Construct the parameter array passed to the plugin initialization function.
                var pluginParameters = new object[1 + pluginConfig.RemoteInfo.UserParams.Length];

                pluginParameters[0] = pluginConfig.UnmanagedInfo;
                for (var i = 0; i < pluginConfig.RemoteInfo.UserParams.Length; ++i)
                {
                    pluginParameters[i + 1] = pluginConfig.RemoteInfo.UserParams[i];
                }

                DeserializeParameters(pluginParameters, remoteInfoFormatter);

                // Execute the plugin library's entry point and pass in the user arguments.
                pluginConfig.State = LoadPlugin(
                    resolver.Assembly,
                    pluginParameters,
                    pluginConfig.RemoteInfo.ChannelName);

                return((int)pluginConfig.State);
            }
            catch (ArgumentOutOfRangeException outOfRangeEx)
            {
                Log(outOfRangeEx.ToString());
                throw;
            }
            catch (Exception exception)
            {
                Log(exception.ToString());
            }
            return((int)PluginInitializationState.Failed);
        }
Exemple #2
0
        /// <summary>
        /// Initialize the plugin dependencies and execute its entry point.
        /// </summary>
        /// <param name="remoteParameters">Parameters containing the plugin to load
        /// and the parameters to pass to it's entry point.</param>
        /// <returns>A status code representing the plugin initialization state.</returns>
        public static int Load(IntPtr remoteParameters)
        {
            try
            {
                if (remoteParameters == IntPtr.Zero)
                {
                    throw new ArgumentOutOfRangeException(nameof(remoteParameters),
                                                          "Remote arguments address was zero");
                }

                // Extract the plugin initialization information
                // from the remote host loader arguments.
                IUserDataFormatter remoteInfoFormatter = CreateRemoteDataFormatter();

                var pluginConfig =
                    PluginConfiguration <RemoteEntryInfo, ManagedRemoteInfo> .LoadData(
                        remoteParameters, remoteInfoFormatter
                        );

                // Start the IPC message notifier with a connection to the host application.
                var hostNotifier = new NotificationHelper(pluginConfig.RemoteInfo.ChannelName);

                hostNotifier.Log($"Initializing plugin: {pluginConfig.RemoteInfo.UserLibrary}.");

                IDependencyResolver resolver = CreateDependencyResolver(
                    pluginConfig.RemoteInfo.UserLibrary);

                // Construct the parameter array passed to the plugin initialization function.
                var pluginParameters = new object[1 + pluginConfig.RemoteInfo.UserParams.Length];

                hostNotifier.Log($"Initializing plugin with {pluginParameters.Length} parameter(s).");

                pluginParameters[0] = pluginConfig.UnmanagedInfo;
                for (var i = 0; i < pluginConfig.RemoteInfo.UserParams.Length; ++i)
                {
                    pluginParameters[i + 1] = pluginConfig.RemoteInfo.UserParams[i];
                }

                hostNotifier.Log("Deserializing parameters.");

                DeserializeParameters(pluginParameters, remoteInfoFormatter);

                hostNotifier.Log("Successfully deserialized parameters.");

                // Execute the plugin library's entry point and pass in the user arguments.
                pluginConfig.State = LoadPlugin(
                    resolver.Assembly,
                    pluginParameters,
                    hostNotifier);

                return((int)pluginConfig.State);
            }
            catch (ArgumentOutOfRangeException outOfRangeEx)
            {
                Log(outOfRangeEx.ToString());
                throw;
            }
            catch (Exception e)
            {
                Log(e.ToString());
            }
            return((int)PluginInitializationState.Failed);
        }