Exemplo n.º 1
0
        /// <summary>
        /// Begin site method - call prior to getParameters
        /// </summary>
        /// <param name="caller">Calling class object</param>
        /// <param name="siteId">SiteId specifier object</param>
        /// <param name="ruleIds">List of Business rule strings</param>
        /// <param name="rules">List of BusinessRuleVO objects - Output param</param>
        /// <returns>PawnRulesSystemReturnCode</returns>
        public PawnRulesSystemReturnCode beginSite(object caller, SiteId siteId, List <string> ruleIds, out Dictionary <string, BusinessRuleVO> rules)
        {
            rules = new Dictionary <string, BusinessRuleVO>();

            //Validate input
            if (caller == null || CollectionUtilities.isEmpty(ruleIds))
            {
                return
                    (new PawnRulesSystemReturnCode(
                         PawnRulesSystemReturnCode.Code.ERROR,
                         "Input values to beginSite are invalid."));
            }
            //Check if this object is already using the pawn rules system
            if (this.beginBlockRegistry.ContainsKey(caller))
            {
                PairType <SiteId, bool> curSiteBegin = this.beginBlockRegistry[caller];
                if (curSiteBegin.Right)
                {
                    return
                        (new PawnRulesSystemReturnCode(
                             PawnRulesSystemReturnCode.Code.WARNING,
                             "Already in an active begin block for this site and this caller parent object."));
                }
                curSiteBegin.Right = true;
                curSiteBegin.Left  = siteId;
            }
            else
            {
                this.beginBlockRegistry.Add(caller, new PairType <SiteId, bool>(siteId, true));
            }

            //Set site id
            this.currentSite = siteId;
            //Change last parameter to true if you want to save the rules file to the disk after it is loaded
            //into the rules engine data structure
            //rules = RulesHelper.BuildBusinessRules(siteId, true);
            rules = RulesHelper.BuildBusinessRules(siteId);

            return(new PawnRulesSystemReturnCode(PawnRulesSystemReturnCode.Code.SUCCESS));
        }