public List <Result> Query(Query query) { if (query.Search.Length <= 2 || // don't affect when user only input "e" or "i" keyword !regValidExpressChar.IsMatch(query.Search) || !IsBracketComplete(query.Search)) { return(new List <Result>()); } try { var result = magesEngine.Interpret(query.Search); if (result.ToString() == "NaN") { result = context.API.GetTranslation("wox_plugin_calculator_not_a_number"); } if (result is Function) { result = context.API.GetTranslation("wox_plugin_calculator_expression_not_complete"); } if (result != null && !string.IsNullOrEmpty(result.ToString())) { return(new List <Result> { new Result { Title = result.ToString(), IcoPath = "Images/calculator.png", Score = 300, SubTitle = context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), Action = c => { try { Clipboard.SetText(result.ToString()); return true; } catch (ExternalException e) { MessageBox.Show("Copy failed, please try later"); return false; } } } }); } } catch { } return(new List <Result>()); }
/// <summary> /// Interprets the given source and returns the result in form of a future. /// </summary> /// <param name="engine">The engine.</param> /// <param name="source">The source to interpret.</param> /// <returns>The result in form of a future. Any callbacks will be aggregated here.</returns> public static Future InterpretAsync(this Engine engine, String source) { var future = new Future(); var result = engine.Interpret(source); var promise = result as Future; if (promise != null) { promise.ContinueWith(future); } else { future.SetResult(result); } return(future); }