示例#1
0
        private Dictionary <string, RuleEngineItem> createRuleEngineItem(int alarmRuleCatalogId)
        {
            DBHelper._AlarmRuleItem dbhelperAlarmRuleItem = new DBHelper._AlarmRuleItem();
            var detailForRuleEngineModelList = dbhelperAlarmRuleItem.GetAllByAlarmRuleCatalogIdForRuleEngine(alarmRuleCatalogId);

            Dictionary <string, RuleEngineItem> ruleEngineItems = new Dictionary <string, RuleEngineItem>();

            int index = 0;

            foreach (var detailForRuleEngineModel in detailForRuleEngineModelList)
            {
                RuleEngineItem rei = new RuleEngineItem();
                rei.ElementName    = detailForRuleEngineModel.MessageElementFullName;
                rei.DataType       = AlarmRuleItemEngineUtility.GetSupportDataType(detailForRuleEngineModel.MessageElementDataType);
                rei.OrderOperation = detailForRuleEngineModel.BitWiseOperation;
                rei.Result         = false;

                ConsoleLog.WriteMessageAlarmLogToConsole("--ElementName={0}, BitWiseOperation={1}", rei.ElementName, rei.OrderOperation);

                if (rei.DataType == SupportDataTypeEnum.String &&
                    (string.IsNullOrEmpty(detailForRuleEngineModel.Value) || detailForRuleEngineModel.Value.ToLower().Equals("null")))
                {
                    detailForRuleEngineModel.Value = "null";
                }

                if (rei.DataType == SupportDataTypeEnum.Numeric || rei.DataType == SupportDataTypeEnum.Bool)
                {
                    rei.Equality = createCompiledRuleFunc(rei.DataType, detailForRuleEngineModel.EqualOperation, detailForRuleEngineModel.Value);
                }
                else
                {
                    // SupportDataTypeEnum.String
                    rei.Equality         = null;
                    rei.StringRightValue = detailForRuleEngineModel.Value;

                    if (detailForRuleEngineModel.EqualOperation.Equals("=") || detailForRuleEngineModel.EqualOperation.Equals("!="))
                    {
                        rei.StringEqualOperation = detailForRuleEngineModel.EqualOperation;
                    }
                    else
                    {
                        throw new ArgumentNullException("String equal operation is not supported - " + detailForRuleEngineModel.EqualOperation);
                    }

                    ConsoleLog.WriteMessageAlarmLogToConsole("----ruleText=({0} {1} {2})", rei.ElementName, detailForRuleEngineModel.EqualOperation, rei.StringRightValue);
                }

                // Add the index to avoid the duplicate key
                ruleEngineItems.Add(rei.ElementName + "-" + index, rei);
                index++;
            }

            return(ruleEngineItems);
        }
示例#2
0
 public IHttpActionResult test(int alarmRuleCatalogId)
 {
     DBHelper._AlarmRuleItem model = new DBHelper._AlarmRuleItem();
     return(Ok(model.GetAllByAlarmRuleCatalogIdForRuleEngine(alarmRuleCatalogId)));
 }