2013-12-21 01:20:17 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-12-23 19:21:51 +08:00
|
|
|
|
using System.Runtime.InteropServices;
|
2013-12-23 23:53:38 +08:00
|
|
|
|
using Newtonsoft.Json;
|
2013-12-21 01:20:17 +08:00
|
|
|
|
using WinAlfred.Plugin;
|
|
|
|
|
|
|
|
|
|
namespace WinAlfred.PluginLoader
|
|
|
|
|
{
|
|
|
|
|
public class PythonPluginWrapper : IPlugin
|
|
|
|
|
{
|
2013-12-23 19:21:51 +08:00
|
|
|
|
private PluginMetadata metadata;
|
|
|
|
|
|
|
|
|
|
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
2013-12-23 23:53:38 +08:00
|
|
|
|
private extern static IntPtr ExecPython(string directory, string file, string query);
|
2013-12-25 19:26:58 +08:00
|
|
|
|
[DllImport("PyWinAlfred.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
|
|
|
|
|
private extern static void InitPythonEnv();
|
2013-12-21 01:20:17 +08:00
|
|
|
|
|
2013-12-23 19:21:51 +08:00
|
|
|
|
public PythonPluginWrapper(PluginMetadata metadata)
|
2013-12-21 01:20:17 +08:00
|
|
|
|
{
|
2013-12-23 19:21:51 +08:00
|
|
|
|
this.metadata = metadata;
|
2013-12-21 01:20:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Result> Query(Query query)
|
|
|
|
|
{
|
2013-12-23 23:53:38 +08:00
|
|
|
|
string s = Marshal.PtrToStringAnsi(ExecPython(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), query.RawQuery));
|
|
|
|
|
List<Result> o = JsonConvert.DeserializeObject<List<Result>>(s);
|
|
|
|
|
return o;
|
2013-12-21 01:20:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2013-12-25 19:26:58 +08:00
|
|
|
|
InitPythonEnv();
|
2013-12-21 01:20:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|