Ejemplo n.º 1
0
        private Func <DynamicMessageElement, bool> createCompiledRuleFunc(SupportDataTypeEnum supportedDataType, string op, string right)
        {
            EqualityRule rule;

            switch (supportedDataType)
            {
            case SupportDataTypeEnum.Bool:
                rule = new EqualityRule("StringValue", AlarmRuleItemEngineUtility.GetEqualityOperation(op), right.ToLower());
                break;

            case SupportDataTypeEnum.Numeric:
                decimal rightValue = Decimal.Parse(right);
                if (rightValue >= 0)
                {
                    rule = new EqualityRule("DecimalValue", AlarmRuleItemEngineUtility.GetEqualityOperation(op), right);
                }
                else
                {
                    rule = new EqualityRule("DecimalValue", AlarmRuleItemEngineUtility.GetEqualityOperation(op), "0-" + Decimal.Negate(rightValue).ToString());
                }
                break;

            case SupportDataTypeEnum.String:
                rule = new EqualityRule("StringValue", AlarmRuleItemEngineUtility.GetEqualityOperation(op), right);
                break;

            default:
                throw new NotSupportedException();
            }

            RuleBase rb = null;

            using (var mem = new MemoryStream())
            {
                Serializer.Serialize(mem, rule);
                mem.Position = 0;
                rb           = Serializer.Deserialize <RuleBase>(mem);
            }

            string ruleText;
            Func <DynamicMessageElement, bool> compiledRule = rb.CompileRule <DynamicMessageElement>(out ruleText);

            //_consoleLog.MessageAlarmDebug("----ruleText={0}", ruleText);
            //_consoleLog.MessageAlarmDebug("----ruleText="+ruleText);

            return(compiledRule);
        }
Ejemplo n.º 2
0
        private Func <DynamicMessageElement, bool> createCompiledRuleFunc(SupportDataTypeEnum isDecimalType, string op, string right)
        {
            EqualityRule rule;

            switch (isDecimalType)
            {
            case SupportDataTypeEnum.Bool:
                rule = new EqualityRule("StringValue", AlarmRuleItemEngineUtility.GetEqualityOperation(op), right.ToLower());
                break;

            case SupportDataTypeEnum.Numeric:
                rule = new EqualityRule("DecimalValue", AlarmRuleItemEngineUtility.GetEqualityOperation(op), right);
                break;

            case SupportDataTypeEnum.String:
                rule = new EqualityRule("StringValue", AlarmRuleItemEngineUtility.GetEqualityOperation(op), right);
                break;

            default:
                throw new NotSupportedException();
            }

            RuleBase rb = null;

            using (var mem = new MemoryStream())
            {
                Serializer.Serialize(mem, rule);
                mem.Position = 0;
                rb           = Serializer.Deserialize <RuleBase>(mem);
            }

            string ruleText;
            Func <DynamicMessageElement, bool> compiledRule = rb.CompileRule <DynamicMessageElement>(out ruleText);

            ConsoleLog.WriteMessageAlarmLogToConsole("----ruleText={0}", ruleText);

            return(compiledRule);
        }