Add system commands

This commit is contained in:
qianlifeng
2014-01-03 18:16:05 +08:00
parent 5893564f46
commit 1eb3f449e2
15 changed files with 317 additions and 45 deletions

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinAlfred.Helper;
using WinAlfred.Plugin;
namespace WinAlfred.Commands
{
public class CommandDispatcher
{
private PluginCommand pluginCmd = new PluginCommand();
private SystemCommand systemCmd = new SystemCommand();
//public delegate void resultUpdateDelegate(List<Result> results);
//public event resultUpdateDelegate OnResultUpdateEvent;
//protected virtual void OnOnResultUpdateEvent(List<Result> list)
//{
// resultUpdateDelegate handler = OnResultUpdateEvent;
// if (handler != null) handler(list);
//}
public void DispatchCommand(Query query)
{
systemCmd.Dispatch(query);
pluginCmd.Dispatch(query);
}
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinAlfred.Helper;
using WinAlfred.Plugin;
using WinAlfred.PluginLoader;
namespace WinAlfred.Commands
{
public class PluginCommand
{
public void Dispatch(Query q)
{
//ThreadPool.QueueUserWorkItem(state =>
//{
foreach (PluginPair pair in Plugins.AllPlugins)
{
if (pair.Metadata.ActionKeyword == q.ActionName)
{
try
{
pair.Plugin.Query(q).ForEach(o => o.PluginDirectory = pair.Metadata.PluginDirecotry);
}
catch (Exception queryException)
{
Log.Error(string.Format("Plugin {0} query failed: {1}", pair.Metadata.Name,
queryException.Message));
#if (DEBUG)
{
throw;
}
#endif
}
}
}
resultCtrl.Dispatcher.Invoke(new Action(() =>
{
resultCtrl.AddResults(results.OrderByDescending(o => o.Score).ToList());
resultCtrl.SelectFirst();
}));
//});
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WinAlfred.Plugin;
namespace WinAlfred.Commands
{
public class SystemCommand
{
public void Dispatch(Query query)
{
}
}
}