mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 05:06:36 +02:00
add AutoAjustScore option for results
This commit is contained in:
@@ -31,7 +31,7 @@ namespace WinAlfred.Plugin.Fanyi
|
|||||||
private string translateURL = "http://openapi.baidu.com/public/2.0/bmt/translate";
|
private string translateURL = "http://openapi.baidu.com/public/2.0/bmt/translate";
|
||||||
private string baiduKey = "SnPcDY3iH5jDbklRewkG2D2v";
|
private string baiduKey = "SnPcDY3iH5jDbklRewkG2D2v";
|
||||||
|
|
||||||
static public string AssemblyDirectory
|
private static string AssemblyDirectory
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -89,23 +89,6 @@ namespace WinAlfred.Plugin.Fanyi
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetHtmlStr(string url)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
WebRequest rGet = WebRequest.Create(url);
|
|
||||||
WebResponse rSet = rGet.GetResponse();
|
|
||||||
Stream s = rSet.GetResponseStream();
|
|
||||||
StreamReader reader = new StreamReader(s, Encoding.UTF8);
|
|
||||||
return reader.ReadToEnd();
|
|
||||||
}
|
|
||||||
catch (WebException)
|
|
||||||
{
|
|
||||||
//连接失败
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|||||||
39
WinAlfred.Plugin.System/BaseSystemPlugin.cs
Normal file
39
WinAlfred.Plugin.System/BaseSystemPlugin.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace WinAlfred.Plugin.System
|
||||||
|
{
|
||||||
|
public abstract class BaseSystemPlugin :ISystemPlugin
|
||||||
|
{
|
||||||
|
protected abstract List<Result> QueryInternal(Query query);
|
||||||
|
protected abstract void InitInternal(PluginInitContext context);
|
||||||
|
|
||||||
|
public List<Result> Query(Query query)
|
||||||
|
{
|
||||||
|
return QueryInternal(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init(PluginInitContext context)
|
||||||
|
{
|
||||||
|
InitInternal(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "System workflow";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Description
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return "System workflow";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ using WinAlfred.Plugin.System.Common;
|
|||||||
|
|
||||||
namespace WinAlfred.Plugin.System
|
namespace WinAlfred.Plugin.System
|
||||||
{
|
{
|
||||||
public class BrowserBookmarks : ISystemPlugin
|
public class BrowserBookmarks : BaseSystemPlugin
|
||||||
{
|
{
|
||||||
|
|
||||||
private List<Bookmark> bookmarks = new List<Bookmark>();
|
private List<Bookmark> bookmarks = new List<Bookmark>();
|
||||||
@@ -21,7 +21,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
|
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
|
||||||
const int CSIDL_LOCAL_APPDATA = 0x001c;
|
const int CSIDL_LOCAL_APPDATA = 0x001c;
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
{
|
||||||
LoadChromeBookmarks();
|
LoadChromeBookmarks();
|
||||||
}
|
}
|
||||||
@@ -114,22 +114,6 @@ namespace WinAlfred.Plugin.System
|
|||||||
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
|
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
|
||||||
return reg.Replace(dataStr, m => ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString());
|
return reg.Replace(dataStr, m => ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "BrowserBookmark";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Description
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "BrowserBookmark";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Bookmark
|
public class Bookmark
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace WinAlfred.Plugin.System
|
namespace WinAlfred.Plugin.System
|
||||||
{
|
{
|
||||||
public class CMD : ISystemPlugin
|
public class CMD : BaseSystemPlugin
|
||||||
{
|
{
|
||||||
public List<Result> Query(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
|
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
|
||||||
@@ -38,24 +38,9 @@ namespace WinAlfred.Plugin.System
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "CMD";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Description
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "Execute shell commands.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ using System.Text;
|
|||||||
|
|
||||||
namespace WinAlfred.Plugin.System
|
namespace WinAlfred.Plugin.System
|
||||||
{
|
{
|
||||||
public class DirectoryIndicator : ISystemPlugin
|
public class DirectoryIndicator : BaseSystemPlugin
|
||||||
{
|
{
|
||||||
public List<Result> Query(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
if (string.IsNullOrEmpty(query.RawQuery)) return results;
|
if (string.IsNullOrEmpty(query.RawQuery)) return results;
|
||||||
|
|
||||||
if (CheckIfDirectory(query.RawQuery))
|
if (Directory.Exists(query.RawQuery))
|
||||||
{
|
{
|
||||||
Result result = new Result
|
Result result = new Result
|
||||||
{
|
{
|
||||||
@@ -30,29 +30,9 @@ namespace WinAlfred.Plugin.System
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckIfDirectory(string path)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
|
||||||
return Directory.Exists(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "DirectoryIndicator";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Description
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "DirectoryIndicator";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
public int Score { get; set; }
|
public int Score { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Programs : ISystemPlugin
|
public class Programs : BaseSystemPlugin
|
||||||
{
|
{
|
||||||
private List<string> indexDirectory = new List<string>();
|
private List<string> indexDirectory = new List<string>();
|
||||||
private List<string> indexPostfix = new List<string> { "lnk", "exe" };
|
private List<string> indexPostfix = new List<string> { "lnk", "exe" };
|
||||||
@@ -32,7 +32,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
const int CSIDL_COMMON_STARTMENU = 0x16; // \Windows\Start Menu\Programs
|
const int CSIDL_COMMON_STARTMENU = 0x16; // \Windows\Start Menu\Programs
|
||||||
const int CSIDL_COMMON_PROGRAMS = 0x17;
|
const int CSIDL_COMMON_PROGRAMS = 0x17;
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
{
|
||||||
indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
|
indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
|
||||||
|
|
||||||
@@ -126,21 +126,5 @@ namespace WinAlfred.Plugin.System
|
|||||||
string name = temp.Substring(0, temp.LastIndexOf('.'));
|
string name = temp.Substring(0, temp.LastIndexOf('.'));
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "Programs";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Description
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "get system programs";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace WinAlfred.Plugin.System
|
namespace WinAlfred.Plugin.System
|
||||||
{
|
{
|
||||||
public class Sys : ISystemPlugin
|
public class Sys : BaseSystemPlugin
|
||||||
{
|
{
|
||||||
List<Result> availableResults = new List<Result>();
|
List<Result> availableResults = new List<Result>();
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
[DllImport("user32")]
|
[DllImport("user32")]
|
||||||
public static extern void LockWorkStation();
|
public static extern void LockWorkStation();
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
{
|
||||||
availableResults.Add(new Result
|
availableResults.Add(new Result
|
||||||
{
|
{
|
||||||
@@ -74,21 +74,5 @@ namespace WinAlfred.Plugin.System
|
|||||||
Action = () => context.CloseApp()
|
Action = () => context.CloseApp()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "sys";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Description
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "provide system commands";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ using System.Text;
|
|||||||
|
|
||||||
namespace WinAlfred.Plugin.System
|
namespace WinAlfred.Plugin.System
|
||||||
{
|
{
|
||||||
public class ThirdpartyPluginIndicator : ISystemPlugin
|
public class ThirdpartyPluginIndicator : BaseSystemPlugin
|
||||||
{
|
{
|
||||||
private List<PluginPair> allPlugins = new List<PluginPair>();
|
private List<PluginPair> allPlugins = new List<PluginPair>();
|
||||||
private Action<string> changeQuery;
|
private Action<string> changeQuery;
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
protected override List<Result> QueryInternal(Query query)
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
if (string.IsNullOrEmpty(query.RawQuery)) return results;
|
if (string.IsNullOrEmpty(query.RawQuery)) return results;
|
||||||
@@ -27,7 +27,7 @@ namespace WinAlfred.Plugin.System
|
|||||||
Score = 50,
|
Score = 50,
|
||||||
IcoPath = "Images/work.png",
|
IcoPath = "Images/work.png",
|
||||||
Action = () => changeQuery(metadataCopy.ActionKeyword + " "),
|
Action = () => changeQuery(metadataCopy.ActionKeyword + " "),
|
||||||
DontHideWinAlfredAfterAction = true
|
DontHideWinAlfredAfterSelect = true
|
||||||
};
|
};
|
||||||
results.Add(result);
|
results.Add(result);
|
||||||
}
|
}
|
||||||
@@ -35,27 +35,12 @@ namespace WinAlfred.Plugin.System
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
protected override void InitInternal(PluginInitContext context)
|
||||||
{
|
{
|
||||||
allPlugins = context.Plugins;
|
allPlugins = context.Plugins;
|
||||||
changeQuery = context.ChangeQuery;
|
changeQuery = context.ChangeQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name {
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "ThirdpartyPluginIndicator";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Description
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "ThirdpartyPluginIndicator";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="BaseSystemPlugin.cs" />
|
||||||
<Compile Include="BrowserBookmarks.cs" />
|
<Compile Include="BrowserBookmarks.cs" />
|
||||||
<Compile Include="CMD.cs" />
|
<Compile Include="CMD.cs" />
|
||||||
<Compile Include="Common\ChineseToPinYin.cs" />
|
<Compile Include="Common\ChineseToPinYin.cs" />
|
||||||
|
|||||||
@@ -14,5 +14,7 @@ namespace WinAlfred.Plugin
|
|||||||
public Action HideApp { get; set; }
|
public Action HideApp { get; set; }
|
||||||
public Action ShowApp { get; set; }
|
public Action ShowApp { get; set; }
|
||||||
public Action<string,string,string> ShowMsg { get; set; }
|
public Action<string,string,string> ShowMsg { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,12 @@ namespace WinAlfred.Plugin
|
|||||||
public Action Action { get; set; }
|
public Action Action { get; set; }
|
||||||
public int Score { get; set; }
|
public int Score { get; set; }
|
||||||
|
|
||||||
public bool DontHideWinAlfredAfterAction { get; set; }
|
public bool DontHideWinAlfredAfterSelect { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Auto add scores for MRU items
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoAjustScore { get; set; }
|
||||||
|
|
||||||
//todo: this should be controlled by system, not visible to users
|
//todo: this should be controlled by system, not visible to users
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace WinAlfred.Commands
|
|||||||
{
|
{
|
||||||
result.PluginDirectory = pair1.Metadata.PluginDirecotry;
|
result.PluginDirectory = pair1.Metadata.PluginDirecotry;
|
||||||
result.OriginQuery = query;
|
result.OriginQuery = query;
|
||||||
|
result.AutoAjustScore = true;
|
||||||
}
|
}
|
||||||
if(results.Count > 0 && updateView) UpdateResultView(results);
|
if(results.Count > 0 && updateView) UpdateResultView(results);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ namespace WinAlfred
|
|||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
selectedRecords.AddSelect(result);
|
selectedRecords.AddSelect(result);
|
||||||
if (!result.DontHideWinAlfredAfterAction)
|
if (!result.DontHideWinAlfredAfterSelect)
|
||||||
{
|
{
|
||||||
HideWinAlfred();
|
HideWinAlfred();
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ namespace WinAlfred
|
|||||||
//todo:this used be opened to users, it's they choise use it or not in thier workflows
|
//todo:this used be opened to users, it's they choise use it or not in thier workflows
|
||||||
list.ForEach(o =>
|
list.ForEach(o =>
|
||||||
{
|
{
|
||||||
o.Score += selectedRecords.GetSelectedCount(o);
|
if(o.AutoAjustScore) o.Score += selectedRecords.GetSelectedCount(o);
|
||||||
});
|
});
|
||||||
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace WinAlfred.PluginLoader
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
|
Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
|
||||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && o.GetInterfaces().Contains(typeof(IPlugin)) || o.GetInterfaces().Contains(typeof(ISystemPlugin))).ToList();
|
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList();
|
||||||
if (types.Count == 0)
|
if (types.Count == 0)
|
||||||
{
|
{
|
||||||
Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin",
|
Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin",
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows.Documents;
|
using System.Windows.Documents;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Python.Runtime;
|
using Python.Runtime;
|
||||||
|
using WinAlfred.Helper;
|
||||||
using WinAlfred.Plugin;
|
using WinAlfred.Plugin;
|
||||||
|
|
||||||
namespace WinAlfred.PluginLoader
|
namespace WinAlfred.PluginLoader
|
||||||
@@ -12,17 +15,19 @@ namespace WinAlfred.PluginLoader
|
|||||||
{
|
{
|
||||||
|
|
||||||
private PluginMetadata metadata;
|
private PluginMetadata metadata;
|
||||||
|
private string moduleName;
|
||||||
|
|
||||||
public PythonPluginWrapper(PluginMetadata metadata)
|
public PythonPluginWrapper(PluginMetadata metadata)
|
||||||
{
|
{
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
|
moduleName = metadata.ExecuteFileName.Replace(".py", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string jsonResult = InvokeFunc(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), "query", query.RawQuery);
|
string jsonResult = InvokeFunc("query", query.RawQuery);
|
||||||
if (string.IsNullOrEmpty(jsonResult))
|
if (string.IsNullOrEmpty(jsonResult))
|
||||||
{
|
{
|
||||||
return new List<Result>();
|
return new List<Result>();
|
||||||
@@ -35,7 +40,7 @@ namespace WinAlfred.PluginLoader
|
|||||||
PythonResult ps = pythonResult;
|
PythonResult ps = pythonResult;
|
||||||
if (!string.IsNullOrEmpty(ps.ActionName))
|
if (!string.IsNullOrEmpty(ps.ActionName))
|
||||||
{
|
{
|
||||||
ps.Action = () => InvokeFunc(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), ps.ActionName, ps.ActionPara);
|
ps.Action = () => InvokeFunc(ps.ActionName, ps.ActionPara);
|
||||||
}
|
}
|
||||||
r.Add(ps);
|
r.Add(ps);
|
||||||
}
|
}
|
||||||
@@ -49,16 +54,37 @@ namespace WinAlfred.PluginLoader
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string InvokeFunc(string path, string moduleName, string func, string para)
|
private string InvokeFunc(string func, params string[] para)
|
||||||
{
|
{
|
||||||
|
string json;
|
||||||
|
|
||||||
|
PyObject[] paras = { };
|
||||||
|
if (para != null && para.Length > 0)
|
||||||
|
{
|
||||||
|
paras = para.Select(o => new PyString(o)).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
IntPtr gs = PythonEngine.AcquireLock();
|
IntPtr gs = PythonEngine.AcquireLock();
|
||||||
|
|
||||||
PyObject module = PythonEngine.ImportModule(moduleName);
|
PyObject module = PythonEngine.ImportModule(moduleName);
|
||||||
PyObject res = module.InvokeMethod(func, new PyString(para));
|
if (module.HasAttr(func))
|
||||||
string json = Runtime.GetManagedString(res.Handle);
|
{
|
||||||
|
PyObject res = paras.Length > 0 ? module.InvokeMethod(func, paras) : module.InvokeMethod(func);
|
||||||
|
json = Runtime.GetManagedString(res.Handle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string error = string.Format("Python Invoke failed: {0} doesn't has function {1}",
|
||||||
|
metadata.ExecuteFilePath, func);
|
||||||
|
Log.Error(error);
|
||||||
|
#if (DEBUG)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(error);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
PythonEngine.ReleaseLock(gs);
|
PythonEngine.ReleaseLock(gs);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user