public async Task <bool> EvaluateConditionAsync( LazyInput lazyInput, IContext context, CancellationToken cancellationToken) { string comparisonValue; switch (Source) { case ValueSource.Input: comparisonValue = lazyInput.SerializedContent; break; case ValueSource.Context: comparisonValue = await context.GetVariableAsync(Variable, cancellationToken); break; case ValueSource.Intent: comparisonValue = (await lazyInput.GetIntentAsync())?.Name; break; case ValueSource.Entity: comparisonValue = (await lazyInput.GetEntityValue(Entity))?.Value; break; default: throw new ArgumentOutOfRangeException(); } switch (Comparison.GetComparisonType()) { case ComparisonType.Unary: var unaryComparisonFunc = Comparison.ToUnaryDelegate(); return(unaryComparisonFunc(comparisonValue)); case ComparisonType.Binary: var binaryComparisonFunc = Comparison.ToBinaryDelegate(); switch (Operator) { case ConditionOperator.Or: return(Values.Any(v => binaryComparisonFunc(comparisonValue, v))); case ConditionOperator.And: return(Values.All(v => binaryComparisonFunc(comparisonValue, v))); default: throw new ArgumentOutOfRangeException(); } default: throw new ArgumentOutOfRangeException(); } }
private async Task <string> GetEntityVariableAsync(LazyInput input, string entityName, string entityProperty) { var entity = await input.GetEntityValue(entityName); if (entity == null) { return(null); } switch (entityProperty) { case "id": return(entity.Id); case "name": return(entity.Name); case "value": return(entity.Value); } return(null); }