Example #1
0
        protected virtual void ConvertRule(RuleEntity entity, RuleExpression expression)
        {
            Guard.NotNull(entity, nameof(entity));
            Guard.NotNull(expression, nameof(expression));

            var descriptor = RuleDescriptors.FindDescriptor(entity.RuleType);

            if (descriptor == null)
            {
                // A descriptor for this entity data does not exist. Allow deletion of it.
                descriptor = new InvalidRuleDescriptor(Scope)
                {
                    Name        = entity.RuleType,
                    DisplayName = entity.RuleType
                };
            }
            else if (descriptor.Scope != Scope)
            {
                throw new SmartException($"Differing rule scope {descriptor.Scope}. Expected {Scope}.");
            }

            expression.Id         = entity.Id;
            expression.RuleSetId  = entity.RuleSetId;
            expression.Descriptor = descriptor;
            expression.Operator   = entity.Operator;
            expression.RawValue   = entity.Value;
            expression.Value      = entity.Value.Convert(descriptor.RuleType.ClrType);
        }
Example #2
0
        private async Task <IRuleExpression> CreateExpression(RuleEntity ruleEntity, IRuleVisitor visitor)
        {
            if (!ruleEntity.IsGroup)
            {
                return(await visitor.VisitRuleAsync(ruleEntity));
            }

            // It's a group, do recursive call.
            var group = await CreateExpressionGroupAsync(ruleEntity.Value.Convert <int>(), visitor);

            if (group != null)
            {
                group.RefRuleId = ruleEntity.Id;
            }

            return(group);
        }
Example #3
0
 public abstract IRuleExpression VisitRule(RuleEntity rule);
Example #4
0
 public abstract Task <IRuleExpression> VisitRuleAsync(RuleEntity rule);
Example #5
0
        private async Task <IRuleExpressionGroup> CreateExpressionGroup(RuleSetEntity ruleSet, RuleEntity refRule, IRuleVisitor visitor)
        {
            if (ruleSet.Scope != visitor.Scope)
            {
                // TODO: ErrHandling (ruleSet is for a different scope)
                return(null);
            }

            var group = visitor.VisitRuleSet(ruleSet);

            if (refRule != null)
            {
                group.RefRuleId = refRule.Id;
            }

            var expressions = await ruleSet.Rules
                              .SelectAsync(x => CreateExpression(x, visitor))
                              .Where(x => x != null)
                              .AsyncToArray();

            group.AddExpressions(expressions);

            return(group);
        }