2015-10-31 07:17:34 +08:00
|
|
|
|
using System.Collections.Generic;
|
2015-11-01 02:06:57 +08:00
|
|
|
|
using System.Diagnostics;
|
2015-02-04 23:16:41 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
2015-10-31 07:17:34 +08:00
|
|
|
|
using Wox.Core.UserSettings;
|
2015-02-04 23:16:41 +08:00
|
|
|
|
using Wox.Infrastructure;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
|
|
|
|
|
namespace Wox.Core.Plugin.QueryDispatcher
|
|
|
|
|
{
|
|
|
|
|
public abstract class BaseQueryDispatcher : IQueryDispatcher
|
|
|
|
|
{
|
|
|
|
|
protected abstract List<PluginPair> GetPlugins(Query query);
|
|
|
|
|
|
|
|
|
|
public void Dispatch(Query query)
|
|
|
|
|
{
|
|
|
|
|
foreach (PluginPair pair in GetPlugins(query))
|
|
|
|
|
{
|
2015-08-27 20:27:14 +08:00
|
|
|
|
var customizedPluginConfig = UserSettingStorage.Instance.
|
|
|
|
|
CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pair.Metadata.ID);
|
|
|
|
|
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-04 23:16:41 +08:00
|
|
|
|
PluginPair localPair = pair;
|
|
|
|
|
if (query.IsIntantQuery && PluginManager.IsInstantSearchPlugin(pair.Metadata))
|
|
|
|
|
{
|
2015-11-01 02:06:57 +08:00
|
|
|
|
Debug.WriteLine(string.Format("Plugin {0} is executing instant search.", pair.Metadata.Name));
|
2015-02-04 23:16:41 +08:00
|
|
|
|
using (new Timeit(" => instant search took: "))
|
|
|
|
|
{
|
|
|
|
|
PluginManager.ExecutePluginQuery(localPair, query);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ThreadPool.QueueUserWorkItem(state =>
|
|
|
|
|
{
|
|
|
|
|
PluginManager.ExecutePluginQuery(localPair, query);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|