コード例 #1
0
ファイル: DomainRule.cs プロジェクト: geffzhang/Wonka
        public WonkaBizRuleValueProps GetDomainValueProps(string psValue)
        {
            WonkaBizRuleValueProps oValueProps = null;

            if (!String.IsNullOrEmpty(psValue) && DomainValueProps.ContainsKey(psValue))
            {
                oValueProps = DomainValueProps[psValue];
            }

            return(oValueProps);
        }
コード例 #2
0
ファイル: DomainRule.cs プロジェクト: geffzhang/Wonka
        /// <summary>
        ///
        /// This method allows the caller to add a domain value to the set, whether it's a literal value or
        /// a referenced Attribute in the Transactional record.
        ///
        /// <param name="psDomainVal">The value to add to the set</param>
        /// <param name="pbIsLiteral">The indicator for whether the value is literal (i.e., '5') or an Attribute name (i.e., 'PubPrice')</param>
        /// <param name="peTargetRecord">The record with the Attribute value that we will add to the set (if the domain value is not literal)</param>
        /// <returns>None.</returns>
        /// </summary>
        public void AddDomainValue(string psDomainVal, bool pbIsLiteral, TARGET_RECORD peTargetRecord)
        {
            WonkaBizRuleValueProps oValueProps =
                new WonkaBizRuleValueProps()
            {
                IsLiteralValue = pbIsLiteral
            };

            if (pbIsLiteral)
            {
                /*
                 * NOTE: This is a bit of a hack...but since we must use commas and parantheses to separate the domain values,
                 *       we will require that any rule value with certain embeddeded delimiters use HTML chars instead, so that
                 *       the value will be replaced with the correct equivalent here.  My apologies.
                 */
                if (!string.IsNullOrEmpty(psDomainVal) && psDomainVal.Contains("&#44;"))
                {
                    psDomainVal = psDomainVal.Replace("&#44;", ",");
                }

                if (!string.IsNullOrEmpty(psDomainVal) && psDomainVal.Contains("&#40;"))
                {
                    psDomainVal = psDomainVal.Replace("&#40;", "(");
                }

                if (!string.IsNullOrEmpty(psDomainVal) && psDomainVal.Contains("&#41;"))
                {
                    psDomainVal = psDomainVal.Replace("&#41;", ")");
                }

                DomainCache.Add(psDomainVal);
            }
            else
            {
                oValueProps.TargetRecord = peTargetRecord;

                oValueProps.AttributeInfo =
                    WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(psDomainVal);

                HasAttrIdTargets = true;
            }

            DomainValueProps[psDomainVal] = oValueProps;
        }
コード例 #3
0
        /// <summary>
        ///
        /// This method allows the caller to add a domain value to the set, whether it's a literal value or
        /// a referenced Attribute in the Transactional record.
        ///
        /// <param name="psDomainVal">The value to add to the set</param>
        /// <param name="pbIsLiteral">The indicator for whether the value is literal (i.e., '5') or an Attribute name (i.e., 'PubPrice')</param>
        /// <param name="peTargetRecord">The record with the Attribute value that we will add to the set (if the domain value is not literal)</param>
        /// <returns>None.</returns>
        /// </summary>
        public void AddDomainValue(string psDomainVal, bool pbIsLiteral, TARGET_RECORD peTargetRecord)
        {
            WonkaBizRuleValueProps oValueProps =
                new WonkaBizRuleValueProps()
            {
                IsLiteralValue = pbIsLiteral
            };

            if (pbIsLiteral)
            {
                /*
                 * NOTE: This is a bit of a hack...but since we must use commas to separate the domain values, we will require
                 *       that any rule value with an embedded comma must use "&#44;", and that value will be replaced with an
                 *       actual comma here.  My apologies.
                 */
                if (!string.IsNullOrEmpty(psDomainVal) && psDomainVal.Contains("&#44;"))
                {
                    psDomainVal = psDomainVal.Replace("&#44;", ",");
                }

                DomainCache.Add(psDomainVal);
            }
            else
            {
                oValueProps.TargetRecord = peTargetRecord;

                oValueProps.AttributeInfo =
                    WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(psDomainVal);

                HasAttrIdTargets = true;
            }

            CustomOpPropArgs.Add(psDomainVal);

            DomainValueProps[psDomainVal] = oValueProps;
        }
