Пример #1
0
        public PluginCoreContext()
        {
            string          pluginPath = System.IO.Path.Combine(AppContext.BaseDirectory, "Plugin");
            DirectoryLoader dl         = new DirectoryLoader();
            var             ass        = dl.LoadFromDirectory(pluginPath);

            this.AdditionalAssembly.Clear();
            this.AdditionalAssembly.AddRange(ass);
        }
Пример #2
0
        public void Load(string pluginPath)
        {
            if (!Directory.Exists(pluginPath))
            {
                return;
            }
            DirectoryLoader dl = new DirectoryLoader();
            var             al = dl.LoadFromDirectory(pluginPath);

            al.ForEach(a =>
            {
                LoadedAssembly.Add(a);
                var tl = dl.GetTypes(a, typeof(IPlugin), (t) =>
                {
                    if (t.GetTypeInfo().IsAbstract)
                    {
                        return(false);
                    }
                    if (t.GetTypeInfo().IsPublic)
                    {
                        return(true);
                    }
                    return(false);
                });

                tl.ForEach(t =>
                {
                    try
                    {
                        IPlugin p     = Activator.CreateInstance(t) as IPlugin;
                        PluginInfo pi = new PluginInfo()
                        {
                            //Description = p.Description,
                            //Order = p.Order,
                            //ID = p.PluginID,
                            Type     = t,
                            Instance = p,
                            //Name = p.PluginName
                        };
                        //if (typeof(IPluginConfig<PluginCoreConfig>).GetTypeInfo().IsAssignableFrom(p.GetType()))
                        //{
                        //    pi.HasConfig = true;
                        //}
                        PluginList.Add(pi);
                    }
                    catch
                    {
                        //Logger.Error("can not load plugin type: {0}\r\n{1}", t.FullName, e.ToString());
                    }
                });
            });
        }