/// <summary>
        /// Adds the required input reference to the decision.
        /// </summary>
        /// <remarks>Required inputs represents the "link" between input and decision in a model.
        /// Technically, the input requirements (existence of the input) are not checked during the execution,
        /// it's more for better understanding the DMN model</remarks>
        /// <param name="input">Reference to the input variable</param>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
        protected void AddRequiredInput(Variable.Ref input)
        {
            if (IsBuilt)
            {
                throw Logger.Error <DmnBuilderException>("Decision is already built");
            }
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (!input.IsInputParameter)
            {
                throw Logger.Error <DmnBuilderException>($"Variable {input.Name} is not an input parameter");
            }

            if (Variables[input] == null)
            {
                throw Logger.Error <DmnBuilderException>($"Can't get the variable from reference {input.Name}");
            }

            if (!RequiredInputs.Contains(input))
            {
                RequiredInputs.Add(input);
            }
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
0
        public StandCombo(string Name, params ComboInput[] inputs)
        {
            ComboName = Name;

            foreach (ComboInput i in inputs)
            {
                RequiredInputs.Add(i);
            }
        }
 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()));
 }