Exemplo n.º 1
0
        public static WonkaBizRuleSet AddNewRuleSet(this WonkaBizRuleSet poRuleSet,
                                                    string psAddRuleSetDesc,
                                                    string psAddRuleSetTypeNum,
                                                    string psAddRuleSetErrorLvlNum)
        {
            int nRuleSetTypeNum   = Int32.Parse(psAddRuleSetTypeNum);
            int nRuleSetErrLvlNum = Int32.Parse(psAddRuleSetErrorLvlNum);

            WonkaBizRuleSet NewRuleSet = null;

            RULE_OP          rulesOp  = RULE_OP.OP_NONE;
            RULE_SET_ERR_LVL errLevel = RULE_SET_ERR_LVL.ERR_LVL_NONE;

            if (String.IsNullOrEmpty(psAddRuleSetDesc))
            {
                throw new DataException("ERROR!  Cannot add RuleSet without a description.");
            }

            if (nRuleSetTypeNum == 1)
            {
                rulesOp = RULE_OP.OP_AND;
            }
            else
            {
                rulesOp = RULE_OP.OP_OR;
            }

            if (nRuleSetErrLvlNum == 1)
            {
                errLevel = RULE_SET_ERR_LVL.ERR_LVL_WARNING;
            }
            else
            {
                errLevel = RULE_SET_ERR_LVL.ERR_LVL_SEVERE;
            }

            NewRuleSet = new WonkaBizRuleSet(mnRuleSetCounter++)
            {
                Description = psAddRuleSetDesc
            };

            NewRuleSet.RulesEvalOperator = rulesOp;
            NewRuleSet.ErrorSeverity     = errLevel;

            poRuleSet.AddChildRuleSet(NewRuleSet);

            return(NewRuleSet);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// This method provides a convenient way of taking RuleReports with failures (from certain failed RuleSets)
        /// and converting them into ProductError records (that can then be packaged into a XML message).
        ///
        /// <param name="psProductId">The Product ID of the current product that has just been evaluated in this RuleTreeReport</param>
        /// <param name="peRuleSetErrLvl">The sought error level of failed RuleSets</param>
        /// <returns>The RuleReport list repackaged as WonkaPrdProductErrors</returns>
        /// </summary>
        public List <WonkaProductError> GetProductErrors(string psProductId, RULE_SET_ERR_LVL peRuleSetErrLvl = RULE_SET_ERR_LVL.ERR_LVL_SEVERE)
        {
            List <WonkaBizRuleSetReportNode> RuleSetErrors    = new List <WonkaBizRuleSetReportNode>();
            List <WonkaProductError>         ProductErrorList = new List <WonkaProductError>();

            WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance();

            if (peRuleSetErrLvl == RULE_SET_ERR_LVL.ERR_LVL_WARNING)
            {
                RuleSetErrors = GetRuleSetWarningFailures();
            }
            else if (peRuleSetErrLvl == RULE_SET_ERR_LVL.ERR_LVL_SEVERE)
            {
                RuleSetErrors = GetRuleSetSevereFailures();
            }

            foreach (WonkaBizRuleSetReportNode RuleSetReport in RuleSetErrors)
            {
                foreach (WonkaBizRuleReportNode RuleReport in RuleSetReport.RuleResults)
                {
                    if (RuleReport.ErrorCode == ERR_CD.CD_FAILURE)
                    {
                        WonkaProductError ProductError = new WonkaProductError();

                        ProductError.ProductId = psProductId;
                        ProductError.AttrName  = WonkaRefEnv.GetAttributeByAttrId(RuleReport.TriggerAttrId).AttrName;

                        ProductError.ErrorMessage =
                            CONST_ERROR_MSG_PREFACE + RuleReport.VerboseError;

                        if (!string.IsNullOrEmpty(RuleSetReport.CustomId))
                        {
                            ProductError.ErrorMessage = "[" + RuleSetReport.CustomId + "] " + ProductError.ErrorMessage;
                        }

                        ProductErrorList.Add(ProductError);
                    }
                }
            }

            return(ProductErrorList);
        }