/// <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) { WonkaBreRuleValueProps oValueProps = new WonkaBreRuleValueProps() { 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 ",", and that value will be replaced with an * actual comma here. My apologies. */ if (!String.IsNullOrEmpty(psDomainVal) && psDomainVal.Contains(",")) { psDomainVal = psDomainVal.Replace(",", ","); } DomainCache.Add(psDomainVal); } else { oValueProps.TargetRecord = peTargetRecord; oValueProps.AttributeInfo = WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(psDomainVal); HasAttrIdTargets = true; } DomainValueProps[psDomainVal] = oValueProps; }
public WonkaBreRuleValueProps GetDomainValueProps(string psValue) { WonkaBreRuleValueProps oValueProps = null; if (!String.IsNullOrEmpty(psValue) && DomainValueProps.ContainsKey(psValue)) { oValueProps = DomainValueProps[psValue]; } return(oValueProps); }
/// <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) { WonkaBreRuleValueProps oValueProps = new WonkaBreRuleValueProps() { 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(",")) { psDomainVal = psDomainVal.Replace(",", ","); } if (!String.IsNullOrEmpty(psDomainVal) && psDomainVal.Contains("(")) { psDomainVal = psDomainVal.Replace("(", "("); } if (!String.IsNullOrEmpty(psDomainVal) && psDomainVal.Contains(")")) { psDomainVal = psDomainVal.Replace(")", ")"); } DomainCache.Add(psDomainVal); } else { oValueProps.TargetRecord = peTargetRecord; oValueProps.AttributeInfo = WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(psDomainVal); HasAttrIdTargets = true; } DomainValueProps[psDomainVal] = oValueProps; }
/// <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) { WonkaBreRuleValueProps oValueProps = new WonkaBreRuleValueProps() { IsLiteralValue = pbIsLiteral }; if (pbIsLiteral) { DomainCache.Add(psDomainVal); } else { oValueProps.TargetRecord = peTargetRecord; oValueProps.AttributeInfo = WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(psDomainVal); HasAttrIdTargets = true; } DomainValueProps[psDomainVal] = oValueProps; }
/// <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, List <string> poDomainCache) { bool bResult = true; int nAttrId = 0; int nGroupId = 0; WonkaBreRuleValueProps 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); }
/// <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]; WonkaBreRuleValueProps AttributeValueProps = new WonkaBreRuleValueProps(); try { dValue = Convert.ToDouble(sTempValue); bLiteralValue = true; } catch (Exception ex) { dValue = 0.0; AttributeValueProps = this.GetAttributeValueProps(sTempValue); } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_LT) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_LT)) { this.MinValue = -999999.0; this.MaxValue = dValue - 0.001; if (!bLiteralValue) { this.MaxValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_LT)) { this.NotOperator = true; } } else if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_GT) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_GT)) { this.MinValue = dValue + 0.001; this.MaxValue = 999999; if (!bLiteralValue) { this.MinValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_GT)) { this.NotOperator = true; } } else if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_LE) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_LE)) { this.MinValue = -999999; this.MaxValue = dValue; if (!bLiteralValue) { this.MaxValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_LE)) { this.NotOperator = true; } } else if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_GE) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_GE)) { this.MinValue = dValue; this.MaxValue = 999999; if (!bLiteralValue) { this.MinValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_GE)) { this.NotOperator = true; } } else if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_EQ) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_EQ)) { this.MinValue = dValue; this.MaxValue = dValue; if (!bLiteralValue) { this.MinValueProps = AttributeValueProps; this.MaxValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_AL_NOT_EQ)) { this.NotOperator = true; } } } }
/// <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; double dValue = 0.0; string sTempValue = paValueSet[0]; DateTime DateTimeValue = DateTime.Now; WonkaBreRuleValueProps AttributeValueProps = new WonkaBreRuleValueProps() { 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; } else { AttributeValueProps = this.GetAttributeValueProps(sTempValue); } } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_IB) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IB)) { this.MinValue = DateTime.MinValue; this.MaxValue = DateTimeValue; if (!bLiteralValue) { this.MaxValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IB)) { this.NotOperator = true; } } else if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_IA) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IA)) { this.MinValue = DateTimeValue; this.MaxValue = DateTime.MaxValue; if (!bLiteralValue) { this.MinValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IA)) { this.NotOperator = true; } } } }
/// <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; double dValue = 0.0; string sTempValue = paValueSet[0]; DateTime DateTimeValue = DateTime.Now; WonkaBreRuleValueProps AttributeValueProps = new WonkaBreRuleValueProps() { 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(WonkaBreXmlReader.CONST_DL_IB) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IB)) { this.MinValue = DateTime.MinValue; this.MaxValue = DateTimeValue; if (!bLiteralValue) { this.MaxValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IB)) { this.NotOperator = true; } } else if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_IA) || psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IA)) { this.MinValue = DateTimeValue; this.MaxValue = DateTime.MaxValue; if (!bLiteralValue) { this.MinValueProps = AttributeValueProps; } if (psRuleExpression.Contains(WonkaBreXmlReader.CONST_DL_NOT_IA)) { this.NotOperator = true; } } else if (psRuleExpression.Contains(WonkaBreXmlReader.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; * } */ } }