Add v2ex python plugin demo.

This commit is contained in:
qianlifeng
2014-07-09 23:44:57 +08:00
parent e307524458
commit 5f7c1ea4f4
12 changed files with 63 additions and 129 deletions

View File

@@ -5,8 +5,8 @@ using System.IO;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Wox.JsonRPC;
using Wox.Plugin;
using Wox.RPC;
namespace Wox.PluginLoader
{
@@ -14,7 +14,7 @@ namespace Wox.PluginLoader
{
protected PluginInitContext context;
public abstract List<string> GetAllowedLanguages();
public abstract string SupportedLanguage { get; }
protected abstract string ExecuteQuery(Query query);
protected abstract string ExecuteAction(JsonRPCRequestModel rpcRequest);

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wox.Plugin;
using Wox.RPC;
namespace Wox.PluginLoader
{
@@ -11,22 +10,14 @@ namespace Wox.PluginLoader
{
public virtual List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
{
List<PluginPair> plugins = new List<PluginPair>();
T pluginWrapper = new T();
List<string> allowedLanguages = pluginWrapper.GetAllowedLanguages();
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => allowedLanguages.Contains(o.Language.ToUpper())).ToList();
foreach (PluginMetadata metadata in metadatas)
{
PluginPair pair = new PluginPair()
{
Plugin = pluginWrapper,
Metadata = metadata
};
plugins.Add(pair);
}
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => pluginWrapper.SupportedLanguage.ToUpper() == o.Language.ToUpper()).ToList();
return plugins;
return metadatas.Select(metadata => new PluginPair()
{
Plugin = pluginWrapper,
Metadata = metadata
}).ToList();
}
}
}

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.IO;
using Wox.JsonRPC;
using Wox.Plugin;
using Wox.RPC;
namespace Wox.PluginLoader
{
@@ -9,27 +9,24 @@ namespace Wox.PluginLoader
{
private static string woxDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
public override List<string> GetAllowedLanguages()
public override string SupportedLanguage
{
return new List<string>()
{
AllowedLanguage.Python
};
get { return AllowedLanguage.Python; }
}
protected override string ExecuteQuery(Query query)
{
string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
JsonRPC.Send("query", query.GetAllRemainingParameter()));
string.Format(@"{{\""method\"": \""query\"", \""parameters\"": \""{0}\""}}",query.GetAllRemainingParameter()));
return Execute(fileName, parameters);
}
protected override string ExecuteAction(JsonRPCRequestModel rpcRequest)
{
string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
rpcRequest.ToString());
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,rpcRequest);
return Execute(fileName, parameters);
}
}