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

@@ -1,9 +1,7 @@
using System.Collections.Generic;
using System.Windows.Documents;
using Newtonsoft.Json;
using Wox.Plugin;
namespace Wox.RPC
namespace Wox.JsonRPC
{
public class JsonRPCErrorModel
{

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);
}
}

View File

@@ -1,21 +0,0 @@
using System.Collections.Generic;
using System.Linq;
namespace Wox.RPC
{
public class JsonRPC
{
public static string Send(string method, List<string> paras)
{
var list = paras.Select(s => string.Format(@"\""{0}\""", s));
return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""params\"": [{1}], \""id\"": 1}}",
method, string.Join(",", list.ToArray()));
}
public static string Send(string method, string para)
{
return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""params\"": {1}, \""id\"": 1}}",
method, string.Join(",", list.ToArray()));
}
}
}

View File

@@ -1,21 +0,0 @@
using System.Collections.Generic;
using System.Linq;
namespace Wox.RPC
{
public class JsonRPC
{
public static string Send(string method, List<string> paras)
{
var list = paras.Select(s => string.Format(@"\""{0}\""", s));
return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""parameters\"": [{1}], \""id\"": 1}}",
method, string.Join(",", list.ToArray()));
}
public static string Send(string method, string para)
{
return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""parameters\"": \""{1}\"", \""id\"": 1}}",
method, para);
}
}
}

View File

@@ -1,56 +0,0 @@
using System.Collections.Generic;
using System.Windows.Documents;
using Newtonsoft.Json;
using Wox.Plugin;
namespace Wox.RPC
{
public class JsonRPCErrorModel
{
public int Code { get; set; }
public string Message { get; set; }
public string Data { get; set; }
}
public class JsonRPCModelBase
{
public int Id { get; set; }
public string JsonRPC { get; set; }
}
public class JsonRPCResponseModel : JsonRPCModelBase
{
public string Result { get; set; }
public JsonRPCErrorModel Error { get; set; }
}
public class JsonRPCQueryResponseModel : JsonRPCResponseModel
{
public new List<JsonRPCResult> Result { get; set; }
}
public class JsonRPCRequestModel : JsonRPCModelBase
{
public string Method { get; set; }
/// <summary>
/// counld be list<string> or string type
/// </summary>
public object Parameters { get; set; }
public override string ToString()
{
if(typeof(Parameters))
return string.Format(@"{""method"":}",Method,Parameters);
}
}
public class JsonRPCResult : Result
{
public JsonRPCRequestModel JsonRPCAction { get; set; }
}
}

View File

@@ -139,7 +139,6 @@
</Compile>
<Compile Include="Converters\ImagePathConverter.cs" />
<Compile Include="PluginLoader\IPluginLoader.cs" />
<Compile Include="RPC\JsonRPC.cs" />
<Compile Include="Msg.xaml.cs">
<DependentUpon>Msg.xaml</DependentUpon>
</Compile>
@@ -147,7 +146,7 @@
<Compile Include="PluginLoader\CSharpPluginLoader.cs" />
<Compile Include="PluginLoader\BasePluginLoader.cs" />
<Compile Include="PluginLoader\BasePlugin.cs" />
<Compile Include="RPC\JsonPRCModel.cs" />
<Compile Include="JsonRPC\JsonPRCModel.cs" />
<Compile Include="PluginLoader\Plugins.cs" />
<Compile Include="PluginLoader\PythonPlugin.cs" />
<Compile Include="Properties\Annotations.cs" />