public override FunctionExecuteResult Execute(FunctionExecuteArgs args) { try { var resName = args.Args[0]; var res = args.Resources[resName]; if (res is PatternText) { var expression = new RoseMarkExpression((res as PatternText).Text); var encode = new Dictionary<string, object>(); var compileResult = expression.Compile(new CompileInfo { EncodeDataHolder = encode, Input = args.Input, PrecompiledDataHolder = args.Resources, ShouldCheckLenght = false }); if (compileResult.IsCompiled) { foreach (var o in encode) { args.Provider.ComponentsData.Add(o.Key, o.Value); } return new FunctionExecuteResult(true, compileResult.Lenght); } } return new FunctionExecuteResult(false, 0); } catch { return new FunctionExecuteResult(false, 0); } }
private void CalculateClick(object sender, RoutedEventArgs e) { try { if (InputBox.Text == string.Empty || PatternBox.Text == string.Empty) { SetStatusLabelMessage("Следует заполнить все поля формы", StatusLabelColor.Red); } var expression = new RoseMarkExpression(PatternBox.Text); var encodeDataHolder = new Dictionary<string, object>(); var res = new Dictionary<string, object>(); var stopwatch = new Stopwatch(); stopwatch.Start();; var compileInfo = new CompileInfo { Input = InputBox.Text, PrecompiledDataHolder = res, ShouldCheckLenght = true, EncodeDataHolder = encodeDataHolder }; var result = expression.Compile(compileInfo); if (result.IsCompiled) { SetStatusLabelMessage("Cоответствие", StatusLabelColor.Green); } else { SetStatusLabelMessage("Несоответствие", StatusLabelColor.Red); } var builder = new StringBuilder(); builder.AppendLine("Затрачено времени: " + stopwatch.Elapsed); var token = ExpressionToken.Parse(PatternBox.Text); builder.AppendLine("Количество элементов токена: " + token.Elements.Count); foreach (var el in token.Elements) { builder.AppendLine("Элемент '" + el.Text + "': Тип:" + el.GetType()); } builder.AppendLine("Количество данных кодировщика: " + encodeDataHolder.Count); foreach (var o in encodeDataHolder) { builder.AppendLine(o.Key + ": " + o.Value); } ResultOutput.Text = builder.ToString(); } catch (Exception exception) { SetStatusLabelMessage("Ошибка во время выполнения", StatusLabelColor.Red); } }
public override EncodingResult Encode(string pattern, string input, Dictionary<string, object> resources) { var expression = new RoseMarkExpression(input); var data = new Dictionary<string, object>(); var matchResult = expression.Compile(new CompileInfo { EncodeDataHolder = data, PrecompiledDataHolder = resources, Input = pattern }); var result = new EncodingResult {Result = matchResult.IsCompiled, EncodeData = data}; return result; }