private bool testSingleRuleStringItem(string left, string op, string right) { string elementName = "elementName"; JObject testObject = new JObject(); testObject.Add(elementName, left); SupportDataTypeEnum testDataType = SupportDataTypeEnum.String; return(runSingleRuleItem(testDataType, elementName, op, right, testObject)); }
private bool testSingleRuleNumericItem(decimal left, string op, decimal right) { string elementName = "elementName"; JObject testObject = new JObject(); testObject.Add(elementName, left); SupportDataTypeEnum testDataType = SupportDataTypeEnum.Numeric; return(runSingleRuleItem(testDataType, elementName, op, right.ToString(), testObject)); }
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); }
private bool runSingleRuleItem(SupportDataTypeEnum testDataType, string elementName, string op, string right, JObject testObject) { MessageProcessorFactoryModel msgProcessorFactoryModel = new MessageProcessorFactoryModel(); IoTHubAliasEventMessageReceiver receiver = new IoTHubAliasEventMessageReceiver("test"); Func <DynamicMessageElement, bool> func = receiver.CreateCompiledRuleFuncTest(testDataType, op, right); SfMessageEventProcessor sfMsgEventProcessor = new SfMessageEventProcessor(msgProcessorFactoryModel); RuleEngineItem ruleEngineItem = new RuleEngineItem { ElementName = elementName, DataType = testDataType, OrderOperation = "end", Result = false, Equality = func }; sfMsgEventProcessor.RunSingleRuleItemTest(ruleEngineItem, testObject); return(ruleEngineItem.Result); }
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); }
public Func <DynamicMessageElement, bool> CreateCompiledRuleFuncTest(SupportDataTypeEnum isDecimalType, string op, string right) { return(createCompiledRuleFunc(isDecimalType, op, right)); }