/// <summary> /// Provides the value associated to this Expression /// </summary> /// <param name="context">The context on which the value must be found</param> /// <returns></returns> public override Values.IValue GetValue(InterpretationContext context) { LastIteration.Value = InitialValue.GetValue(context); bool stop = false; while (!stop) { int token = context.LocalScope.PushContext(); context.LocalScope.setVariable(LastIteration); CurrentIteration.Value = Expression.GetValue(context); context.LocalScope.setVariable(CurrentIteration); Values.BoolValue stopCondition = Condition.GetValue(context) as Values.BoolValue; if (stopCondition != null) { stop = stopCondition.Val; } else { AddError("Cannot evaluate condition " + Condition.ToString()); stop = true; } context.LocalScope.PopContext(token); LastIteration.Value = CurrentIteration.Value; } return(CurrentIteration.Value); }
/// <summary> /// Provides the value associated to this Expression /// </summary> /// <param name="context">The context on which the value must be found</param> /// <returns></returns> public override Values.IValue GetValue(InterpretationContext context) { Values.IValue retVal = null; Values.ListValue value = ListExpression.GetValue(context) as Values.ListValue; if (value != null) { int token = PrepareIteration(context); context.LocalScope.setVariable(AccumulatorVariable); AccumulatorVariable.Value = InitialValue.GetValue(context); foreach (Values.IValue v in value.Val) { if (v != EFSSystem.EmptyValue) { IteratorVariable.Value = v; if (conditionSatisfied(context)) { AccumulatorVariable.Value = IteratorExpression.GetValue(context); } } NextIteration(); } EndIteration(context, token); retVal = AccumulatorVariable.Value; } else { AddError("Cannot evaluate list value " + ListExpression.ToString()); } return(retVal); }
public string Extract(IRow row) { try { var field = InitialValue.GetValue(row); foreach (var filter in Filters) { field = filter.Apply(field); } return(field); } catch (Exception ex) { throw new ExtractedValueException(this, row, InitialValue, ex); } }
/// <summary> /// Provides the value associated to this Expression /// </summary> /// <param name="context">The context on which the value must be found</param> /// <param name="explain">The explanation to fill, if any</param> /// <returns></returns> protected internal override IValue GetValue(InterpretationContext context, ExplanationPart explain) { IValue retVal = null; ListValue value = ListExpression.GetValue(context, explain) as ListValue; if (value != null) { int token = PrepareIteration(context); context.LocalScope.SetVariable(AccumulatorVariable); AccumulatorVariable.Value = InitialValue.GetValue(context, explain); foreach (IValue v in value.Val) { if (v != EfsSystem.Instance.EmptyValue) { // All elements should always be != from EmptyValue ElementFound = true; IteratorVariable.Value = v; if (ConditionSatisfied(context, explain)) { MatchingElementFound = true; AccumulatorVariable.Value = IteratorExpression.GetValue(context, explain); } } NextIteration(); } EndIteration(context, explain, token); retVal = AccumulatorVariable.Value; } else { AddError("Cannot evaluate list value " + ListExpression, RuleChecksEnum.ExecutionFailed); } return(retVal); }
/// <summary> /// Provides the value associated to this Expression /// </summary> /// <param name="context">The context on which the value must be found</param> /// <param name="explain">The explanation to fill, if any</param> /// <returns></returns> protected internal override IValue GetValue(InterpretationContext context, ExplanationPart explain) { ExplanationPart stabilizeExpressionExplanation = ExplanationPart.CreateSubExplanation(explain, this); IterationsList = new List <IValue>(); LastIteration.Value = InitialValue.GetValue(context, explain); int i = 0; bool stop = false; while (!stop) { i = i + 1; ExplanationPart iterationExplanation = ExplanationPart.CreateSubExplanation(stabilizeExpressionExplanation, "Iteration " + i); ExplanationPart iteratorValueExplanation = ExplanationPart.CreateSubExplanation(iterationExplanation, "Iteration expression value = "); int token = context.LocalScope.PushContext(); context.LocalScope.SetVariable(LastIteration); CurrentIteration.Value = Expression.GetValue(context, iteratorValueExplanation); ExplanationPart.SetNamable(iteratorValueExplanation, CurrentIteration.Value); ExplanationPart stopValueExplanation = ExplanationPart.CreateSubExplanation(iterationExplanation, "Stop expression value = "); context.LocalScope.SetVariable(CurrentIteration); BoolValue stopCondition = Condition.GetValue(context, stopValueExplanation) as BoolValue; ExplanationPart.SetNamable(stopValueExplanation, stopCondition); if (stopCondition != null) { stop = stopCondition.Val; } else { AddError("Cannot evaluate condition " + Condition, RuleChecksEnum.ExecutionFailed); stop = true; } if (!stop && IterationsList.Exists(x => x.LiteralName == CurrentIteration.Value.LiteralName)) { // Cycle found !!! IterationsList.Add(CurrentIteration.Value); string cycleReport = "Execution cycled: "; bool keepvalues = false; foreach (IValue value in IterationsList) { if (keepvalues) { cycleReport += ", " + value.LiteralName; } else if (value.LiteralName == CurrentIteration.Value.LiteralName) { keepvalues = true; cycleReport += value.LiteralName; } } ExplanationPart.CreateSubExplanation(stabilizeExpressionExplanation, cycleReport); CurrentIteration.Value = EfsSystem.Instance.EmptyValue; stop = true; } else { IterationsList.Add(CurrentIteration.Value); } context.LocalScope.PopContext(token); LastIteration.Value = CurrentIteration.Value; } ExplanationPart.SetNamable(stabilizeExpressionExplanation, CurrentIteration.Value); return(CurrentIteration.Value); }