internal void LoadPlugins(IPluginsHost host, string pluginsDir) { _Host = host; var dir = new DirectoryInfo(pluginsDir); var plugins = new PluginsComposition(dir.GetDirectories().Select(d => d.FullName)); foreach (var type in plugins.Factory.GetPlugins().Select(p => p.GetType())) { if (type.GetInterface("PluginsCore.ISyncPlugin") != null) { SyncPlugins.Add((ISyncPlugin)Activator.CreateInstance(type)); } else if (type.GetInterface("PluginsCore.IPostPlugin") != null) { SocialPlugins.Add((IPostPlugin)Activator.CreateInstance(type)); } } //var dirs = new DirectoryInfo(pluginsDir).GetDirectories(); //foreach ( // var type in // dirs.Select(d => d.GetFiles(d.Name + ".dll")) // .SelectMany( // files => // files.Select(f => Assembly.Load(AssemblyName.GetAssemblyName(f.FullName))) // .Select( // ass => // ass.GetTypes().FirstOrDefault(t => t.GetInterface("PluginsCore.IPlugin") != null)) // .Where(type => type != null))) //{ // if (type.GetInterface("PluginsCore.ISyncPlugin") != null) // SyncPlugins.Add((ISyncPlugin)Activator.CreateInstance(type)); // else if (type.GetInterface("PluginsCore.IPostPlugin") != null) // PostPlugins.Add((IPostPlugin)Activator.CreateInstance(type)); //} foreach (var p in SyncPlugins) { p.Init(host); p.BeforeSync += sync_BeforeSync; p.SyncComplete += sync_SyncComplete; } foreach (var p in SocialPlugins) { p.Init(host); p.PostPerformed += plugin_PostPerformed; p.GotPostsPartial += plugin_GotPostsPartial; p.GotPostsFull += plugin_GotPostsFull; } }
internal void LoadPlugins(IPluginsHost host, string pluginsDir) { _Host = host; var dir = new DirectoryInfo(pluginsDir); var plugins = new PluginsComposition(dir.GetDirectories().Select(d => d.FullName)); foreach (var type in plugins.Factory.GetPlugins().Select(p => p.GetType())) { if (type.GetInterface("PluginsCore.ISyncPlugin") != null) SyncPlugins.Add((ISyncPlugin)Activator.CreateInstance(type)); else if (type.GetInterface("PluginsCore.IPostPlugin") != null) SocialPlugins.Add((IPostPlugin)Activator.CreateInstance(type)); } //var dirs = new DirectoryInfo(pluginsDir).GetDirectories(); //foreach ( // var type in // dirs.Select(d => d.GetFiles(d.Name + ".dll")) // .SelectMany( // files => // files.Select(f => Assembly.Load(AssemblyName.GetAssemblyName(f.FullName))) // .Select( // ass => // ass.GetTypes().FirstOrDefault(t => t.GetInterface("PluginsCore.IPlugin") != null)) // .Where(type => type != null))) //{ // if (type.GetInterface("PluginsCore.ISyncPlugin") != null) // SyncPlugins.Add((ISyncPlugin)Activator.CreateInstance(type)); // else if (type.GetInterface("PluginsCore.IPostPlugin") != null) // PostPlugins.Add((IPostPlugin)Activator.CreateInstance(type)); //} foreach (var p in SyncPlugins) { p.Init(host); p.BeforeSync += sync_BeforeSync; p.SyncComplete += sync_SyncComplete; } foreach (var p in SocialPlugins) { p.Init(host); p.PostPerformed += plugin_PostPerformed; p.GotPostsPartial += plugin_GotPostsPartial; p.GotPostsFull += plugin_GotPostsFull; } }