2013-12-20 12:38:10 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2013-12-20 18:20:17 +01:00
|
|
|
|
using System.Reflection;
|
2013-12-22 12:35:21 +01:00
|
|
|
|
using System.Threading;
|
2014-01-29 11:33:24 +01:00
|
|
|
|
using Wox.Helper;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
using Wox.Plugin.System;
|
2013-12-20 12:38:10 +01:00
|
|
|
|
|
2014-01-29 11:33:24 +01:00
|
|
|
|
namespace Wox.PluginLoader
|
2013-12-20 12:38:10 +01:00
|
|
|
|
{
|
2013-12-20 18:20:17 +01:00
|
|
|
|
public class CSharpPluginLoader : BasePluginLoader
|
2013-12-20 12:38:10 +01:00
|
|
|
|
{
|
2013-12-20 18:20:17 +01:00
|
|
|
|
public override List<PluginPair> LoadPlugin()
|
2013-12-20 12:38:10 +01:00
|
|
|
|
{
|
2013-12-20 18:20:17 +01:00
|
|
|
|
List<PluginPair> plugins = new List<PluginPair>();
|
|
|
|
|
|
|
|
|
|
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
|
|
|
|
foreach (PluginMetadata metadata in metadatas)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-12-23 16:53:38 +01:00
|
|
|
|
Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
|
2014-01-15 15:45:02 +01:00
|
|
|
|
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList();
|
2013-12-20 18:20:17 +01:00
|
|
|
|
if (types.Count == 0)
|
|
|
|
|
{
|
2013-12-21 17:44:56 +01:00
|
|
|
|
Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin",
|
|
|
|
|
metadata.Name));
|
2013-12-20 18:20:17 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-03 16:52:36 +01:00
|
|
|
|
foreach (Type type in types)
|
2013-12-20 18:20:17 +01:00
|
|
|
|
{
|
2014-01-03 16:52:36 +01:00
|
|
|
|
PluginPair pair = new PluginPair()
|
|
|
|
|
{
|
|
|
|
|
Plugin = Activator.CreateInstance(type) as IPlugin,
|
|
|
|
|
Metadata = metadata
|
|
|
|
|
};
|
|
|
|
|
plugins.Add(pair);
|
|
|
|
|
}
|
2013-12-20 18:20:17 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(string.Format("Cound't load plugin {0}: {1}", metadata.Name, e.Message));
|
|
|
|
|
#if (DEBUG)
|
2013-12-21 17:44:56 +01:00
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2013-12-20 18:20:17 +01:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-20 12:38:10 +01:00
|
|
|
|
return plugins;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|