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

47 lines
1.7 KiB
C#
Raw Normal View History

2014-01-03 18:16:05 +08:00
using System;
using System.Collections.Generic;
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;
2014-09-19 16:57:48 +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 RegularPluginQueryDispatcher : IQueryDispatcher
2014-01-03 18:16:05 +08:00
{
2014-12-26 22:51:04 +08:00
public void Dispatch(Query query)
2014-01-03 23:52:36 +08:00
{
2015-01-23 20:49:00 +08:00
PluginPair regularPlugin = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName);
if (regularPlugin != null && !string.IsNullOrEmpty(regularPlugin.Metadata.ActionKeyword))
2014-01-03 18:16:05 +08:00
{
2015-01-23 20:49:00 +08:00
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == regularPlugin.Metadata.ID);
if (customizedPluginConfig != null && customizedPluginConfig.Disabled)
{
2014-07-05 23:10:34 +08:00
//need to stop the loading animation
2014-12-26 22:51:04 +08:00
PluginManager.API.StopLoadingBar();
return;
}
ThreadPool.QueueUserWorkItem(t =>
{
try
2014-01-03 18:16:05 +08:00
{
2015-01-23 20:49:00 +08:00
List<Result> results = regularPlugin.Plugin.Query(query) ?? new List<Result>();
2015-01-24 22:34:55 +08:00
results.ForEach(o =>
{
o.PluginID = regularPlugin.Metadata.ID;
});
PluginManager.API.PushResults(query, regularPlugin.Metadata, results);
}
2015-01-16 23:42:12 +08:00
catch (System.Exception e)
{
2015-01-23 20:49:00 +08:00
throw new WoxPluginException(regularPlugin.Metadata.Name, e);
}
});
}
}
2014-01-03 18:16:05 +08:00
}
}