PowerToys/Wox.Core/Plugin/QueryDispatcher/WildcardPluginQueryDispatcher.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2014-12-26 22:51:04 +08:00
using System.Collections.Generic;
2014-01-03 18:16:05 +08:00
using System.Linq;
2014-01-03 23:52:36 +08:00
using System.Threading;
2015-01-16 23:42:12 +08:00
using Wox.Core.Exception;
using Wox.Core.UserSettings;
2015-01-16 23:42:12 +08:00
using Wox.Infrastructure.Logger;
2014-01-29 18:33:24 +08:00
using Wox.Plugin;
2014-01-03 18:16:05 +08:00
2014-12-26 22:51:04 +08:00
namespace Wox.Core.Plugin.QueryDispatcher
2014-01-03 18:16:05 +08:00
{
2015-01-23 20:49:00 +08:00
public class WildcardPluginQueryDispatcher : IQueryDispatcher
2014-01-03 18:16:05 +08:00
{
2015-01-23 20:49:00 +08:00
private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => PluginManager.IsWildcardPlugin(o.Metadata));
2014-10-22 22:49:34 +08:00
2014-12-26 22:51:04 +08:00
public void Dispatch(Query query)
2014-01-03 18:16:05 +08:00
{
2014-10-23 18:39:11 +08:00
var queryPlugins = allSytemPlugins;
foreach (PluginPair pair in queryPlugins)
{
PluginPair pair1 = pair;
2014-01-03 23:52:36 +08:00
ThreadPool.QueueUserWorkItem(state =>
{
2015-01-16 23:42:12 +08:00
try
{
List<Result> results = pair1.Plugin.Query(query);
results.ForEach(o => { o.AutoAjustScore = true; });
2014-07-05 23:10:34 +08:00
2015-01-16 23:42:12 +08:00
PluginManager.API.PushResults(query, pair1.Metadata, results);
}
catch (System.Exception e)
{
throw new WoxPluginException(pair1.Metadata.Name,e);
}
2014-01-03 23:52:36 +08:00
});
}
2014-01-03 18:16:05 +08:00
}
}
2015-01-04 23:08:26 +08:00
}