Example #1
0
        /// <summary>
        /// Builds the decision table definition
        /// </summary>
        /// <returns>Table decision definition built</returns>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when there is no input, no output or no rule defined in builder</exception>
        protected internal override IDmnDecision Build()
        {
            if (IsBuilt)
            {
                throw Logger.Error <DmnBuilderException>("Decision is already built");
            }
            if (InputsInternal.Count < 1)
            {
                throw Logger.Error <DmnBuilderException>($"At least one input must be defined for decision table {Name}");
            }
            if (OutputsInternal.Count < 1)
            {
                throw Logger.Error <DmnBuilderException>($"At least one output must be defined for decision table {Name}");
            }
            if (RulesInternal.Count < 1)
            {
                throw Logger.Error <DmnBuilderException>($"At least one rule must be defined for decision table {Name}");
            }

            //create
            var tableDecision = new DmnDecisionTable(
                Name,
                HitPolicy,
                Aggregation,
                InputsInternal.Select(i => i.GetResultOrBuild()).ToArray(),
                OutputsInternal.Select(o => o.GetResultOrBuild()).ToArray(),
                RulesInternal.Select(r => r.GetResultOrBuild()).ToArray(),
                RequiredInputs.Select(i => Variables[i].GetResultOrBuild()).ToArray(),
                RequiredDecisions.Select(d => Decisions[d].GetResultOrBuild()).ToArray());

            ResultInternal = tableDecision;
            return(tableDecision);
        }
Example #2
0
        /// <summary>
        /// Builds the expression decision definition
        /// </summary>
        /// <returns>Decision definition built</returns>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the expression or output variable is not defined in builder</exception>
        protected internal override IDmnDecision Build()
        {
            if (IsBuilt)
            {
                throw Logger.Error <DmnBuilderException>("Decision is already built");
            }

            if (OutputVariableInternal == null)
            {
                throw Logger.Error <DmnBuilderException>($"Missing output variable for expression decision {Name}");
            }

            if (string.IsNullOrWhiteSpace(Expression))
            {
                throw Logger.Error <DmnBuilderException>($"Missing expression for expression decision {Name}");
            }

            //create
            var expressionDecision = new DmnExpressionDecision(
                Name,
                Expression,
                OutputVariableInternal.GetResultOrBuild(),
                RequiredInputs.Select(i => Variables[i].GetResultOrBuild()).ToArray(),
                RequiredDecisions.Select(d => Decisions[d].GetResultOrBuild()).ToArray());

            ResultInternal = expressionDecision;
            return(expressionDecision);
        }
 protected override IDmnDecision Build()
 {
     return(new DmnLogicalAndDecision(
                Name,
                GetResultOrBuild(Variables[Input1Var]),
                GetResultOrBuild(Variables[Input2Var]),
                Negate,
                GetResultOrBuild(Variables[OutputVar]),
                RequiredInputs.Select(i => GetResultOrBuild(Variables[i])).ToArray(),
                RequiredDecisions.Select(d => GetResultOrBuild(Decisions[d])).ToArray()));
 }