Add portable python environment

This commit is contained in:
qianlifeng
2014-07-09 18:15:23 +08:00
parent 3efe3d63ce
commit 53cb4189d8
893 changed files with 19533 additions and 42 deletions

View File

@@ -10,14 +10,14 @@ using Wox.RPC;
namespace Wox.PluginLoader
{
public abstract class BasePluginWrapper : IPlugin
public abstract class BasePlugin : IPlugin
{
protected PluginInitContext context;
public abstract List<string> GetAllowedLanguages();
protected abstract string ExecuteQuery(Query query);
protected abstract string ExecuteAction(string rpcRequest);
protected abstract string ExecuteAction(JsonRPCRequestModel rpcRequest);
public List<Result> Query(Query query)
{
@@ -29,13 +29,13 @@ namespace Wox.PluginLoader
List<Result> results = new List<Result>();
JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject<JsonRPCQueryResponseModel>(output);
foreach (JsonRPCResult result in queryResponseModel.QueryResults)
foreach (JsonRPCResult result in queryResponseModel.Result)
{
if (result.JSONRPCActionModel != null)
if (result.JsonRPCAction != null)
{
result.Action = (c) =>
{
ExecuteAction(result.JSONRPCAction);
string actionResponse = ExecuteAction(result.JsonRPCAction);
return true;
};
}

View File

@@ -7,7 +7,7 @@ using Wox.RPC;
namespace Wox.PluginLoader
{
public class BasePluginLoader<T> : IPluginLoader where T : BasePluginWrapper, new()
public class BasePluginLoader<T> : IPluginLoader where T : BasePlugin, new()
{
public virtual List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
{

View File

@@ -8,7 +8,7 @@ using Wox.Plugin.SystemPlugins;
namespace Wox.PluginLoader {
public class CSharpPluginConfigLoader : IPluginLoader
public class CSharpPluginLoader : IPluginLoader
{
public List<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
{

View File

@@ -16,8 +16,8 @@ namespace Wox.PluginLoader
plugins.Clear();
List<PluginMetadata> pluginMetadatas = PluginConfigLoader.ParsePluginsConfig();
plugins.AddRange(new CSharpPluginConfigLoader().LoadPlugin(pluginMetadatas));
plugins.AddRange(new BasePluginLoader<PythonPluginWrapper>().LoadPlugin(pluginMetadatas));
plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
plugins.AddRange(new BasePluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
Forker forker = new Forker();
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))

View File

@@ -5,7 +5,7 @@ using Wox.RPC;
namespace Wox.PluginLoader
{
public class PythonPluginWrapper : BasePluginWrapper
public class PythonPlugin : BasePlugin
{
private static string woxDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
@@ -19,17 +19,17 @@ namespace Wox.PluginLoader
protected override string ExecuteQuery(Query query)
{
string fileName = Path.Combine(woxDirectory, "PYTHONTHOME\\Scripts\\python.exe");
string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
JsonRPC.Send("query", query.GetAllRemainingParameter()));
return Execute(fileName, parameters);
}
protected override string ExecuteAction(string rpcRequest)
protected override string ExecuteAction(JsonRPCRequestModel rpcRequest)
{
string fileName = Path.Combine(woxDirectory, "PYTHONTHOME\\Scripts\\python.exe");
string fileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe");
string parameters = string.Format("{0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath,
rpcRequest);
rpcRequest.ToString());
return Execute(fileName, parameters);
}
}

21
Wox/RPC/2obywmlm.f50 Normal file
View File

@@ -0,0 +1,21 @@
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

@@ -30,33 +30,31 @@ namespace Wox.RPC
public class JsonRPCQueryResponseModel : JsonRPCResponseModel
{
public List<JsonRPCResult> QueryResults
{
get
{
return JsonConvert.DeserializeObject<List<JsonRPCResult>>(Result);
}
}
public new List<JsonRPCResult> Result { get; set; }
}
public class JsonRPCRequestModel : JsonRPCModelBase
{
public string Method { get; set; }
/*
* 1. c# can't use params as the variable name
* 2. all prarmeter should be string type
*/
public List<string> Parameters { get; set; }
/// <summary>
/// counld be list<string> or string type
/// </summary>
public object Parameters { get; set; }
public override string ToString()
{
if (Parameters is string)
{
return string.Format(@"{{\""method\"":\""{0}\"",\""parameters\"":\""{1}\""}}", Method, Parameters);
}
return string.Empty;
}
}
public class JsonRPCResult : Result
{
public string JSONRPCAction { get; set; }
public JsonRPCRequestModel JSONRPCActionModel
{
get { return null; }
}
public JsonRPCRequestModel JsonRPCAction { get; set; }
}
}

View File

@@ -8,13 +8,14 @@ namespace Wox.RPC
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}}",
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 Send(method, new List<string>() { para });
return string.Format(@"{{\""jsonrpc\"": \""2.0\"",\""method\"": \""{0}\"", \""parameters\"": \""{1}\"", \""id\"": 1}}",
method, para);
}
}
}

56
Wox/RPC/tr3fzfc4.och Normal file
View File

@@ -0,0 +1,56 @@
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

@@ -144,12 +144,12 @@
<DependentUpon>Msg.xaml</DependentUpon>
</Compile>
<Compile Include="PluginLoader\PluginConfigLoader.cs" />
<Compile Include="PluginLoader\CSharpPluginConfigLoader.cs" />
<Compile Include="PluginLoader\CSharpPluginLoader.cs" />
<Compile Include="PluginLoader\BasePluginLoader.cs" />
<Compile Include="PluginLoader\BasePluginWrapper.cs" />
<Compile Include="PluginLoader\BasePlugin.cs" />
<Compile Include="RPC\JsonPRCModel.cs" />
<Compile Include="PluginLoader\Plugins.cs" />
<Compile Include="PluginLoader\PythonPluginWrapper.cs" />
<Compile Include="PluginLoader\PythonPlugin.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="ResultPanel.xaml.cs">
<DependentUpon>ResultPanel.xaml</DependentUpon>