コード例 #1
0
        /// <summary>
        /// Retreives a list of available IR Server plugins.
        /// </summary>
        /// <returns>Array of plugin instances.</returns>
        public static PluginBase[] AvailablePlugins()
        {
            List <PluginBase> plugins = new List <PluginBase>();

            string path = Path.Combine(Application.StartupPath, "Plugins");

            string[] files = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);

            // TODO: Return a Type[], don't instantiate unless required

            foreach (string file in files)
            {
                try
                {
                    Assembly assembly = Assembly.LoadFrom(file);

                    Type[] types = assembly.GetExportedTypes();

                    foreach (Type type in types)
                    {
                        if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(PluginBase)))
                        {
                            PluginBase plugin = (PluginBase)assembly.CreateInstance(type.FullName);

                            if (plugin != null && plugin.Detect() != PluginBase.DetectionResult.DeviceDisabled)
                            {
                                plugins.Add(plugin);
                            }
                        }
                    }
                }
                catch (BadImageFormatException)
                {
                } // Ignore Bad Image Format Exceptions, just keep checking for IR Server Plugins
                catch (TypeLoadException)
                {
                } // Ignore Type Load Exceptions, just keep checking for IR Server Plugins
                catch (FileNotFoundException)
                {
                } // Ignore File Not Found Exceptions, just keep checking for IR Server Plugins
            }

            return(plugins.ToArray());
        }