Esempio n. 1
0
        /// <summary>
        /// Adds do nothing rule to each rule set and rule layer
        /// </summary>
        /// <returns>Returns created rule ids</returns>
        public IEnumerable <string> AddDoNothingRules()
        {
            List <string> temp = new List <string>();

            MentalProto.ForEach(set =>
            {
                //only for layers with UseDoNothing: true configuration
                set.Layers.Where(layer => layer.LayerConfiguration.UseDoNothing).ForEach(layer =>
                {
                    if (!layer.Rules.Any(r => r.IsAction == false))
                    {
                        Rule proto = layer.Rules.First();

                        Rule doNothing = Rule.Create(
                            new RuleAntecedentPart[] { new RuleAntecedentPart(VariablesUsedInCode.IsActive, "==", true) },
                            RuleConsequent.Renew(proto.Consequent, Activator.CreateInstance(proto.Consequent.Value.GetType())),
                            false, false, 1, true
                            );

                        AddNewRule(doNothing, layer);

                        temp.Add(doNothing.Id);
                    }
                });
            });

            return(temp);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates rule copy but replaces antecedent parts and consequent by new values.
        /// </summary>
        /// <param name="old"></param>
        /// <param name="newValue"></param>
        /// <returns></returns>
        public static Rule Renew(Rule old, RuleAntecedentPart[] newAntecedent, RuleConsequent newConsequent)
        {
            Rule newRule = old.Clone();

            newRule.Antecedent = newAntecedent;
            newRule.Consequent = newConsequent;

            return(newRule);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates new rule with passed parameters
        /// </summary>
        /// <param name="antecedent"></param>
        /// <param name="consequent"></param>
        /// <returns></returns>
        public static Rule Create(RuleAntecedentPart[] antecedent, RuleConsequent consequent, bool isAction, bool isModifable, int requiredParticipants, bool autoGenerated = false)
        {
            Rule newRule = new Rule();

            newRule.Antecedent           = antecedent;
            newRule.Consequent           = consequent;
            newRule.IsAction             = isAction;
            newRule.IsModifiable         = isModifable;
            newRule.RequiredParticipants = requiredParticipants;
            newRule.AutoGenerated        = autoGenerated;

            return(newRule);
        }