Пример #1
0
        public RuleExecutionResponse ExecuteRuleAsync(IRuleContext context)
        {
            var pointContext = (PointRuleContext) context;

            double actual = (double) pointContext.CurrentValue;
            double threshold = pointContext.HighWarningValue;

            var rule = RuleFactory.First(r => r.GetType() == typeof(DoubleGreaterThanRuleFactory)).Make(threshold);

            var ruleEngine = _engineFactory.Make(actual);
            ruleEngine.Add(rule);

            var result = new RuleExecutionResponse();
            // TODO: Interpret the result and update the RuleExecutionResponse enum
            if (ruleEngine.MatchAny())
            {
                result.CurrentState = CurrentStateType.AnalogHighWarning;
            }

            return result;
        }
Пример #2
0
        public RuleExecutionResponse ExecuteRuleAsync(IRuleContext context)
        {
            var pointContext = (PointRuleContext)context;
            var result = new RuleExecutionResponse { CurrentState = CurrentStateType.Normal };

            int actual = Convert.ToInt32(context.CurrentValue);
            int previous = Convert.ToInt32(pointContext.LastValue);

            var rule = RuleFactory.First(r => r.GetType() == typeof (IntegerEqualToRuleFactory)).Make(Convert.ToInt32(context.BooleanAlarmState));

            var ruleEngine = _engineFactory.Make(actual);
            ruleEngine.Add(rule);

            if (!ruleEngine.MatchAny())
            {
                // Values were different...now determine whether it was into alarm or out of alarm
                result.CurrentState = previous > actual ? CurrentStateType.DigitalOutOfAlarmTransition : CurrentStateType.DigitalIntoAlarmTransition;

                // TODO: Update the actor with alarm state
            }

            return result;
        }