public override FunctionExecuteResult Execute(FunctionExecuteArgs args) { try { for (var i = 0; i < args.Args[0].Length; i++) { if (char.ToLower(args.Args[0][i]) != char.ToLower(args.Input[i])) return new FunctionExecuteResult(false, 0); } return new FunctionExecuteResult(true, args.Args[0].Length); } catch (Exception e) { return new FunctionExecuteResult(false, 0); } }
public override FunctionExecuteResult Execute(FunctionExecuteArgs args) { try { var argss = new List<string>(); if (args.Attributes.ContainsKey("type") && args.Attributes["type"].ToLower() == "word") { foreach (var a in args.Args) { var fa = string.Empty; if (!a.StartsWith(" ") && args.CurrentTokenIndex != 0) { fa += " "; } fa += a; if (!a.EndsWith(" ")) { fa += " "; } argss.Add(fa); } } else { argss.AddRange(args.Args); } args.Args = argss.ToArray(); var any = new AnyFunctionExecutor(); var result = any.Execute(args); if (result.IsMatch) { return result; } return new FunctionExecuteResult(true, 0); } catch (Exception e) { return new FunctionExecuteResult(true, 0); } }
public override FunctionExecuteResult Execute(FunctionExecuteArgs args) { var res = new List<string>(); if (args.Args[0].StartsWith("@")) { var source = new WebSynonymsSource(); Console.WriteLine("Соединяюсь с интернетом, на выполнение запроса уйдет немного больше времени..."); var ss = source.GetSynonyms(args.Args[0].Substring(1)); res.AddRange(ss); res.Add(args.Args[0].Substring(1)); } else { res = new List<string>(args.Args); } var result = new List<string>(); foreach (var arg in res) { try { for (var i = 0; i < arg.Length; i++) { if (i == arg.Length - 1 && char.ToLower(args.Input[i]) == char.ToLower(arg[i])) { if (args.Attributes.ContainsKey("id")) { args.Provider.ComponentsData.Add(args.Attributes["id"], arg); } result.Add(arg); } if (char.ToLower(args.Input[i]) != char.ToLower(arg[i])) break; } } catch { } } if (result.Count == 0) { return new FunctionExecuteResult(false, 0); } if (result.Count == 1) { return new FunctionExecuteResult(true, result.First().Length); } result.Sort((s1, s2) => { if (s1.Length > s2.Length) return 1; if (s1.Length == s2.Length) return 0; return -1; }); return new FunctionExecuteResult(true, result.Last().Length); }
public override FunctionExecuteResult Execute(FunctionExecuteArgs args) { try { var result = string.Empty; if (args.CurrentTokenIndex == args.Token.Elements.Count - 1) { result = args.Input; } else { var textLine = new TextLine(args.Input); for (var i = 0; i < textLine.Words.Count; i++) { var str = textLine.Words[i].ToEnd; var expressionBuilder = new StringBuilder(); for (var j = args.CurrentTokenIndex+1; j < args.Token.Elements.Count; j++) { expressionBuilder.Append(args.Token.Elements[j].Text); } var expressionText = expressionBuilder.ToString(); var expression = new RoseMarkExpression(expressionText); var encodeDataHolder = new Dictionary<string, object>(); var compileResult = expression.Compile(new CompileInfo { EncodeDataHolder = encodeDataHolder, Input = " " + str, PrecompiledDataHolder = args.Resources, ShouldCheckLenght = false }); if (compileResult.IsCompiled) { if (args.Attributes.ContainsKey("id")) { args.Provider.ComponentsData.Add(args.Attributes["id"], textLine.Words[i].ToStart); } return new FunctionExecuteResult(true, textLine.Words[i].ToStart.Length); } } return new FunctionExecuteResult(false, 0); } if (args.Attributes.ContainsKey("id")) { args.Provider.ComponentsData.Add(args.Attributes["id"], result); } return new FunctionExecuteResult(true, result.Length); } catch (Exception e) { return new FunctionExecuteResult(false, 0); } }