Example #1
0
        /// <summary>
        /// Removes the registration of a plugin host class
        /// </summary>
        public static void UnRegisterHost(PluginHosts hostType, Type pluginClass)
        {
            ArrayList pluginsList;

            if (_pluginsClassType.TryGetValue(hostType, out pluginsList))
            {
                // remove from registered list
                pluginsList.Remove(pluginClass);
            }

            // remove from loaded list
            Dictionary <PluginHosts, List <PluginStore> > loadedList = LoadedPluginsList;
            List <PluginStore> plugins;

            if (loadedList != null &&
                loadedList.TryGetValue(hostType, out plugins))
            {
                for (int i = 0; i < plugins.Count; i++)
                {
                    PluginStore plugin = plugins[i];
                    if (plugin.ClassType == pluginClass)
                    {
                        plugins.RemoveAt(i);
                        break;
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Checks if there is any plugin class registered for specified type
        /// </summary>
        internal static bool IsPluginAvailable(PluginHosts hostType)
        {
            if (!_pluginsEnabled)
            {
                return(false);
            }

            if (_pluginsClassType.ContainsKey(hostType))
            {
                return(true);
            }
            return(false);
        }
Example #3
0
        /// <summary>
        /// Removes the registration of a plugin host class
        /// </summary>
        private static void UnRegisterHost(PluginHosts hostType)
        {
            // remove from registered list
            _pluginsClassType.Remove(hostType);

            // remove from loaded list
            Dictionary <PluginHosts, List <PluginStore> > loadedList = LoadedPluginsList;

            if (loadedList != null)
            {
                loadedList.Remove(hostType);
            }
        }
Example #4
0
        /// <summary>
        /// Registers plugin host
        /// </summary>
        public static void RegisterHost(PluginHosts hostType, Type pluginClass)
        {
            ArrayList added;

            // added plugins list
            if (!_pluginsClassType.TryGetValue(hostType, out added))
            {
                added = new ArrayList();
            }

            added.Add(pluginClass);
            _pluginsClassType[hostType] = added;
        }
Example #5
0
        /// <summary>
        /// Calls specified method of all specified hosts.
        /// </summary>
        internal static void CallPluginMethod(PluginHosts hostType, Enum methodNameEnum, params object[] arguments)
        {
            // Gets the available plugins list
            List <PluginStore> plugins = GetPluginsInstances(hostType);

            if (plugins != null && plugins.Count > 0)
            {
                // method name as enum
                string methodName = methodNameEnum.ToString();

                for (int i = 0; i < plugins.Count; i++)
                {
                    PluginStore pluginStore = plugins[i];
                    try
                    {
                        // getting requested method info using reflection
                        MethodInfo info = pluginStore.ClassType
                                          .GetMethod(methodName,
                                                     BindingFlags.Instance | BindingFlags.Public);

                        // call plugin with specifed arguments
                        info.Invoke(pluginStore.Instance, arguments);
                    }
                    catch (EPluginStopRequest)
                    {
                        // The plugin requested to stop the process
                        throw;
                    }
                    catch (Exception ex)
                    {
                        // the plugin requested to stop any operation
                        if (ex.InnerException is EPluginStopRequest)
                        {
                            throw;
                        }

                        if (Systems.LogSystem.ErrorLogEnabled)
                        {
                            Systems.LogSystem.LogError(ex, "Plugin method failed. IPluginEngine Plugin=" + plugins[i].ClassType + " MethodName=" + methodName, string.Empty);
                        }
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Creates and stores plugin class instances, then returns the their list
        /// </summary>
        private static List <PluginStore> GetPluginsInstances(PluginHosts hostType)
        {
            // reads loaded plugins list from context
            Dictionary <PluginHosts, List <PluginStore> > loadedPlugins = LoadedPluginsList;

            List <PluginStore> loaded;

            // if the request host is already created
            if (loadedPlugins.TryGetValue(hostType, out loaded))
            {
                // if there is any return it
                if (loaded.Count > 0)
                {
                    return(loaded);
                }
            }


            ArrayList available;

            // the plugin class is not created
            // trying to get the plugin class type if avaialble
            if (_pluginsClassType.TryGetValue(hostType, out available))
            {
                // new store list
                loaded = new List <PluginStore>();

                for (int i = 0; i < available.Count; i++)
                {
                    Type   classType = (Type)available[i];
                    object classObj;
                    try
                    {
                        // creatig a new instance of class type
                        classObj = InvokeDefaultCreateInstance(classType);

                        PluginStore store;
                        store.ClassType = classType;
                        store.Instance  = classObj;

                        loaded.Add(store);
                    }
                    catch (Exception ex)
                    {
                        if (Systems.LogSystem.ErrorLogEnabled)
                        {
                            Systems.LogSystem.LogError(ex, "Error in create new instance of plugin host: hostName=" + hostType, string.Empty);
                        }
                    }
                }

                // adding stored plugin in a collection
                loadedPlugins[hostType] = loaded;

                // and the result
                return(loaded);
            }

            // nothing found
            return(null);
        }
Example #7
0
        /// <summary>
        /// Creates and stores plugin class instances, then returns the their list
        /// </summary>
        private static List<PluginStore> GetPluginsInstances(PluginHosts hostType)
        {
            // reads loaded plugins list from context
            Dictionary<PluginHosts, List<PluginStore>> loadedPlugins = LoadedPluginsList;

            List<PluginStore> loaded;

            // if the request host is already created
            if (loadedPlugins.TryGetValue(hostType, out loaded))
            {
                // if there is any return it
                if (loaded.Count > 0)
                    return loaded;
            }


            ArrayList available;

            // the plugin class is not created
            // trying to get the plugin class type if avaialble
            if (_pluginsClassType.TryGetValue(hostType, out available))
            {
                // new store list
                loaded = new List<PluginStore>();

                for (int i = 0; i < available.Count; i++)
                {
                    Type classType = (Type)available[i];
                    object classObj;
                    try
                    {
                        // creatig a new instance of class type
                        classObj = InvokeDefaultCreateInstance(classType);

                        PluginStore store;
                        store.ClassType = classType;
                        store.Instance = classObj;

                        loaded.Add(store);
                    }
                    catch (Exception ex)
                    {
                        if (Systems.LogSystem.ErrorLogEnabled)
                            Systems.LogSystem.LogError(ex, "Error in create new instance of plugin host: hostName=" + hostType, string.Empty);
                    }
                }

                // adding stored plugin in a collection
                loadedPlugins[hostType] = loaded;

                // and the result
                return loaded;
            }

            // nothing found
            return null;
        }
Example #8
0
        /// <summary>
        /// Checks if there is any plugin class registered for specified type
        /// </summary>
        internal static bool IsPluginAvailable(PluginHosts hostType)
        {
            if (!_pluginsEnabled)
                return false;

            if (_pluginsClassType.ContainsKey(hostType))
            {
                return true;
            }
            return false;
        }
Example #9
0
        /// <summary>
        /// Calls specified method of all specified hosts.
        /// </summary>
        internal static void CallPluginMethod(PluginHosts hostType, Enum methodNameEnum, params object[] arguments)
        {
            // Gets the available plugins list
            List<PluginStore> plugins = GetPluginsInstances(hostType);
            if (plugins != null && plugins.Count > 0)
            {
                // method name as enum
                string methodName = methodNameEnum.ToString();

                for (int i = 0; i < plugins.Count; i++)
                {
                    PluginStore pluginStore = plugins[i];
                    try
                    {
                        // getting requested method info using reflection
                        MethodInfo info = pluginStore.ClassType
                            .GetMethod(methodName,
                            BindingFlags.Instance | BindingFlags.Public);

                        // call plugin with specifed arguments
                        info.Invoke(pluginStore.Instance, arguments);
                    }
                    catch (EPluginStopRequest)
                    {
                        // The plugin requested to stop the process
                        throw;
                    }
                    catch (Exception ex)
                    {
                        // the plugin requested to stop any operation
                        if (ex.InnerException is EPluginStopRequest)
                            throw;

                        if (Systems.LogSystem.ErrorLogEnabled)
                            Systems.LogSystem.LogError(ex, "Plugin method failed. IPluginEngine Plugin=" + plugins[i].ClassType + " MethodName=" + methodName, string.Empty);
                    }
                }
            }
        }
Example #10
0
        /// <summary>
        /// Removes the registration of a plugin host class
        /// </summary>
        private static void UnRegisterHost(PluginHosts hostType)
        {
            // remove from registered list
            _pluginsClassType.Remove(hostType);

            // remove from loaded list
            Dictionary<PluginHosts, List<PluginStore>> loadedList = LoadedPluginsList;
            if (loadedList != null)
                loadedList.Remove(hostType);
        }
Example #11
0
        /// <summary>
        /// Removes the registration of a plugin host class
        /// </summary>
        public static void UnRegisterHost(PluginHosts hostType, Type pluginClass)
        {
            ArrayList pluginsList;
            if (_pluginsClassType.TryGetValue(hostType, out pluginsList))
            {
                // remove from registered list
                pluginsList.Remove(pluginClass);
            }

            // remove from loaded list
            Dictionary<PluginHosts, List<PluginStore>> loadedList = LoadedPluginsList;
            List<PluginStore> plugins;
            if (loadedList != null &&
                loadedList.TryGetValue(hostType, out plugins))
            {
                for (int i = 0; i < plugins.Count; i++)
                {
                    PluginStore plugin = plugins[i];
                    if (plugin.ClassType == pluginClass)
                    {
                        plugins.RemoveAt(i);
                        break;
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Registers plugin host
        /// </summary>
        public static void RegisterHost(PluginHosts hostType, Type pluginClass)
        {
            ArrayList added;

            // added plugins list
            if (!_pluginsClassType.TryGetValue(hostType, out added))
                added = new ArrayList();

            added.Add(pluginClass);
            _pluginsClassType[hostType] = added;
        }