Exemple #1
0
 public bool TryGetFileFormat(string extension, out Plugins.FileFormat FileFormatter)
 {
     foreach (var plugin in Plugins)
     {
         if (plugin.FileExtension.Equals(extension))
         {
             FileFormatter = plugin;
             return(true);
         }
     }
     FileFormatter = null;
     return(false);
 }
Exemple #2
0
        public FileFormatPluginLoader(string path)
        {
            string[] dllFileNames = null;
            Plugins = new List <Plugins.FileFormat>();

            if (Directory.Exists(path))
            {
                dllFileNames = Directory.GetFiles(path, "Plugin.FileFormat*.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(Plugins.FileFormat);
                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);
                            }
                        }
                    }
                }

                foreach (Type type in pluginTypes)
                {
                    Plugins.FileFormat plugin = (Plugins.FileFormat)Activator.CreateInstance(type);
                    Plugins.Add(plugin);
                }
                Plugins.Add(new Plugins.BIN());
            }
        }