Пример #1
0
 private static IEnumerable <IPluginConfigurator> GetPluginConfigurators()
 {
     if (_pluginConfigurators == null)
     {
         _pluginConfigurators = PluginFinder.GetConfigurators(true);
     }
     return(_pluginConfigurators);
 }
Пример #2
0
        private static IEnumerable <IPluginConfigurator> GetPlugins(XmlNode section)
        {
            List <IPluginConfigurator>        plugins        = new List <IPluginConfigurator>();
            IEnumerable <IPluginConfigurator> dotlessPlugins = null; //lazy initiate incase of no plugins used
            List <string> assemblies = new List <string>();

            foreach (XmlNode node in section.SelectNodes("plugin"))
            {
                if (dotlessPlugins == null)
                {
                    dotlessPlugins = PluginFinder.GetConfigurators(false);
                }

                string assembly = GetStringValue(node, "assembly");

                if (assembly != null)
                {
                    if (!assemblies.Contains(assembly))
                    {
                        dotlessPlugins = dotlessPlugins.Union(PluginFinder.GetConfigurators(Assembly.Load(assembly)));
                        assemblies.Add(assembly);
                    }
                }

                string name   = GetStringValue(node, "name");
                var    plugin = dotlessPlugins.Where(p => p.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                                .FirstOrDefault();

                if (plugin == null)
                {
                    throw new Exception(
                              string.Format("Cannot find plugin called {0}. If it is an external plugin, make sure the assembly is referenced.", name));
                }
                var pluginParameters = plugin.GetParameters();

                foreach (XmlNode pluginParameter in node.SelectNodes("pluginParameter"))
                {
                    var pluginParameterName  = GetStringValue(pluginParameter, "name");
                    var pluginParameterValue = GetStringValue(pluginParameter, "value");

                    var actualParameter = pluginParameters
                                          .Where(p => p.Name.Equals(pluginParameterName, StringComparison.InvariantCultureIgnoreCase))
                                          .FirstOrDefault();

                    if (actualParameter == null)
                    {
                        throw new Exception(
                                  string.Format("Cannot find plugin argument {0} in plugin {1}", pluginParameterName, name));
                    }

                    actualParameter.SetValue(pluginParameterValue);
                }

                plugin.SetParameterValues(pluginParameters);
                plugins.Add(plugin);
            }
            return(plugins);
        }
Пример #3
0
        public void TestLoadingAndConfigurating()
        {
            IEnumerable <IPluginConfigurator> plugins = PluginFinder.GetConfigurators(Assembly.GetAssembly(typeof(PluginFixture)));

            Assert.AreEqual(2, plugins.Count());

            IPluginConfigurator plugin1 = plugins.ElementAt(0);
            IPluginConfigurator plugin2 = plugins.ElementAt(1);

            Assert.IsInstanceOf <GenericPluginConfigurator <TestPlugin1> >(plugin1);
            Assert.IsInstanceOf <TestPluginConfiguratorB>(plugin2);

            Assert.AreEqual("Plugin A", plugin1.Name);
            Assert.AreEqual("Plugin B", plugin2.Name);
            Assert.AreEqual("Plugs into A", plugin1.Description);
            Assert.AreEqual("Plugs into B", plugin2.Description);
        }