public List <Result> Query(Query query) { if (query == null) { throw new ArgumentNullException(paramName: nameof(query)); } if (!CalculateHelper.InputValid(query.Search)) { return(new List <Result>()); } try { // Using CurrentUICulture since this is user facing var result = CalculateEngine.Interpret(query.Search, CultureInfo.CurrentUICulture); // This could happen for some incorrect queries, like pi(2) if (result.Equals(default(CalculateResult))) { return(new List <Result>()); } return(new List <Result> { ResultHelper.CreateResult(result.RoundedResult, IconPath), }); } // We want to keep the process alive if any the mages library throws any exceptions. #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { Log.Exception("Exception when query for <{query}>", e, GetType()); } return(new List <Result>()); }
public CalculateResult Interpret(string input, CultureInfo cultureInfo) { if (!CalculateHelper.InputValid(input)) { return(default);