Ejemplo n.º 1
0
 public void VerifyRule(IRuleRequest ruleRequest = null)
 {
     foreach (var action in RulesInContainer(ruleRequest))
     {
         action.VerifyRule(ruleRequest);
     }
 }
Ejemplo n.º 2
0
        public override void VerifyRule(IRuleRequest request = null)
        {
            base.VerifyRule(request);
            if (!StorageMechanism.Items.Any())
            {
                Logger("INFO", $"Cache empty for {RuleSetName}");
                return;
            }
            if (AggregateRule == null)
            {
                Logger("ERROR", $"Aggregate rule for {RuleSetName} is empty");
                return;
            }

            var filtered = AggregateFilter != null
                ? AggregateFilter.Compile().Invoke(StorageMechanism.Items, RuleRequest)
                : StorageMechanism.Items;

            var invalid = AggregateRule.Compile().Invoke(filtered);

            if (!invalid)
            {
                return;
            }
            FailRule();
        }
Ejemplo n.º 3
0
        public virtual void VerifyRule(IRuleRequest request = null)
        {
            if (request == null)
            {
                request = Activator.CreateInstance <T>();
            }
            else
            {
                RecordRequest(request);
            }

            RuleRequest = (T)request;
        }
Ejemplo n.º 4
0
        public RuleContainer(IRuleRequest request)
        {
            var rules = new List <IRuleContainer>();

            foreach (var _rule in request.Rules)
            {
                rules.Add(new RuleContainer(_rule));
            }

            Operand = request.Operand;
            Negate  = request.Negate;
            Request = request;
            Rules   = rules;
        }
Ejemplo n.º 5
0
        protected IEnumerable <IRuleRunner> RulesInContainer(IRuleRequest ruleRequest)
        {
            if (ruleRequest == null)
            {
                return(null);
            }
            var found = Rules.Where(x => x.Key == ruleRequest.GetType());

            var result = found
                         .Select(z => z.Value)
                         .Cast <IRuleRunner>();

            return(result);
        }
Ejemplo n.º 6
0
 private static void EnsureCreated <T>(Action <T> setter = null) where T : IRuleRequest, new()
 {
     if (_rule == null)
     {
         _rule = Activator.CreateInstance <TRuleSetHandler>();
     }
     if (_request == null)
     {
         _request = Activator.CreateInstance <T>();
     }
     if (setter != null)
     {
         setter((T)_request);
     }
 }
Ejemplo n.º 7
0
        protected void RecordRequest(IRuleRequest request)
        {
            Logger("DEBUG", "RecordRequest: " + request.Id);
            if (!UpdateRuleCollectionOnSuccess)
            {
                return;
            }
            var item    = (T)request;
            var storage = StorageMechanism.Items.ToList();

            if (!storage.Contains(item))
            {
                storage.Add(item);
            }
            _storageMechanism.Items = storage.AsQueryable();
        }
Ejemplo n.º 8
0
        public void Run(IRuleRequest item, bool addRequestToItemsCollection = true)
        {
            _ruleRequest = (T)item;
            if (addRequestToItemsCollection)
            {
                StorageMechanism().Add((T)item);
                _logger("INFO", "Added item to collection. Count = " + StorageMechanism().Count);
            }

            _logger("DEBUG", "Verify Maximum Count Rule");
            VerifyMaximumCount();
            _logger("DEBUG", "Verify Single Rule");
            VerifySingleRule();
            _logger("DEBUG", "Verify Aggregate Rule");
            VerifyAggregateRule();

            _logger("INFO", "Request passed rule : " + RuleType.Name);
        }
        public override void VerifyRule(IRuleRequest request = null)
        {
            base.VerifyRule(request);
            if (StorageMechanism == null || !StorageMechanism.Items.Any())
            {
                return;
            }
            long count   = StorageMechanism.Items.LongCount();
            bool invalid = MaximumResultCount.HasValue && count >= MaximumResultCount;

            if (!invalid)
            {
                return;
            }
            string log = string.Format("Maximum Count excedeed.. Maximum items allowed count : {0}  total found: {1}",
                                       MaximumResultCount, count);

            FailRule(log);
        }
Ejemplo n.º 10
0
        public override void VerifyRule(IRuleRequest request = null)
        {
            base.VerifyRule(request);
            if (!StorageMechanism.Items.Any())
            {
                return;
            }

            if (Rule != null)
            {
                var invalid = StorageMechanism.Items
                              .AsQueryable()
                              .Cast <T>()
                              .Where(Rule);

                if (!invalid.Any())
                {
                    return;
                }
                FailRule();
            }
        }