Ejemplo n.º 1
0
        private static List <TerrainPlugin> readAvailablePlugins()
        {
            List <TerrainPlugin> plugins = new List <TerrainPlugin>();

            string pluginsPath = PLUGINS_PATH;

            Console.Out.WriteLine("Plugins path: " + pluginsPath);
            Console.Out.WriteLine("Loading plugins...");
            string[] dllFileNames = null;
            if (Directory.Exists(pluginsPath))
            {
                dllFileNames = Directory.GetFiles(pluginsPath, "*.dll");

                ICollection <Assembly> assemblies = new List <Assembly>(dllFileNames.Length);
                foreach (string dllFile in dllFileNames)
                {
                    AssemblyName an       = AssemblyName.GetAssemblyName(dllFile);
                    Assembly     assembly = Assembly.Load(an);
                    assemblies.Add(assembly);
                }

                Type pluginType = typeof(TerrainPlugin);
                ICollection <Type> pluginTypes = new List <Type>();
                foreach (Assembly assembly in assemblies)
                {
                    if (assembly != null)
                    {
                        Type[] types = assembly.GetTypes();
                        foreach (Type type in types)
                        {
                            if (type.IsInterface || type.IsAbstract)
                            {
                                continue;
                            }
                            else
                            {
                                if (type.GetInterface(pluginType.FullName) != null)
                                {
                                    pluginTypes.Add(type);
                                }
                            }
                        }
                    }
                }

                Console.Out.WriteLine("### Available plugins: ###");

                foreach (Type type in pluginTypes)
                {
                    TerrainPlugin plugin = (TerrainPlugin)Activator.CreateInstance(type);
                    plugins.Add(plugin);
                    Console.Out.WriteLine("##################");
                    Console.Out.WriteLine("Hash code: " + plugin.GetHashCode());
                    foreach (LayerType layerType in plugin.Out)
                    {
                        Console.Out.WriteLine(layerType.ToString());
                    }
                    Console.Out.WriteLine(plugin.Name);
                    Console.Out.WriteLine("##################");
                }
            }
            else
            {
                Console.Out.WriteLine("Plugin path does not exist!!!");
            }

            return(plugins);
        }