/// <summary> /// Sets the <paramref name="outputExpression">output expression</paramref> for the output referenced by <paramref name="outputRef"/> /// </summary> /// <remarks> /// When the expression is null or whitespace the table output will not be used for the rule (will be removed when it was already defined before). /// When the expression is "valid" and the output expression has been defined before, it will override it /// </remarks> /// <param name="outputRef">Reference to decision table output</param> /// <param name="outputExpression">Output calculation 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="outputRef"/> is null</exception> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="outputRef"/> is not recognized as the valid table output</exception> private void SetOutput(TableOutput.Ref outputRef, string outputExpression) { if (IsBuilt) { throw Logger.Error <DmnBuilderException>("Table rule is already built"); } if (outputRef == null) { throw new ArgumentNullException(nameof(outputRef)); } if (!AllTableOutputs.ContainsKey(outputRef)) { throw Logger.Error <DmnBuilderException>("Output reference is not valid for current table"); } if (string.IsNullOrWhiteSpace(outputExpression)) { if (OutputsInternal.ContainsKey(outputRef)) { OutputsInternal.Remove(outputRef); } } else { OutputsInternal[outputRef] = outputExpression; } }
/// <summary> /// Adds the table output with reference to the variable to store the output value to /// </summary> /// <remarks>The outputs are "indexed" in the order as added to the table definition builder</remarks> /// <param name="variableRef">Reference to variable used to store the table output to</param> /// <param name="outputRef">Reference to added table output that can be used in rule builders</param> /// <param name="allowedValues">Allowed output values</param> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception> /// <exception cref="ArgumentNullException"> when the <paramref name="variableRef"/> is not provided</exception> public TableDecision WithOutput(Variable.Ref variableRef, out TableOutput.Ref outputRef, params string[] allowedValues) { if (IsBuilt) { throw Logger.Error <DmnBuilderException>($"Decision is already built"); } if (variableRef == null) { throw new ArgumentNullException(nameof(variableRef)); } var output = new TableOutput(Variables, Decisions, OutputsInternal.Count).WithVariable(variableRef); _ = allowedValues != null && allowedValues.Length > 0 ? output.WithAllowedValues(allowedValues) : output.WithoutAllowedValuesConstraint(); outputRef = output.Reference; OutputsInternal.Add(output); OutputsByRef.Add(outputRef, output); return(this); }
/// <summary> /// Sets the <paramref name="outputExpression">output expression</paramref> for the output referenced by <paramref name="outputRef"/> /// </summary> /// <remarks> /// When the expression is null or whitespace the table output will not be used for the rule (will be removed when it was already defined before). /// When the expression is "valid" and the output expression has been defined before, it will override it /// </remarks> /// <param name="outputRef">Reference to decision table output</param> /// <param name="outputExpression">Output calculation 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="outputRef"/> is null</exception> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="outputRef"/> is not recognized as the valid table output</exception> public TableRuleAndOutputBuilder And(TableOutput.Ref outputRef, string outputExpression) { Rule.SetOutput(outputRef, outputExpression); return(this); }
/// <summary> /// Sets the <paramref name="outputExpression">output expression</paramref> for the output referenced by <paramref name="outputRef"/> /// </summary> /// <remarks> /// <see cref="Then"/>clears all output expressions for the rule first and then add the <paramref name="outputExpression"/> for <see cref="outputRef"/> /// When the expression is null or whitespace the table input will not be used for the rule (will not be added). /// </remarks> /// <param name="outputRef">Reference to decision table output</param> /// <param name="outputExpression">Output calculation 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="outputRef"/> is null</exception> /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the <paramref name="outputRef"/> is not recognized as the valid table output</exception> public TableRuleAndOutputBuilder Then(TableOutput.Ref outputRef, string outputExpression) { Rule.ClearOutputs(); Rule.SetOutput(outputRef, outputExpression); return(new TableRuleAndOutputBuilder(Rule)); }
/// <summary> /// Adds the table output with reference to the variable to store the output value to /// </summary> /// <remarks>The outputs are "indexed" in the order as added to the table definition builder</remarks> /// <param name="variableRef">Reference to variable used to store the table output to</param> /// <param name="outputRef">Reference to added table output 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="variableRef"/> is not provided</exception> public TableDecision WithOutput(Variable.Ref variableRef, out TableOutput.Ref outputRef) { return(WithOutput(variableRef, out outputRef, null)); }