コード例 #4
0
        /// <summary>
        ///
        /// This method allows the caller to add a value to the set for the arithmetic operation, whether it's a literal value or
        /// a referenced Attribute in the Transactional record.
        ///
        /// <param name="psDomainVal">The value to add to the set</param>
        /// <param name="pbIsLiteral">The indicator for whether the value is literal (i.e., '5') or an Attribute name (i.e., 'PubPrice')</param>
        /// <param name="peTargetRecord">The record with the Attribute value that we will add to the set (if the domain value is not literal)</param>
        /// <returns>None.</returns>
        /// </summary>
        public void AddDomainValue(string psDomainVal, bool pbIsLiteral, TARGET_RECORD peTargetRecord)
        {
            WonkaBizRuleValueProps oValueProps =
                new WonkaBizRuleValueProps()
            {
                IsLiteralValue = pbIsLiteral
            };

            if (pbIsLiteral)
            {
                DomainCache.Add(psDomainVal);
            }
            else
            {
                oValueProps.TargetRecord = peTargetRecord;

                oValueProps.AttributeInfo =
                    WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(psDomainVal);

                HasAttrIdTargets = true;
            }

            DomainValueProps[psDomainVal] = oValueProps;
        }
コード例 #5
0
ファイル: DomainRule.cs プロジェクト: geffzhang/Wonka
        /// <summary>
        ///
        /// This method will refresh the set of data if there are any mentioned Attributes.
        ///
        /// <param name="poNewProduct">The incoming Product whose Attributes might be used to populate the Set</param>
        /// <param name="poOldProduct">The current Product whose Attributes might be used to populate the Set</param>
        /// <param name="poDomainCache">Our domain cache that will be refreshed</param>
        /// <returns>Indicator of whether the set was refreshed successfully</returns>
        /// </summary>
        public bool RefreshCache(WonkaProduct poNewProduct, WonkaProduct poOldProduct, HashSet <string> poDomainCache)
        {
            bool bResult  = true;
            int  nAttrId  = 0;
            int  nGroupId = 0;

            WonkaBizRuleValueProps RuleValueProps = null;

            if (HasAttrIdTargets)
            {
                if (poNewProduct == null)
                {
                    throw new Exception("ERROR!  The new Product is null.");
                }

                if (poNewProduct == null)
                {
                    throw new Exception("ERROR!  The old Product is null.");
                }

                if (poDomainCache == null)
                {
                    throw new Exception("ERROR!  The provided Domain Cache is null.");
                }

                poDomainCache.Clear();
                foreach (string sDomainValue in DomainValueProps.Keys)
                {
                    RuleValueProps = DomainValueProps[sDomainValue];

                    if (RuleValueProps.IsLiteralValue)
                    {
                        poDomainCache.Add(sDomainValue);
                    }
                    else
                    {
                        nAttrId  = RuleValueProps.AttributeInfo.AttrId;
                        nGroupId = RuleValueProps.AttributeInfo.GroupId;

                        WonkaPrdGroup TempProductGroup = null;

                        if (RuleValueProps.TargetRecord == TARGET_RECORD.TRID_NEW_RECORD)
                        {
                            TempProductGroup = poNewProduct.GetProductGroup(nGroupId);
                        }
                        else
                        {
                            TempProductGroup = poOldProduct.GetProductGroup(nGroupId);
                        }

                        foreach (WonkaPrdGroupDataRow TempDataRow in TempProductGroup)
                        {
                            if (TempDataRow.Keys.Contains(nAttrId))
                            {
                                poDomainCache.Add(TempDataRow[nAttrId]);
                            }
                        }
                    }
                }
            }

            return(bResult);
        }
コード例 #6
0
        /// <summary>
        ///
        /// This method will use the provided values to set the min and max of this rule.  More importantly,
        /// it will assist with the initialization of the rule by interpreting the provided values
        /// to detect which values are literal and which of them are Attribute names (which
        /// will be used to dynamically update the value(s) on every processed pair of records).
        ///
        /// <param name="psRuleExpression">The date rule in verbose form</param>
        /// <param name="paValueSet">The value(s) that will determine the min and max</param>
        /// <returns>None</returns>
        /// </summary>
        public void SetMinAndMax(string psRuleExpression, string[] paValueSet)
        {
            if (paValueSet.Count() > 0)
            {
                // NOTE: Currently, if more than one value has been provided, we will only
                //       take the first value into account
                bool   bLiteralValue = false;
                string sTempValue    = paValueSet[0];

                DateTime DateTimeValue = DateTime.Now;
                WonkaBizRuleValueProps AttributeValueProps = new WonkaBizRuleValueProps()
                {
                    IsLiteralValue = false
                };

                try
                {
                    DateTimeValue = DateTime.ParseExact(sTempValue, CONST_WONKA_DATETIME_FORMAT, null);
                    bLiteralValue = true;
                }
                catch (Exception ex)
                {
                    if (sTempValue == CONST_CURRENT_DATETIME_IND)
                    {
                        DateTimeValue = DateTime.Now;
                        bLiteralValue = true;

                        this.TodayIndicator = true;
                    }
                    else
                    {
                        AttributeValueProps = this.GetAttributeValueProps(sTempValue);
                    }
                }

                if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_DL_IB) ||
                    psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_DL_NOT_IB))
                {
                    this.MinValue = DateTime.MinValue;
                    this.MaxValue = DateTimeValue;

                    if (!bLiteralValue)
                    {
                        this.MaxValueProps = AttributeValueProps;
                    }

                    if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_DL_NOT_IB))
                    {
                        this.NotOperator = true;
                    }
                }
                else if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_DL_IA) ||
                         psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_DL_NOT_IA))
                {
                    this.MinValue = DateTimeValue;
                    this.MaxValue = DateTime.MaxValue;

                    if (!bLiteralValue)
                    {
                        this.MinValueProps = AttributeValueProps;
                    }

                    if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_DL_NOT_IA))
                    {
                        this.NotOperator = true;
                    }
                }
                else if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_DL_ALMOST))
                {
                    if (!this.TodayIndicator)
                    {
                        throw new Exception("ERROR!  Cannot use ALMOST operator without using the TODAY keyword.");
                    }

                    System.TimeSpan WindowSpan = new System.TimeSpan(1, 0, 0, 0);

                    this.MinValue = DateTimeValue;
                    this.MaxValue = DateTimeValue.Add(WindowSpan);

                    this.AlmostOperator = true;
                }

                /*
                 * NOTE: Will be implemented later, with a defined plan
                 * else if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_AROUND))
                 * {
                 *  System.TimeSpan WindowSpan = new System.TimeSpan(0, 12, 0, 0);
                 *
                 *  this.MinValue = DateTimeValue.Subtract(WindowSpan);
                 *  this.MaxValue = DateTimeValue.Add(WindowSpan);
                 *
                 *  this.AroundOperator = true;
                 * }
                 */
            }
        }
