/// <summary> /// Evaluates the selected <see cref="Pattern"/>. /// </summary> /// <remarks> /// As most of the other evaluation methods, it repositions the /// <see cref="EvaluationContextBase.Source"/> navigator on the root node. /// <para> /// Clears the <see cref="EvaluationContextBase.Matched"/> object before /// proceeding, as the restriction about node mathing (see <linkref id="schematron" />) /// applies only inside a single pattern. /// </para> /// </remarks> /// <param name="pattern">The <see cref="Pattern"/> to evaluate.</param> /// <param name="output">Contains the builder to accumulate messages in.</param> /// <returns>A boolean indicating if a new message was added.</returns> private bool Evaluate(Pattern pattern, StringBuilder output) { bool failed = false; Source.MoveToRoot(); StringBuilder sb = new StringBuilder(); // Reset matched nodes, as across patters, nodes can be // evaluated more than once. Matched.Clear(); foreach (Rule rule in pattern.Rules) { if (Evaluate(rule, sb)) { failed = true; } } if (failed) { Formatter.Format(pattern, Source, sb); output.Append(sb.ToString()); } return(failed); }
void Sort <T>(Func <ManualMatchedPair <TInternal, TExternal>, T> sortKey) { var list = Matched.OrderBy(sortKey).ToList(); Matched.Clear(); foreach (var e in list) { Matched.Add(e); } }
/// <summary> /// Evaluates the selected <see cref="Pattern"/>. /// </summary> /// <remarks> /// Processing is synchronous, as rules must me evaluated in document order. /// <para> /// As most of the other evaluation methods, it repositions the /// <see cref="EvaluationContextBase.Source"/> navigator on the root node. /// </para> /// <para> /// Clears the <see cref="EvaluationContextBase.Matched"/> object before /// proceeding, as the restriction about node mathing (see <link ref="schematron" />) /// applies only inside a single pattern. /// </para> /// </remarks> /// <param name="pattern">The <see cref="Pattern"/> to evaluate.</param> /// <returns>The messages accumulated by the evaluation of all the child /// <see cref="Rule"/>, or <see cref="String.Empty"/> if there are no messages.</returns> private string Evaluate(Pattern pattern) { Source.MoveToRoot(); StringBuilder sb = new StringBuilder(); // Reset matched nodes, as across patters, nodes can be // evaluated more than once. Matched.Clear(); foreach (Rule rule in pattern.Rules) { sb.Append(Evaluate(rule)); } string res = sb.ToString(); return(Formatter.Format(pattern, res, Source)); }