/// <summary> /// Executes this action. /// </summary> /// <param name="model">The model.</param> /// <param name="context">The context.</param> public abstract void Execute([NotNull] RootModel model, [NotNull] ActionExecutionContext context);
public abstract string GetParameterValue([NotNull] RootModel rootModel, [NotNull] ActionExecutionContext context);
/// <summary> /// /// </summary> /// <param name="textMessage"></param> /// <param name="rootModel"></param> public void HandleMessage([NotNull] TextMessage textMessage, [NotNull] RootModel rootModel) { Assert.ArgumentNotNull(textMessage, "message"); Assert.ArgumentNotNull(rootModel, "rootModel"); ClearMatchingResults(); string text = textMessage.InnerText; if (string.IsNullOrEmpty(textMessage.InnerText)) { return; } if (IsRegExp) { Regex rExp; if (_compiledRegex != null) { rExp = _compiledRegex; } else { var varReplace = rootModel.ReplaceVariables(_pattern); if (!varReplace.IsAllVariables) { return; } rExp = new Regex(varReplace.Value); } StringBuilder sb = new StringBuilder(text.Length); int offset = 0; Match match = rExp.Match(textMessage.InnerText); if (match.Success) { do { if (offset < match.Index) { sb.Append(text, offset, match.Index - offset); } offset = match.Index + match.Length; sb.Append(_wildRegex.Replace(SubstituteWith, m => { return(match.Groups[int.Parse(m.Value.Substring(1))].Value); })); match = rExp.Match(textMessage.InnerText, match.Index + match.Length); } while (match.Success); if (offset < textMessage.InnerText.Length) { sb.Append(text, offset, textMessage.InnerText.Length - offset); } //TODO: We have cleared information about color :( Need to do something with this textMessage.Clear(); textMessage.AppendText(sb.ToString()); } } else { int position = 0; ClearMatchingResults(); var res = GetRootPatternToken(rootModel).Match(text, position, _matchingResults); while (res.IsSuccess) { //Actually method TextMessage.Substitute() too heavy if we are substituting more than one substitution in one string //TODO: Best way build string right here textMessage.Substitute(res.StartPosition, res.EndPosition - res.StartPosition, GetSubstituteWithPatternToken(rootModel).GetValue(_matchingResults)); position = res.StartPosition + GetSubstituteWithPatternToken(rootModel).GetValue(_matchingResults).Length; ClearMatchingResults(); if (position > text.Length) { break; } res = GetRootPatternToken(rootModel).Match(text, position, _matchingResults); } } }