2014-01-03 18:16:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-01-11 15:02:17 +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;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
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);
|
2014-07-01 22:19:46 +08:00
|
|
|
|
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();
|
2014-07-01 22:19:46 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-11 15:02:17 +08:00
|
|
|
|
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);
|
2014-01-11 15:02:17 +08:00
|
|
|
|
}
|
2015-01-16 23:42:12 +08:00
|
|
|
|
catch (System.Exception e)
|
2014-01-11 15:02:17 +08:00
|
|
|
|
{
|
2015-01-23 20:49:00 +08:00
|
|
|
|
throw new WoxPluginException(regularPlugin.Metadata.Name, e);
|
2014-01-11 15:02:17 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-03 18:16:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|