Ejemplo n.º 1
0
        public Expressions.INode Parse(IExecutionContext executionContext, string condition)
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));
            var expressionTrace = new TraceWriter(Trace, executionContext);
            var parser          = new Expressions.Parser();
            var namedValues     = new Expressions.INamedValueInfo[]
            {
                new Expressions.NamedValueInfo <VariablesNode>(name: Constants.Expressions.Variables),
            };
            var functions = new Expressions.IFunctionInfo[]
            {
                new Expressions.FunctionInfo <AlwaysNode>(name: Constants.Expressions.Always, minParameters: 0, maxParameters: 0),
                new Expressions.FunctionInfo <CanceledNode>(name: Constants.Expressions.Canceled, minParameters: 0, maxParameters: 0),
                new Expressions.FunctionInfo <FailedNode>(name: Constants.Expressions.Failed, minParameters: 0, maxParameters: 0),
                new Expressions.FunctionInfo <SucceededNode>(name: Constants.Expressions.Succeeded, minParameters: 0, maxParameters: 0),
                new Expressions.FunctionInfo <SucceededOrFailedNode>(name: Constants.Expressions.SucceededOrFailed, minParameters: 0, maxParameters: 0),
            };

            return(parser.CreateTree(condition, expressionTrace, namedValues, functions) ?? new SucceededNode());
        }
Ejemplo n.º 2
0
        public bool Evaluate(IExecutionContext executionContext, string condition)
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));

            // Parse the condition.
            var expressionTrace = new TraceWriter(executionContext);
            var parser          = new DT.Parser();
            var extensions      = new DT.IFunctionInfo[]
            {
                new DT.FunctionInfo <AlwaysNode>(name: Constants.Expressions.Always, minParameters: 0, maxParameters: 0),
                new DT.FunctionInfo <SucceededNode>(name: Constants.Expressions.Succeeded, minParameters: 0, maxParameters: 0),
                new DT.FunctionInfo <SucceededOrFailedNode>(name: Constants.Expressions.SucceededOrFailed, minParameters: 0, maxParameters: 0),
                new DT.FunctionInfo <VariablesNode>(name: Constants.Expressions.Variables, minParameters: 1, maxParameters: 1),
            };

            DT.INode tree = parser.CreateTree(condition, expressionTrace, extensions) ?? new SucceededNode();

            // Evaluate the tree.
            return(tree.EvaluateBoolean(trace: expressionTrace, state: executionContext));
        }