/// <summary> /// /// This method will serialize a ProductGroup within a Product instance. /// /// </summary> /// <param name="poTmpPrdGroup">The target ProductGroup being serialized</param> /// <param name="poProductListBuilder">The buffer that is holding the written WONKA-XML message</param> /// <returns>None</returns> private void AppendProductGroup(WonkaPrdGroup poTmpPrdGroup, StringBuilder poProductListBuilder) { WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.GetInstance(); if (poTmpPrdGroup.GetRowCount() > 0) { string sTmpAttrValue = null; foreach (WonkaPrdGroupDataRow TempDataRow in poTmpPrdGroup) { poProductListBuilder.Append("\n <" + poTmpPrdGroup.MasterGroup.GroupName + ">"); foreach (int nTmpAttrId in TempDataRow.Keys) { sTmpAttrValue = TempDataRow[nTmpAttrId]; if (!String.IsNullOrEmpty(sTmpAttrValue)) { WonkaRefAttr TempAttribute = WonkaRefEnv.GetAttributeByAttrId(nTmpAttrId); poProductListBuilder.Append("\n <" + TempAttribute.AttrName + ">"); poProductListBuilder.Append(WrapWithCData(sTmpAttrValue)); poProductListBuilder.Append("</" + TempAttribute.AttrName + ">"); } } poProductListBuilder.Append("\n </" + poTmpPrdGroup.MasterGroup.GroupName + ">"); } } }
/// <summary> /// /// This method will iterate through the DataRows inside this Group in order to form /// the appropriate repeating composite bodies as its correct XML amalgamation. /// /// For example, in the case of an Account group with two rows, it could then /// generate XML like the following: /// /// <Account> /// <AccountType><![CDATA[Checking]]></AccountType> /// <Currency><![CDATA[Ethereum]]></Currency> /// <Amount><![CDATA[10.5]]></Amount> /// </Account> /// <Account> /// <AccountType><![CDATA[Savings]]></AccountType> /// <Currency><![CDATA[USD]]></Currency> /// <Amount><![CDATA[20.5]]></Amount> /// </Account> /// /// </summary> /// <returns>The serialized Wonka XML that represents this Product Group</returns> public string AssembleGroupXml() { WonkaRefEnvironment RefEnv = WonkaRefEnvironment.GetInstance(); StringBuilder GroupBuilder = new StringBuilder(); foreach (WonkaPrdGroupDataRow TempDataRow in this) { GroupBuilder.Append("<" + this.MasterGroup.GroupName + ">"); foreach (int nTempAttrId in TempDataRow.Keys) { WonkaRefAttr TempAttribute = RefEnv.GetAttributeByAttrId(nTempAttrId); string sTempAttrValue = TempDataRow[nTempAttrId]; if (!String.IsNullOrEmpty(sTempAttrValue)) { GroupBuilder.Append("\t<" + TempAttribute.AttrName + ">" + WrapWithCDATA(sTempAttrValue) + "</" + TempAttribute.AttrName + ">"); } } GroupBuilder.Append("</" + this.MasterGroup.GroupName + ">"); } return(GroupBuilder.ToString()); }
/// <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); }
/// <summary> /// /// This method will iterate through all of the data in the contained groups and detect whether /// any of them are not valid according to the designated type for that Attribute. /// /// <param name="poErrors">The list to which we will add any errors concerning the validation of types</param> /// <returns>Indicates whether or not there any errors with validating types</returns> /// </summary> public bool ValidateTypes(List <WonkaProductError> poErrors) { WonkaRefEnvironment RefEnv = WonkaRefEnvironment.GetInstance(); bool bResult = true; foreach (int nGrpId in this.ProductGroups.Keys) { WonkaPrdGroup TempGroup = ProductGroups[nGrpId]; foreach (WonkaPrdGroupDataRow TempDataRow in TempGroup) { foreach (int nAttrId in TempDataRow.Keys) { string sAttrValue = TempDataRow[nAttrId]; if (!String.IsNullOrEmpty(sAttrValue)) { WonkaRefAttr TempAttr = RefEnv.GetAttributeByAttrId(nAttrId); if (TempAttr.IsDecimal) { try { Decimal dValue = Convert.ToDecimal(sAttrValue); } catch (Exception ex) { poErrors.Add(new WonkaProductError() { AttrName = TempAttr.AttrName, ErrorMessage = "ERROR! Value(" + sAttrValue + ") is not a valid decimal!" }); } } else if (TempAttr.IsNumeric) { try { long nValue = Convert.ToInt64(sAttrValue); } catch (Exception ex) { poErrors.Add(new WonkaProductError() { AttrName = TempAttr.AttrName, ErrorMessage = "ERROR! Value(" + sAttrValue + ") is not a valid number!" }); } } else if (TempAttr.IsDate) { try { DateTime dtValue = DateTime.Parse(sAttrValue); } catch (Exception ex) { poErrors.Add(new WonkaProductError() { AttrName = TempAttr.AttrName, ErrorMessage = "ERROR! Value(" + sAttrValue + ") is not a valid date!" }); } } } } } } return(bResult); }