Exemplo n.º 1
0
        /// <summary>Gets plugins in the current app domain using the type finder.</summary>
        /// <returns>An enumeration of available plugins.</returns>
        public IEnumerable <IPluginDefinition> GetPluginDefinitions()
        {
            List <IPluginDefinition> pluginDefinitions = new List <IPluginDefinition>();

            // assembly defined plugins
            foreach (ICustomAttributeProvider assembly in typeFinder.GetAssemblies())
            {
                foreach (PluginAttribute plugin in assembly.GetCustomAttributes(typeof(PluginAttribute), false))
                {
                    if (!IsRemoved(plugin.InitializerType))
                    {
                        pluginDefinitions.Add(plugin);
                    }
                }
            }

            // autoinitialize plugins
            foreach (Type type in typeFinder.Find(typeof(IPluginInitializer)))
            {
                foreach (AutoInitializeAttribute plugin in type.GetCustomAttributes(typeof(AutoInitializeAttribute), true))
                {
                    plugin.InitializerType = type;

                    if (!IsRemoved(type))
                    {
                        pluginDefinitions.Add(plugin);
                    }
                }
            }

            // configured plugins
            foreach (PluginInitializerElement configElement in addedInitializers)
            {
                Type pluginType = Type.GetType(configElement.Type);
                if (pluginType == null)
                {
                    throw new N2Exception("Could not find the configured plugin initializer type '{0}'", configElement.Type);
                }
                if (typeof(IPluginDefinition).IsAssignableFrom(pluginType))
                {
                    throw new N2Exception("The configured plugin initializer type '{0}' is not a valid plugin initializer since it doesn't implement the IPluginDefinition interface.", configElement.Type);
                }

                PluginAttribute plugin = new PluginAttribute();
                plugin.Name            = configElement.Name;
                plugin.InitializerType = pluginType;
                plugin.Title           = "Configured plugin " + configElement.Name;
                pluginDefinitions.Add(plugin);
            }

            return(pluginDefinitions);
        }
Exemplo n.º 2
0
        /// <summary>Gets plugins in the current app domain using the type finder.</summary>
        /// <returns>An enumeration of available plugins.</returns>
        public IEnumerable<IPluginDefinition> GetPluginDefinitions()
        {
            List<IPluginDefinition> pluginDefinitions = new List<IPluginDefinition>();

            // assembly defined plugins
            foreach (ICustomAttributeProvider assembly in typeFinder.GetAssemblies())
            {
                foreach (PluginAttribute plugin in assembly.GetCustomAttributes(typeof(PluginAttribute), false))
                {
                    if (!IsRemoved(plugin.InitializerType))
                        pluginDefinitions.Add(plugin);
                }
            }
            
            // autoinitialize plugins
            foreach(Type type in typeFinder.Find(typeof(IPluginInitializer)))
            {
                foreach (AutoInitializeAttribute plugin in type.GetCustomAttributes(typeof(AutoInitializeAttribute), true))
                {
                    plugin.InitializerType = type;

                    if (!IsRemoved(type))
                        pluginDefinitions.Add(plugin);
                }
            }
        
            // configured plugins
            foreach (PluginInitializerElement configElement in addedInitializers)
            {
                Type pluginType = Type.GetType(configElement.Type);
                if (pluginType == null)
                    throw new N2Exception("Could not find the configured plugin initializer type '{0}'", configElement.Type);
                if (typeof(IPluginDefinition).IsAssignableFrom(pluginType))
                    throw new N2Exception("The configured plugin initializer type '{0}' is not a valid plugin initializer since it doesn't implement the IPluginDefinition interface.", configElement.Type);

                PluginAttribute plugin = new PluginAttribute();
                plugin.Name = configElement.Name;
                plugin.InitializerType = pluginType;
                plugin.Title = "Configured plugin " + configElement.Name;
                pluginDefinitions.Add(plugin);
            }

            return pluginDefinitions;
        }