Ejemplo n.º 1
0
        public void Execute(IRuleEnvironment environment)
        {
            var result = environment.GetFact <RuleResult>("result");

            if (!result.Allow)
            {
                return;
            }
            TokenInfo tokenInfo = environment.GetFact <TokenInfo>("tokenInfo");

            if (tokenInfo.NoOfTimesCalledInLastHour >= hitLimit)
            {
                result.Allow   = false;
                result.Message = "X requests per hour reached.";
            }
        }
Ejemplo n.º 2
0
        public void Execute(IRuleEnvironment environment)
        {
            var result = environment.GetFact <RuleResult>("result");

            if (!result.Allow)
            {
                return;
            }
            TokenInfo tokenInfo = environment.GetFact <TokenInfo>("tokenInfo");

            if (tokenInfo.Location.ToLower() != "us")
            {
                result.Allow   = false;
                result.Message = "Requests not from US.";
            }
        }
Ejemplo n.º 3
0
        public void Execute(IRuleEnvironment environment)
        {
            var result = environment.GetFact <RuleResult>("result");

            if (!result.Allow)
            {
                return;
            }

            TokenInfo tokenInfo = environment.GetFact <TokenInfo>("tokenInfo");

            if (DateTime.Now < tokenInfo.LastRequestTime.Add(WaitTime))
            {
                result.Allow   = false;
                result.Message = $"A certain timespan {WaitTime} should pass since last call.";
            }
        }