public void Dispatch(Query query) { foreach (PluginPair pair in GetPlugins(query)) { var customizedPluginConfig = UserSettingStorage.Instance. CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pair.Metadata.ID); if (customizedPluginConfig != null && customizedPluginConfig.Disabled) { return; } PluginPair localPair = pair; if (query.IsIntantQuery && PluginManager.IsInstantSearchPlugin(pair.Metadata)) { DebugHelper.WriteLine(string.Format("Plugin {0} is executing instant search.", pair.Metadata.Name)); using (new Timeit(" => instant search took: ")) { PluginManager.ExecutePluginQuery(localPair, query); } } else { ThreadPool.QueueUserWorkItem(state => { PluginManager.ExecutePluginQuery(localPair, query); }); } } }
public MainViewModel(Settings settings) { _saved = false; _queryTextBeforeLeaveResults = ""; _queryText = ""; _lastQuery = new Query(); _settings = settings; _historyItemsStorage = new JsonStrorage<History>(); _userSelectedRecordStorage = new JsonStrorage<UserSelectedRecord>(); _topMostRecordStorage = new JsonStrorage<TopMostRecord>(); _history = _historyItemsStorage.Load(); _userSelectedRecord = _userSelectedRecordStorage.Load(); _topMostRecord = _topMostRecordStorage.Load(); ContextMenu = new ResultsViewModel(_settings); Results = new ResultsViewModel(_settings); History = new ResultsViewModel(_settings); _selectedResults = Results; InitializeKeyCommands(); RegisterResultsUpdatedEvent(); SetHotkey(_settings.Hotkey, OnHotkey); SetCustomPluginHotkey(); }
public List<Result> Query(Query query) { try { string jsonResult = InvokeFunc("query", query.RawQuery); if (string.IsNullOrEmpty(jsonResult)) { return new List<Result>(); } List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(jsonResult); List<Result> r = new List<Result>(); foreach (PythonResult pythonResult in o) { PythonResult ps = pythonResult; if (!string.IsNullOrEmpty(ps.ActionName)) { ps.Action = (context) => InvokeFunc(ps.ActionName, GetPythonActionContext(context),new PyString(ps.ActionPara)); } r.Add(ps); } return r; } catch (Exception) { #if (DEBUG) { throw; } #endif } return new List<Result>(); }
public override void Dispatch(Query q) { PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName); if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword)) { if (thirdPlugin.Metadata.Language == AllowedLanguage.Python) { SwitchPythonEnv(thirdPlugin); } ThreadPool.QueueUserWorkItem(t => { try { List<Result> r = thirdPlugin.Plugin.Query(q); r.ForEach(o => { o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry; o.OriginQuery = q; }); UpdateResultView(r); } catch (Exception queryException) { Log.Error(string.Format("Plugin {0} query failed: {1}", thirdPlugin.Metadata.Name, queryException.Message)); #if (DEBUG) { throw; } #endif } }); } }
public MainViewModel(Settings settings) { _saved = false; _queryTextBeforeLoadContextMenu = ""; _queryText = ""; _lastQuery = new Query(); _settings = settings; // happlebao todo temp fix for instance code logic HttpProxy.Instance.Settings = _settings; InternationalizationManager.Instance.Settings = _settings; InternationalizationManager.Instance.ChangeLanguage(_settings.Language); ThemeManager.Instance.Settings = _settings; _queryHistoryStorage = new JsonStrorage<QueryHistory>(); _userSelectedRecordStorage = new JsonStrorage<UserSelectedRecord>(); _topMostRecordStorage = new JsonStrorage<TopMostRecord>(); _queryHistory = _queryHistoryStorage.Load(); _userSelectedRecord = _userSelectedRecordStorage.Load(); _topMostRecord = _topMostRecordStorage.Load(); InitializeResultListBox(); InitializeContextMenu(); InitializeKeyCommands(); RegisterResultsUpdatedEvent(); SetHotkey(_settings.Hotkey, OnHotkey); SetCustomPluginHotkey(); }
public override void Dispatch(Query query) { PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionName); if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword)) { var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == thirdPlugin.Metadata.ID); if (customizedPluginConfig != null && customizedPluginConfig.Disabled) { //need to stop the loading animation UpdateResultView(null); return; } ThreadPool.QueueUserWorkItem(t => { try { List<Result> results = thirdPlugin.Plugin.Query(query) ?? new List<Result>(); App.Window.PushResults(query,thirdPlugin.Metadata,results); } catch (Exception queryException) { Log.Error(string.Format("Plugin {0} query failed: {1}", thirdPlugin.Metadata.Name, queryException.Message)); #if (DEBUG) { throw; } #endif } }); } }
public List<Result> Query(Query query) { try { string jsonResult = InvokeFunc("query", query.RawQuery); if (string.IsNullOrEmpty(jsonResult)) { return new List<Result>(); } List<PythonResult> o = JsonConvert.DeserializeObject<List<PythonResult>>(jsonResult); List<Result> r = new List<Result>(); foreach (PythonResult pythonResult in o) { PythonResult ps = pythonResult; if (!string.IsNullOrEmpty(ps.ActionName)) { ps.Action = (context) => InvokeFunc(ps.ActionName, GetPythonActionContext(context), new PyString(ps.ActionPara)); } r.Add(ps); } return r; } catch (Exception e) { #if (DEBUG) { throw new WoxPythonException(e.Message); } #endif Log.Error(string.Format("Python Plugin {0} query failed: {1}", metadata.Name, e.Message)); } return new List<Result>(); }
public List<Result> Query(Query query) { var result = new Result { Title = "Hello Word from CSharp", SubTitle = $"Query: {query.Search}", IcoPath = "app.png" }; return new List<Result> {result}; }
public void ExclusivePluginQueryTest() { Query q = new Query("f file.txt file2 file3"); q.Search = "file.txt file2 file3"; Assert.AreEqual(q.FirstSearch, "file.txt"); Assert.AreEqual(q.SecondSearch, "file2"); Assert.AreEqual(q.ThirdSearch, "file3"); Assert.AreEqual(q.SecondToEndSearch, "file2 file3"); }
public void GenericPluginQueryTest() { Query q = new Query("file.txt file2 file3"); q.Search = q.RawQuery; Assert.AreEqual(q.FirstSearch, "file.txt"); Assert.AreEqual(q.SecondSearch, "file2"); Assert.AreEqual(q.ThirdSearch, "file3"); Assert.AreEqual(q.SecondToEndSearch, "file2 file3"); }
public static void DispatchCommand(Query query) { if (Plugins.HitThirdpartyKeyword(query)) { pluginCmd.Dispatch(query); } else { systemCmd.Dispatch(query); } }
private IEnumerable<Result> EnumerateResults(Query query) { Func<Connection, bool> filter = e => true; if (!string.IsNullOrEmpty(query.FirstSearch)) filter = e => e.Name.Contains(query.FirstSearch); return ConnectionManager.EnumerateConnections() .Where(filter) .Select(Transform); }
public static void Dispatch(Query query) { if (PluginManager.IsExclusivePluginQuery(query)) { exclusivePluginDispatcher.Dispatch(query); } else { genericQueryDispatcher.Dispatch(query); } }
protected override List<PluginPair> GetPlugins(Query query) { List<PluginPair> pluginPairs = new List<PluginPair>(); var exclusivePluginPair = PluginManager.GetExclusivePlugin(query) ?? PluginManager.GetActionKeywordPlugin(query); if (exclusivePluginPair != null) { pluginPairs.Add(exclusivePluginPair); } return pluginPairs; }
public List<Result> Query(Query query) { string output = ExecuteQuery(query); if (!string.IsNullOrEmpty(output)) { try { List<Result> results = new List<Result>(); JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject<JsonRPCQueryResponseModel>(output); if (queryResponseModel.Result == null) return null; foreach (JsonRPCResult result in queryResponseModel.Result) { JsonRPCResult result1 = result; result.Action = c => { if (result1.JsonRPCAction == null) return false; if (!string.IsNullOrEmpty(result1.JsonRPCAction.Method)) { if (result1.JsonRPCAction.Method.StartsWith("Wox.")) { ExecuteWoxAPI(result1.JsonRPCAction.Method.Substring(4), result1.JsonRPCAction.Parameters); } else { ThreadPool.QueueUserWorkItem(state => { string actionReponse = ExecuteCallback(result1.JsonRPCAction); JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject<JsonRPCRequestModel>(actionReponse); if (jsonRpcRequestModel != null && !string.IsNullOrEmpty(jsonRpcRequestModel.Method) && jsonRpcRequestModel.Method.StartsWith("Wox.")) { ExecuteWoxAPI(jsonRpcRequestModel.Method.Substring(4), jsonRpcRequestModel.Parameters); } }); } } return !result1.JsonRPCAction.DontHideAfterAction; }; results.Add(result); } return results; } catch (Exception e) { Log.Error(e); } } return null; }
protected override string ExecuteQuery(Query query) { JsonRPCServerRequestModel request = new JsonRPCServerRequestModel { Method = "query", Parameters = new object[] { query.GetAllRemainingParameter() }, HttpProxy = HttpProxy.Instance }; //Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable _startInfo.FileName = Path.Combine(PythonHome, "pythonw.exe"); _startInfo.Arguments = $"-B \"{context.CurrentPluginMetadata.ExecuteFilePath}\" \"{request}\""; return Execute(_startInfo); }
protected override string ExecuteQuery(Query query) { JsonRPCServerRequestModel request = new JsonRPCServerRequestModel() { Method = "query", Parameters = new object[] { query.GetAllRemainingParameter() }, HttpProxy = HttpProxy.Instance }; //Add -B flag to tell python don't write .py[co] files. Because .pyc contains location infos which will prevent python portable startInfo.FileName = Path.Combine(woxDirectory, "PythonHome\\pythonw.exe"); startInfo.Arguments = string.Format("-B {0} \"{1}\"", context.CurrentPluginMetadata.ExecuteFilePath, request); return Execute(startInfo); }
public void QueryActionTest() { Query q = new Query("this"); Assert.AreEqual(q.ActionName,"this"); q = new Query("ev file.txt"); Assert.AreEqual(q.ActionName,"ev"); Assert.AreEqual(q.ActionParameters.Count,1); Assert.AreEqual(q.ActionParameters[0],"file.txt"); q = new Query("ev file.txt file2.txt"); Assert.AreEqual(q.ActionName,"ev"); Assert.AreEqual(q.ActionParameters.Count,2); Assert.AreEqual(q.ActionParameters[1],"file2.txt"); }
public override void Dispatch(Query query) { foreach (PluginPair pair in Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System)) { PluginPair pair1 = pair; ThreadPool.QueueUserWorkItem(state => { List<Result> results = pair1.Plugin.Query(query); results.ForEach(o=> { o.AutoAjustScore = true; }); App.Window.PushResults(query,pair1.Metadata,results); }); } }
public static void DispatchCommand(Query query) { //lazy init command instance. if (pluginCmd == null) { pluginCmd = new PluginCommand(); } if (systemCmd == null) { systemCmd = new SystemCommand(); } systemCmd.Dispatch(query); pluginCmd.Dispatch(query); }
public override void Dispatch(Query query,bool updateView = true) { foreach (PluginPair pair in systemPlugins) { PluginPair pair1 = pair; ThreadPool.QueueUserWorkItem(state => { List<Result> results = pair1.Plugin.Query(query); foreach (Result result in results) { result.PluginDirectory = pair1.Metadata.PluginDirecotry; result.OriginQuery = query; result.AutoAjustScore = true; } if(results.Count > 0 && updateView) UpdateResultView(results); }); } }
public static void DispatchCommand(Query query) { //lazy init command instance. if (pluginCmd == null) { pluginCmd = new PluginCommand(); } if (systemCmd == null) { systemCmd = new SystemCommand(); } if (Plugins.HitThirdpartyKeyword(query)) { pluginCmd.Dispatch(query); } else { systemCmd.Dispatch(query); } }
public void Dispatch(Query query) { foreach (PluginPair pair in GetPlugins(query)) { PluginPair localPair = pair; if (query.IsIntantQuery && PluginManager.IsInstantSearchPlugin(pair.Metadata)) { DebugHelper.WriteLine(string.Format("Plugin {0} is executing instant search.", pair.Metadata.Name)); using (new Timeit(" => instant search took: ")) { PluginManager.ExecutePluginQuery(localPair, query); } } else { ThreadPool.QueueUserWorkItem(state => { PluginManager.ExecutePluginQuery(localPair, query); }); } } }
public List<Result> Query(Query query) { List<Result> results = new List<Result>(); string key = query.Search; if (string.IsNullOrEmpty(key) || key.Trim() == string.Empty) { return results; } var segs = key.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries); var fake = segs[0]; int num = segs.Length - 1; StringBuilder builder = new StringBuilder(); if (fake.Length >= num) { combine(builder, fake, segs, num); builder.Append(fake.Substring(num)); } else { combine(builder, fake, segs, num); } results.Add(new Result { Title = builder.ToString(), SubTitle = "按回车复制", IcoPath = "zx.png", Action = e => { Clipboard.SetText(builder.ToString()); return true; } }); return results; }
public override void Dispatch(Query query) { foreach (PluginPair pair in Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System)) { PluginPair pair1 = pair; ThreadPool.QueueUserWorkItem(state => { pair1.InitContext.PushResults = (q, r) => { if (r == null || r.Count == 0) return; foreach (Result result in r) { result.PluginDirectory = pair1.Metadata.PluginDirecotry; result.OriginQuery = q; result.AutoAjustScore = true; } UpdateResultView(r); }; List<Result> results = pair1.Plugin.Query(query); pair1.InitContext.PushResults(query, results); }); } }
public override void Dispatch(Query query) { var queryPlugins = allSytemPlugins; if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == query.ActionName && o.Enabled)) { //websearch mode queryPlugins = new List<PluginPair>() { allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF") }; } foreach (PluginPair pair in queryPlugins) { PluginPair pair1 = pair; ThreadPool.QueueUserWorkItem(state => { List<Result> results = pair1.Plugin.Query(query); results.ForEach(o => { o.AutoAjustScore = true; }); App.Window.PushResults(query, pair1.Metadata, results); }); } }
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) { if (ignoreTextChange) { ignoreTextChange = false; return; } lastQuery = tbQuery.Text; toolTip.IsOpen = false; resultCtrl.Dirty = true; Dispatcher.DelayInvoke("UpdateSearch", o => { Dispatcher.DelayInvoke("ClearResults", i => { // first try to use clear method inside resultCtrl, which is more closer to the add new results // and this will not bring splash issues.After waiting 30ms, if there still no results added, we // must clear the result. otherwise, it will be confused why the query changed, but the results // didn't. if (resultCtrl.Dirty) resultCtrl.Clear(); }, TimeSpan.FromMilliseconds(100), null); var q = new Query(lastQuery); CommandFactory.DispatchCommand(q); queryHasReturn = false; if (Plugins.HitThirdpartyKeyword(q)) { Dispatcher.DelayInvoke("ShowProgressbar", originQuery => { if (!queryHasReturn && originQuery == lastQuery) { StartProgress(); } }, TimeSpan.FromSeconds(0), lastQuery); } }, TimeSpan.FromMilliseconds((isCMDMode = tbQuery.Text.StartsWith(">")) ? 0 : 150)); }
private void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery) { Thread.Sleep(3000); _queryHasReturn = true; progressBar.Dispatcher.Invoke(new Action(StopProgress)); list.ForEach(o => { o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5; }); if (originQuery.RawQuery == _lastQuery.RawQuery) { UpdateResultViewInternal(list, metadata); } }
protected abstract List<PluginPair> GetPlugins(Query query);
public void PushResults(Query query, PluginMetadata plugin, List<Result> results) { results.ForEach(o => { o.PluginDirectory = plugin.PluginDirectory; o.PluginID = plugin.ID; o.OriginQuery = query; }); Task.Run(() => { _mainVM.UpdateResultView(results, plugin, query); }); }