Add IContextMenu interface & lazy load context menus

This commit is contained in:
qianlifeng
2015-02-07 23:49:46 +08:00
parent c24e216f26
commit bc7dce6026
10 changed files with 196 additions and 166 deletions

View File

@@ -12,37 +12,18 @@ namespace Wox.Core
{
public static List<KeyValuePair<PluginPair, T>> LoadPluginInterfaces<T>() where T : class
{
List<PluginMetadata> CSharpPluginMetadatas = PluginManager.AllPlugins.Select(o => o.Metadata).Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
List<KeyValuePair<PluginPair, T>> plugins = new List<KeyValuePair<PluginPair, T>>();
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
List<KeyValuePair<PluginPair, T>> results = new List<KeyValuePair<PluginPair, T>>();
foreach (PluginPair pluginPair in PluginManager.AllPlugins)
{
try
//need to load types from AllPlugins
//PluginInitContext is only available in this instance
T type = pluginPair.Plugin as T;
if (type != null)
{
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(T))).ToList();
if (types.Count == 0)
{
continue;
}
foreach (Type type in types)
{
plugins.Add(new KeyValuePair<PluginPair, T>(PluginManager.AllPlugins.First(o => o.Metadata.ID == metadata.ID),
Activator.CreateInstance(type) as T));
}
}
catch (System.Exception e)
{
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
#if (DEBUG)
{
throw;
}
#endif
results.Add(new KeyValuePair<PluginPair, T>(pluginPair,type));
}
}
return plugins;
return results;
}
public static List<T> LoadInterfacesFromAppDomain<T>() where T : class