コード例 #7
0
        /// <summary>
        ///
        /// This method will use the provided values to set the min and max of this rule.  More importantly,
        /// it will assist with the initialization of the rule by interpreting the provided values
        /// to detect which values are literal and which of them are Attribute names (which
        /// will be used to dynamically update the value(s) on every processed pair of records).
        ///
        /// <param name="psRuleExpression">The arithmetic rule in verbose form</param>
        /// <param name="paValueSet">The value(s) that will determine the min and max</param>
        /// <returns>None</returns>
        /// </summary>
        public void SetMinAndMax(string psRuleExpression, string[] paValueSet)
        {
            if (paValueSet.Count() > 0)
            {
                // NOTE: Currently, if more than one value has been provided, we will only
                //       take the first value into account
                bool   bLiteralValue = false;
                double dValue        = 0.0;
                string sTempValue    = paValueSet[0];

                WonkaBizRuleValueProps AttributeValueProps = new WonkaBizRuleValueProps();

                try
                {
                    dValue        = Convert.ToDouble(sTempValue);
                    bLiteralValue = true;
                }
                catch (Exception ex)
                {
                    dValue = 0.0;

                    if (sTempValue == CONST_BLOCKNUM_IND)
                    {
                        bLiteralValue = true;

                        this.BlockNumOperator = true;
                    }
                    else
                    {
                        AttributeValueProps = this.GetAttributeValueProps(sTempValue);
                    }
                }

                if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_LT) ||
                    psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_LT))
                {
                    this.MinValue = Double.MinValue;
                    this.MaxValue = dValue - 0.001;

                    if (!bLiteralValue)
                    {
                        this.MaxValueProps = AttributeValueProps;
                    }

                    if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_LT))
                    {
                        this.NotOperator = true;
                    }
                }
                else if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_GT) ||
                         psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_GT))
                {
                    this.MinValue = dValue + 0.001;
                    this.MaxValue = Double.MaxValue;

                    if (!bLiteralValue)
                    {
                        this.MinValueProps = AttributeValueProps;
                    }

                    if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_GT))
                    {
                        this.NotOperator = true;
                    }
                }
                else if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_LE) ||
                         psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_LE))
                {
                    this.MinValue = Double.MinValue;
                    this.MaxValue = dValue;

                    if (!bLiteralValue)
                    {
                        this.MaxValueProps = AttributeValueProps;
                    }

                    if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_LE))
                    {
                        this.NotOperator = true;
                    }
                }
                else if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_GE) ||
                         psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_GE))
                {
                    this.MinValue = dValue;
                    this.MaxValue = Double.MaxValue;

                    if (!bLiteralValue)
                    {
                        this.MinValueProps = AttributeValueProps;
                    }

                    if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_GE))
                    {
                        this.NotOperator = true;
                    }
                }
                else if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_EQ) ||
                         psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_EQ))
                {
                    this.MinValue = dValue;
                    this.MaxValue = dValue;

                    if (!bLiteralValue)
                    {
                        this.MinValueProps = AttributeValueProps;
                        this.MaxValueProps = AttributeValueProps;
                    }

                    if (psRuleExpression.Contains(WonkaBizRulesXmlReader.CONST_AL_NOT_EQ))
                    {
                        this.NotOperator = true;
                    }
                }
            }
        }