Ejemplo n.º 1
0
        /// <summary>
        /// Sets the <paramref name="inputExpression">input expression</paramref> for the input referenced by <paramref name="inputRef"/>
        /// </summary>
        /// <remarks>
        /// When the expression is null or whitespace the table input will not be used for the rule (will be removed when it was already defined before).
        /// When the expression is "valid" and the input expression has been defined before, it will override it
        /// </remarks>
        /// <param name="inputRef">Reference to decision table input</param>
        /// <param name="inputExpression">Input evaluation expression</param>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
        /// <exception cref="ArgumentNullException">Throws <see cref="ArgumentNullException"/> when the <paramref name="inputRef"/> is null</exception>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="inputRef"/> is not recognized as the valid table input</exception>
        private void SetInput(TableInput.Ref inputRef, string inputExpression)
        {
            if (IsBuilt)
            {
                throw Logger.Error <DmnBuilderException>("Table rule is already built");
            }

            if (inputRef == null)
            {
                throw new ArgumentNullException(nameof(inputRef));
            }
            if (!AllTableInputs.ContainsKey(inputRef))
            {
                throw Logger.Error <DmnBuilderException>("Input reference is not valid for current table");
            }

            if (string.IsNullOrWhiteSpace(inputExpression))
            {
                if (InputsInternal.ContainsKey(inputRef))
                {
                    InputsInternal.Remove(inputRef);
                }
            }
            else
            {
                InputsInternal[inputRef] = inputExpression;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the expression based table input
        /// </summary>
        /// <remarks>The inputs are "indexed" in the order as added to the table definition builder</remarks>
        /// <param name="expression">Expression to be used as table input</param>
        /// <param name="inputRef">Reference to added table input that can be used in rule builders</param>
        /// <param name="allowedValues">Allowed input values</param>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
        /// <exception cref="ArgumentNullException"> when the <paramref name="expression"/> is not provided</exception>
        /// <exception cref="ArgumentException"> when the <paramref name="expression"/> is empty or whitespace</exception>
        public TableDecision WithInput(string expression, out TableInput.Ref inputRef, params string[] allowedValues)
        {
            if (IsBuilt)
            {
                throw Logger.Error <DmnBuilderException>($"Decision is already built");
            }
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }
            if (string.IsNullOrWhiteSpace(expression))
            {
                throw new ArgumentException("Missing expression", nameof(expression));
            }

            var input = new TableInput(Variables, Decisions, InputsInternal.Count).WithExpression(expression);

            _ = allowedValues != null && allowedValues.Length > 0
                ? input.WithAllowedValues(allowedValues)
                : input.WithoutAllowedValuesConstraint();

            inputRef = input.Reference;
            InputsInternal.Add(input);
            InputsByRef.Add(inputRef, input);
            return(this);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets the <paramref name="inputExpression">input expression</paramref> for the input referenced by <paramref name="inputRef"/>
 /// </summary>
 /// <remarks>
 /// When the expression is null or whitespace the table input will not be used for the rule (will be removed when it was already defined before).
 /// When the expression is "valid" and the input expression has been defined before, it will override it
 /// </remarks>
 /// <param name="inputRef">Reference to decision table input</param>
 /// <param name="inputExpression">Input evaluation expression</param>
 /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
 /// <exception cref="ArgumentNullException">Throws <see cref="ArgumentNullException"/> when the <paramref name="inputRef"/> is null</exception>
 /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="inputRef"/> is not recognized as the valid table input</exception>
 public TableRuleThenOrAndBuilder And(TableInput.Ref inputRef, string inputExpression)
 {
     Rule.SetInput(inputRef, inputExpression);
     return(this);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets the <paramref name="inputExpression">input expression</paramref> for the input referenced by <paramref name="inputRef"/>
 /// </summary>
 /// <remarks>
 /// <see cref="When"/>clears all input expressions for the rule first and then add the <paramref name="inputExpression"/> for <see cref="inputRef"/>
 /// When the expression is null or whitespace the table input will not be used for the rule (will not be added).
 /// </remarks>
 /// <param name="inputRef">Reference to decision table input</param>
 /// <param name="inputExpression">Input evaluation expression</param>
 /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
 /// <exception cref="ArgumentNullException">Throws <see cref="ArgumentNullException"/> when the <paramref name="inputRef"/> is null</exception>
 /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="inputRef"/> is not recognized as the valid table input</exception>
 public TableRuleThenOrAndBuilder When(TableInput.Ref inputRef, string inputExpression)
 {
     Rule.ClearInputs();
     Rule.SetInput(inputRef, inputExpression);
     return(new TableRuleThenOrAndBuilder(Rule));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds the expression based table input
 /// </summary>
 /// <remarks>The inputs are "indexed" in the order as added to the table definition builder</remarks>
 /// <param name="expression">Expression to be used as table input</param>
 /// <param name="inputRef">Reference to added table input that can be used in rule builders</param>
 /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
 /// <exception cref="ArgumentNullException"> when the <paramref name="expression"/> is not provided</exception>
 /// <exception cref="ArgumentException"> when the <paramref name="expression"/> is empty or whitespace</exception>
 public TableDecision WithInput(string expression, out TableInput.Ref inputRef)
 {
     return(WithInput(expression, out inputRef, null));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Adds the variable based table input
 /// </summary>
 /// <remarks>The inputs are "indexed" in the order as added to the table definition builder</remarks>
 /// <param name="variableRef">Reference to variable used as table input</param>
 /// <param name="inputRef">Reference to added table input that can be used in rule builders</param>
 /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
 public TableDecision WithInput(Variable.Ref variableRef, out TableInput.Ref inputRef)
 {
     return(WithInput(variableRef, out inputRef, null));
 }