コード例 #1
0
        public int LoadAllPlugin(string pluginsDirectory)
        {
            string[]        files         = System.IO.Directory.GetFiles(pluginsDirectory);
            PluginAttribute typeAttribute = new PluginAttribute();
            int             result        = 0;

            foreach (string file in files)
            {
                try
                {
                    if (AddPlugin(file) != null)
                    {
                        result++;
                    }
                }
                catch (Exception err)
                {
                    throw err;
                }
            }
            return(result);
        }
コード例 #2
0
        public IPlugin InitOnePluginByPath(string pluginPath)
        {
            string ext = System.IO.Path.GetExtension(pluginPath); // file.Substring(file.LastIndexOf("."));

            if (ext.ToLower() != ".dll")
            {
                return(null);
            }

            int      i   = plugins.Count;
            Assembly tmp = Assembly.LoadFile(pluginPath);

            Type[] types = tmp.GetTypes();
            foreach (Type t in types)
            {
                if (IsValidPlugin(t))
                {
                    IPlugin plugin = (IPlugin)tmp.CreateInstance(t.FullName);
                    if (!Contains(plugin.PluginInfo.GUID))
                    {
                        plugins.Add(plugin.PluginInfo.GUID, plugin);
                        PluginAttribute attribute = plugin.PluginInfo;
                        if (plugin.PluginInfo != null)
                        {
                            plugin.Index    = i + 1;
                            plugin.FullName = pluginPath;
                        }
                        else
                        {
                            throw new Exception("The Current Plugin(" + t.FullName + ") Properties Can Not Be Null!");
                        }
                    }
                    return(plugin);
                }
            }
            return(null);
        }