public static void AddNethereumERC20GetBalanceRule(this WonkaBizRuleSet poRuleSet, WonkaRefEnvironment poRefEnv, Web3 poWeb3, WonkaRefAttr poTargetAttr, string psAddRuleDesc, string psTargetOwner, string psERC20ContractAddress) { WonkaBizRule NewRule = null; WonkaBizSource DummySource = new WonkaBizSource("ERC20", psERC20ContractAddress, "", "", "", "", "", null); WonkaEthCustomOpRule CustomOpRule = new WonkaEthCustomOpRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, poTargetAttr.AttrId, CONST_ERC20_GET_BALANCE_OP, null, DummySource); CustomOpRule.OwnerWeb3 = poWeb3; CustomOpRule.PrimaryContractAddress = psERC20ContractAddress; CustomOpRule.CustomOpDelegate = CustomOpRule.InvokeERC20GetBalance; CustomOpRule.AddDomainValue(psTargetOwner, true, TARGET_RECORD.TRID_NONE); if (!String.IsNullOrEmpty(psAddRuleDesc)) { NewRule.DescRuleId = psAddRuleDesc; } poRuleSet.AddRule(NewRule); }
private void SetTargetAttribute(WonkaBizRule poTargetRule, string psRuleExpression) { char[] acTargetAttributeDelim = new char[1] { '.' }; int nAttrNameStartIdx = psRuleExpression.IndexOf(CONST_RULE_TOKEN_START_DELIM); if (nAttrNameStartIdx >= 0) { int nAttrNameEndIdx = psRuleExpression.IndexOf(CONST_RULE_TOKEN_END_DELIM, nAttrNameStartIdx + 1); if (nAttrNameEndIdx > 0) { string sRecordOfInterest = "N"; string sAttrName = psRuleExpression.Substring(nAttrNameStartIdx + 1, (nAttrNameEndIdx - nAttrNameStartIdx - 1)); if (sAttrName.Contains(acTargetAttributeDelim[0])) { string[] acAttrNameParts = sAttrName.Split(acTargetAttributeDelim); if (acAttrNameParts.Length > 1) { sRecordOfInterest = acAttrNameParts[0]; sAttrName = acAttrNameParts[1]; } } if (sRecordOfInterest == "N") { poTargetRule.RecordOfInterest = TARGET_RECORD.TRID_NEW_RECORD; } else { poTargetRule.RecordOfInterest = TARGET_RECORD.TRID_OLD_RECORD; } if (WonkaRefEnvironment.GetInstance().IsAttribute(sAttrName)) { poTargetRule.TargetAttribute = WonkaRefEnvironment.GetInstance().GetAttributeByAttrName(sAttrName); } else { throw new WonkaBizRuleException(-1, -1, "ERROR! Attribute (" + sAttrName + ") does not exist."); } } } }
/// <summary> /// /// This method will archive the results of a particular rule's execution by storing them as a /// a RuleReportNode and by inserting it into a RuleSetReportNode. /// /// <param name="poRule">The business rule that we have executed</param> /// <param name="peRuleErrCd">The error (i.e., result) code of that rule's execution</param> /// <param name="psRuleErrorDesc">The general description of the rule's error (if there is one)</param> /// <param name="psVerboseError">The verbose description of the rule's error (if there is one)</param> /// <returns>The indicator for whether or not the rule's execution results were successfully archived</returns> /// </summary> public bool ArchiveRuleExecution(WonkaBizRule poRule, ERR_CD peRuleErrCd, string psRuleErrorDesc, string psVerboseError) { bool bResult = true; WonkaBizRuleSetReportNode RuleSetReportNode = FindRuleSetReport(poRule.ParentRuleSetId, true); if (RuleSetReportNode != null) { WonkaBizRuleReportNode RuleReportNode = new WonkaBizRuleReportNode(poRule); RuleReportNode.ErrorCode = peRuleErrCd; RuleReportNode.ErrorDescription = psRuleErrorDesc; RuleReportNode.VerboseError = psVerboseError; RuleSetReportNode.RuleResults.Add(RuleReportNode); } return(bResult); }
public static string GetRuleDescription(this WonkaBizRule targetRule) { StringBuilder RuleDesc = new StringBuilder("Rule:" + targetRule.DescRuleId + ":"); if (targetRule is ArithmeticLimitRule) { RuleDesc.Append(" (ArithLimit -> " + targetRule.TargetAttribute.AttrName); } else if (targetRule is ArithmeticRule) { RuleDesc.Append(" (ArithAssign -> " + targetRule.TargetAttribute.AttrName); } else if (targetRule is AssignmentRule) { RuleDesc.Append(" (AssignRule -> " + targetRule.TargetAttribute.AttrName); } else if (targetRule is CustomOperatorRule) { RuleDesc.Append(" (CustomOpRule -> " + targetRule.TargetAttribute.AttrName); } else if (targetRule is DateLimitRule) { RuleDesc.Append(" (DateLimitRule -> " + targetRule.TargetAttribute.AttrName); } else if (targetRule is DomainRule) { RuleDesc.Append(" (DomainRule) -> " + targetRule.TargetAttribute.AttrName); } else if (targetRule is PopulatedRule) { RuleDesc.Append(" (PopulatedRule -> " + targetRule.TargetAttribute.AttrName); } else if (targetRule is CustomOperatorRule) { RuleDesc.Append(" (CustomOperatorRule -> " + targetRule.TargetAttribute.AttrName); } RuleDesc.Append(")"); return(RuleDesc.ToString()); }
private void SetRuleValues(WonkaBizRule poTargetRule, string psRuleExpression) { char[] acRuleValuesDelim = new char[1] { ',' }; int nValueStartIdx = psRuleExpression.LastIndexOf(CONST_RULE_TOKEN_START_DELIM); if (nValueStartIdx >= 0) { int nValueEndIdx = psRuleExpression.IndexOf(CONST_RULE_TOKEN_END_DELIM, nValueStartIdx + 1); if (nValueEndIdx > 0) { string sValues = psRuleExpression.Substring(nValueStartIdx + 1, (nValueEndIdx - nValueStartIdx - 1)); string[] asValueSet = sValues.Split(acRuleValuesDelim); if (poTargetRule.RuleType == RULE_TYPE.RT_DOMAIN) { DomainRule Rule = (DomainRule)poTargetRule; Rule.SetDomain(asValueSet); } else if (poTargetRule.RuleType == RULE_TYPE.RT_ARITHMETIC) { ArithmeticRule Rule = (ArithmeticRule)poTargetRule; Rule.SetDomain(asValueSet); } else if (poTargetRule.RuleType == RULE_TYPE.RT_ARITH_LIMIT) { ArithmeticLimitRule Rule = (ArithmeticLimitRule)poTargetRule; Rule.SetMinAndMax(psRuleExpression, asValueSet); } else if (poTargetRule.RuleType == RULE_TYPE.RT_ASSIGNMENT) { AssignmentRule Rule = (AssignmentRule)poTargetRule; Rule.SetAssignValue(asValueSet); } else if (poTargetRule.RuleType == RULE_TYPE.RT_DATE_LIMIT) { DateLimitRule Rule = (DateLimitRule)poTargetRule; Rule.SetMinAndMax(psRuleExpression, asValueSet); } else if (poTargetRule.RuleType == RULE_TYPE.RT_CUSTOM_OP) { CustomOperatorRule Rule = (CustomOperatorRule)poTargetRule; string sCustomOpKey = CustomOpSources.Keys.Where(s => psRuleExpression.Contains(s)).FirstOrDefault(); if (!string.IsNullOrEmpty(sCustomOpKey)) { Rule.SetDomain(asValueSet); Rule.CustomOpName = sCustomOpKey; Rule.CustomOpSource = CustomOpSources[sCustomOpKey]; } } } } }
private void ParseSingleRule(XmlNode poRuleXmlNode, WonkaBizRuleSet poTargetRuleSet) { int nNewRuleId = ++(this.RuleIdCounter); string sRuleExpression = poRuleXmlNode.InnerText; WonkaBizRule NewRule = null; if (this.CustomOpSources.Keys.Any(s => sRuleExpression.Contains(s))) { string sFoundKey = this.CustomOpSources.Keys.FirstOrDefault(s => sRuleExpression.Contains(s)); if (!String.IsNullOrEmpty(sFoundKey) && (this.CustomOpSources[sFoundKey].CustomOpRuleBuilder != null)) { WonkaBizSource CustomOpSource = this.CustomOpSources[sFoundKey]; NewRule = CustomOpSource.CustomOpRuleBuilder.Invoke(CustomOpSource, nNewRuleId); } else { NewRule = new CustomOperatorRule() { RuleId = nNewRuleId }; } } else if (this.ArithmeticLimitOps.Any(s => sRuleExpression.Contains(s))) { NewRule = new ArithmeticLimitRule() { RuleId = nNewRuleId }; } else if (this.DateLimitOps.Any(s => sRuleExpression.Contains(s))) { NewRule = new DateLimitRule() { RuleId = nNewRuleId }; } else if (sRuleExpression.Contains("NOT POPULATED")) { NewRule = new PopulatedRule() { RuleId = nNewRuleId, NotOperator = true }; } else if (sRuleExpression.Contains("POPULATED")) { NewRule = new PopulatedRule() { RuleId = nNewRuleId, NotOperator = false }; } else if (sRuleExpression.Contains("!=")) { NewRule = new DomainRule() { RuleId = nNewRuleId, NotOperator = true }; } else if (sRuleExpression.Contains("==")) { NewRule = new DomainRule() { RuleId = nNewRuleId, NotOperator = false }; } else if (sRuleExpression.Contains("NOT IN")) { NewRule = new DomainRule() { RuleId = nNewRuleId, NotOperator = true }; } else if (sRuleExpression.Contains("IN")) { NewRule = new DomainRule() { RuleId = nNewRuleId, NotOperator = false }; } else if (sRuleExpression.Contains("EXISTS AS")) { NewRule = new DomainRule() { RuleId = nNewRuleId, NotOperator = false, SearchAllDataRows = true }; } else if (sRuleExpression.Contains("DEFAULT")) { NewRule = new AssignmentRule() { RuleId = nNewRuleId, NotOperator = false, DefaultAssignment = true }; } else if (sRuleExpression.Contains("ASSIGN_SUM")) { NewRule = new ArithmeticRule() { RuleId = nNewRuleId, NotOperator = false, OpType = ARITH_OP_TYPE.AOT_SUM }; } else if (sRuleExpression.Contains("ASSIGN_DIFF")) { NewRule = new ArithmeticRule() { RuleId = nNewRuleId, NotOperator = false, OpType = ARITH_OP_TYPE.AOT_DIFF }; } else if (sRuleExpression.Contains("ASSIGN_PROD")) { NewRule = new ArithmeticRule() { RuleId = nNewRuleId, NotOperator = false, OpType = ARITH_OP_TYPE.AOT_PROD }; } else if (sRuleExpression.Contains("ASSIGN_QUOT")) { NewRule = new ArithmeticRule() { RuleId = nNewRuleId, NotOperator = false, OpType = ARITH_OP_TYPE.AOT_QUOT }; } else if (sRuleExpression.Contains("ASSIGN")) { NewRule = new AssignmentRule() { RuleId = nNewRuleId, NotOperator = false }; } if (NewRule != null) { var RuleId = poRuleXmlNode.Attributes.GetNamedItem(CONST_RULE_ID_ATTR); if (RuleId != null) { NewRule.DescRuleId = RuleId.Value; } NewRule.ParentRuleSetId = poTargetRuleSet.RuleSetId; SetTargetAttribute(NewRule, sRuleExpression); if (NewRule.RuleType != RULE_TYPE.RT_POPULATED) { SetRuleValues(NewRule, sRuleExpression); } if (RulesHostEngine != null) { NewRule.RulesHostEngine = RulesHostEngine; if (RulesHostEngine.StdOpMap != null) { if ((NewRule is ArithmeticLimitRule) && RulesHostEngine.StdOpMap.ContainsKey(STD_OP_TYPE.STD_OP_BLOCK_NUM)) { ((ArithmeticLimitRule)NewRule).BlockNumDelegate = RulesHostEngine.StdOpMap[STD_OP_TYPE.STD_OP_BLOCK_NUM]; } } } } if (NewRule != null) { poTargetRuleSet.AddRule(NewRule); } }
public static string GetRuleDetails(this WonkaBizRule targetRule) { StringBuilder RuleDesc = new StringBuilder(); if (targetRule is ArithmeticLimitRule) { var ArithLimitRule = (ArithmeticLimitRule)targetRule; if (targetRule.NotOperator) { RuleDesc.Append("NOT ("); } RuleDesc.Append(ArithLimitRule.MinValue + " > " + targetRule.TargetAttribute.AttrName + " > " + ArithLimitRule.MaxValue); if (targetRule.NotOperator) { RuleDesc.Append(")"); } } else if (targetRule is ArithmeticRule) { var ArithAssignRule = (ArithmeticRule)targetRule; RuleDesc.Append(ArithAssignRule.TargetAttribute.AttrName + " = " + ArithAssignRule.GetOpTypeDesc() + "(" + String.Join(",", ArithAssignRule.DomainValueProps.Keys) + ")"); } else if (targetRule is AssignmentRule) { var AssignRule = (AssignmentRule)targetRule; RuleDesc.Append(AssignRule.TargetAttribute.AttrName + " = (" + AssignRule.AssignValue + ")"); } else if (targetRule is CustomOperatorRule) { var CustomOpRule = (CustomOperatorRule)targetRule; if (CustomOpRule.CustomOpDelegate == BlazorAppNethereumExtensions.CheckBalanceIsWithinRange) { var CustomOpParams = CustomOpRule.DomainValueProps.Keys.ToList(); RuleDesc.Append("Target: " + CustomOpRule.TargetAttribute.AttrName + "||Operator: " + CustomOpRule.CustomOpName + "||Param - EOA Address(" + CustomOpParams[0] + ")" + "||Param - Min Value(" + CustomOpParams[1] + ")" + "||Param - Max Value(" + CustomOpParams[2] + ")"); } else { RuleDesc.Append("Target: " + CustomOpRule.TargetAttribute.AttrName + "||Operator: " + CustomOpRule.CustomOpName + "||Parameters(" + String.Join(",", CustomOpRule.DomainValueProps.Keys.ToList()) + ")"); } } else if (targetRule is DateLimitRule) { var DateLmtRule = (DateLimitRule)targetRule; if (targetRule.NotOperator) { RuleDesc.Append("NOT ("); } RuleDesc.Append(DateLmtRule.MinValue + " > " + targetRule.TargetAttribute.AttrName + " > " + DateLmtRule.MaxValue); if (targetRule.NotOperator) { RuleDesc.Append(")"); } } else if (targetRule is DomainRule) { string sNot = (targetRule.NotOperator) ? "NOT" : ""; var DmnRule = (DomainRule)targetRule; RuleDesc.Append(DmnRule.TargetAttribute.AttrName + " " + sNot + " IN (" + String.Join(",", DmnRule.DomainCache) + ")"); } else if (targetRule is PopulatedRule) { string sNot = (targetRule.NotOperator) ? "NOT" : ""; var PopRule = (PopulatedRule)targetRule; RuleDesc.Append(PopRule.TargetAttribute.AttrName + " IS " + sNot + " POPULATED"); } return(RuleDesc.ToString()); }
public static void AddNewRule(this WonkaBizRuleSet poRuleSet, WonkaRefEnvironment poRefEnv, string psAddRuleDesc, string psAddRuleTargetAttr, string psAddRuleTypeNum, string psAddRuleValue1, string psAddRuleValue2, bool pbAddRuleNotOp = false) { int nRuleTypeNum = Int32.Parse(psAddRuleTypeNum); WonkaBizRule NewRule = null; WonkaRefAttr targetAttr = poRefEnv.GetAttributeByAttrName(psAddRuleTargetAttr); if (nRuleTypeNum == 1) { if (!targetAttr.IsNumeric && !targetAttr.IsDecimal) { throw new DataException("ERROR! Cannot perform arithmetic limit on a non-numeric value."); } double dMinVal = 0; double dMaxVal = 0; Double.TryParse(psAddRuleValue1, out dMinVal); Double.TryParse(psAddRuleValue2, out dMaxVal); NewRule = new ArithmeticLimitRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, dMinVal, dMaxVal); } else if (nRuleTypeNum == 2) { /* * NOTE: Will handle ArithmeticRule later * string[] asParamArray = new string[0]; */ } else if (nRuleTypeNum == 3) { if (!String.IsNullOrEmpty(psAddRuleValue1)) { NewRule = new AssignmentRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, psAddRuleValue1); } } else if (nRuleTypeNum == 4) { /* * NOTE: Will handle CustomOperatorRule later */ } else if (nRuleTypeNum == 5) { if (!targetAttr.IsDate) { throw new DataException("ERROR! Cannot perform date limit on a non-date value."); } if ((!String.IsNullOrEmpty(psAddRuleValue1)) || (!String.IsNullOrEmpty(psAddRuleValue2))) { DateTime dtMinTime = DateTime.MinValue; DateTime dtMaxTime = DateTime.MaxValue; if (!String.IsNullOrEmpty(psAddRuleValue1)) { DateTime.TryParse(psAddRuleValue1, out dtMinTime); } if (!String.IsNullOrEmpty(psAddRuleValue2)) { DateTime.TryParse(psAddRuleValue2, out dtMaxTime); } var DtLimitRule = new DateLimitRule(mnRuleCounter++) { MinValue = dtMinTime, MaxValue = dtMaxTime, TargetAttribute = targetAttr }; NewRule = DtLimitRule; } } else if (nRuleTypeNum == 6) { if ((!String.IsNullOrEmpty(psAddRuleValue1)) || (!String.IsNullOrEmpty(psAddRuleValue2))) { HashSet <string> RuleDomain = new HashSet <string>(); if (!String.IsNullOrEmpty(psAddRuleValue1)) { if (psAddRuleValue1.Contains(",")) { var DomainVals = psAddRuleValue1.Split(new char[1] { ',' }); DomainVals.ToList().ForEach(x => DomainVals.Append(x)); } else { RuleDomain.Add(psAddRuleValue1); } } if (!String.IsNullOrEmpty(psAddRuleValue2)) { if (psAddRuleValue2.Contains(",")) { var DomainVals = psAddRuleValue2.Split(new char[1] { ',' }); DomainVals.ToList().ForEach(x => DomainVals.Append(x)); } else { RuleDomain.Add(psAddRuleValue2); } } var DmnRule = new DomainRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, false); DmnRule.DomainCache = RuleDomain; foreach (string sTmpValue in RuleDomain) { DmnRule.DomainValueProps.Add(sTmpValue, new WonkaBizRuleValueProps() { IsLiteralValue = true }); } NewRule = DmnRule; } } else if (nRuleTypeNum == 7) { NewRule = new PopulatedRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId); } if (NewRule != null) { if (!String.IsNullOrEmpty(psAddRuleDesc)) { NewRule.DescRuleId = psAddRuleDesc; } NewRule.ParentRuleSetId = poRuleSet.RuleSetId; NewRule.NotOperator = pbAddRuleNotOp; poRuleSet.AddRule(NewRule); } }
public static void AddNewNethereumRule(this WonkaBizRuleSet poRuleSet, WonkaRefEnvironment poRefEnv, string psAddRuleDesc, string psAddRuleTargetAttr, string psAddRuleTypeNum, string psAddRuleEthAddress, string psAddRuleValue1, string psAddRuleValue2) { if (String.IsNullOrEmpty(psAddRuleTypeNum)) { psAddRuleTypeNum = "1"; } int nRuleTypeNum = Int32.Parse(psAddRuleTypeNum); WonkaBizRule NewRule = null; WonkaRefAttr targetAttr = poRefEnv.GetAttributeByAttrName(psAddRuleTargetAttr); if ((nRuleTypeNum == 1) | (nRuleTypeNum == 2) || (nRuleTypeNum == 5)) { if (targetAttr.IsNumeric || targetAttr.IsDecimal) { throw new DataException("ERROR! Cannot perform offered Nethereum rules on a numeric value."); } if (String.IsNullOrEmpty(psAddRuleEthAddress)) { psAddRuleEthAddress = BlazorAppNethereumExtensions.CONST_ETH_FNDTN_EOA_ADDRESS; } } if (nRuleTypeNum == 1) { if (targetAttr.AttrName != "AccountStatus") { throw new Exception("ERROR! Cannot add BALANCE_WITHIN_RANGE rule with any attribute target other than AccountStatus."); } WonkaBizSource DummySource = new WonkaBizSource("EF_EOA", psAddRuleEthAddress, "", "", "", "", "", null); CustomOperatorRule CustomOpRule = new CustomOperatorRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, "BALANCE_WITHIN_RANGE", BlazorAppNethereumExtensions.CheckBalanceIsWithinRange, DummySource); CustomOpRule.AddDomainValue(psAddRuleEthAddress, true, TARGET_RECORD.TRID_NONE); CustomOpRule.AddDomainValue(psAddRuleValue1, true, TARGET_RECORD.TRID_NONE); CustomOpRule.AddDomainValue(psAddRuleValue2, true, TARGET_RECORD.TRID_NONE); NewRule = CustomOpRule; } else if (nRuleTypeNum == 2) { if (targetAttr.AttrName != "AuditReviewFlag") { throw new Exception("ERROR! Cannot add ANY_EVENTS_IN_BLOCK_RANGE rule with any attribute target other than AuditReviewFlag."); } WonkaBizSource DummySource = new WonkaBizSource("ERC20", psAddRuleEthAddress, "", "", "", "", "", null); CustomOperatorRule CustomOpRule = new CustomOperatorRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, "ANY_EVENTS_IN_BLOCK_RANGE", BlazorAppNethereumExtensions.AnyEventsInBlockRange, DummySource); if (String.IsNullOrEmpty(psAddRuleValue1)) { psAddRuleValue1 = "8450678"; } if (String.IsNullOrEmpty(psAddRuleValue2)) { psAddRuleValue2 = "8450698"; } CustomOpRule.AddDomainValue(psAddRuleEthAddress, true, TARGET_RECORD.TRID_NONE); CustomOpRule.AddDomainValue(psAddRuleValue1, true, TARGET_RECORD.TRID_NONE); CustomOpRule.AddDomainValue(psAddRuleValue2, true, TARGET_RECORD.TRID_NONE); NewRule = CustomOpRule; } else if (nRuleTypeNum == 3) { if (!targetAttr.IsNumeric && !targetAttr.IsDecimal) { throw new DataException("ERROR! Cannot perform arithmetic limit on a non-numeric value."); } WonkaBizSource DummySource = new WonkaBizSource("ERC20", psAddRuleEthAddress, "", "", "", "", "", null); CustomOperatorRule CustomOpRule = new CustomOperatorRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, "GET_ERC20_BALANCE", BlazorAppNethereumExtensions.GetERC20Balance, DummySource); CustomOpRule.AddDomainValue(psAddRuleEthAddress, true, TARGET_RECORD.TRID_NONE); CustomOpRule.AddDomainValue(psAddRuleValue1, true, TARGET_RECORD.TRID_NONE); NewRule = CustomOpRule; } else if (nRuleTypeNum == 4) { if (!targetAttr.IsNumeric && !targetAttr.IsDecimal) { throw new DataException("ERROR! Cannot perform arithmetic limit on a non-numeric value."); } WonkaBizSource DummySource = new WonkaBizSource("ContractName", psAddRuleEthAddress, "", "", "", "", "", null); CustomOperatorRule CustomOpRule = new CustomOperatorRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, "CALL_SIMPLE_CONTRACT_METHOD", BlazorAppNethereumExtensions.GetContractSimpleMethodValue, DummySource); var sAltConfigIpfsUrl = psAddRuleValue1; var sFunctionName = psAddRuleValue2; if (String.IsNullOrEmpty(sAltConfigIpfsUrl)) { sAltConfigIpfsUrl = BlazorAppNethereumExtensions.CONST_INFURA_IPFS_GATEWAY_URL + "/QmYDp4ocbF1AVSuY1zBhXa6P4c2oaPkHi2jaSE3HU6bQnQ"; } using (var client = new System.Net.Http.HttpClient()) { var sConfigDataXml = client.GetStringAsync(sAltConfigIpfsUrl).Result; var configData = ReadConfigXml(sConfigDataXml); if (!String.IsNullOrEmpty(configData.HostUrl)) { CustomOpRule.AddDomainValue(configData.HostUrl, true, TARGET_RECORD.TRID_NONE); } else { CustomOpRule.AddDomainValue(BlazorAppNethereumExtensions.CONST_TEST_INFURA_URL, true, TARGET_RECORD.TRID_NONE); } CustomOpRule.AddDomainValue(configData.ContractABI, true, TARGET_RECORD.TRID_NONE); if (!String.IsNullOrEmpty(psAddRuleEthAddress)) { CustomOpRule.AddDomainValue(psAddRuleEthAddress, true, TARGET_RECORD.TRID_NONE); } else { CustomOpRule.AddDomainValue(configData.ContractAddress, true, TARGET_RECORD.TRID_NONE); } CustomOpRule.AddDomainValue(sFunctionName, true, TARGET_RECORD.TRID_NONE); NewRule = CustomOpRule; } } else if (nRuleTypeNum == 5) { if (targetAttr.AttrName != "AccountStatus") { throw new Exception("ERROR! Cannot add V rule with any attribute target other than AccountStatus."); } WonkaBizSource DummySource = new WonkaBizSource("ContractName", psAddRuleEthAddress, "", "", "", "", "", null); CustomOperatorRule CustomOpRule = new CustomOperatorRule(mnRuleCounter++, TARGET_RECORD.TRID_NEW_RECORD, targetAttr.AttrId, "VALIDATE_SIGNATURE", BlazorAppNethereumExtensions.DetermineStatusByValidatingSignature, DummySource); var sAttrTarget = psAddRuleValue1; var sSignature = psAddRuleValue2; var TargetAttr = poRefEnv.GetAttributeByAttrName(sAttrTarget); if (TargetAttr == null) { throw new Exception("ERROR! Cannot add rule since attribute(" + sAttrTarget + ") does not exist!"); } CustomOpRule.AddDomainValue(psAddRuleEthAddress, true, TARGET_RECORD.TRID_NONE); CustomOpRule.AddDomainValue(sAttrTarget, false, TARGET_RECORD.TRID_NEW_RECORD); CustomOpRule.AddDomainValue(sSignature, true, TARGET_RECORD.TRID_NONE); NewRule = CustomOpRule; } if (NewRule != null) { if (!String.IsNullOrEmpty(psAddRuleDesc)) { NewRule.DescRuleId = psAddRuleDesc; } poRuleSet.AddRule(NewRule); } }
/// /// <summary> /// /// This method will write the XML (i.e., Wonka rules markup) of a Rule. /// /// NOTE: Currently, we use a StringBuilder class to build the XML Document. In the future, we should transition to /// using a XmlDocument and a XmlWriter. /// /// <returns>Returns the XML payload that represents a Rule</returns> /// </summary> public string ExportXmlString(WonkaBizRule poRule, StringBuilder poSpaces) { string sOpName = string.Empty; string sRuleValue = ""; string sDelim = WonkaBizRulesXmlReader.CONST_RULE_TOKEN_VAL_DELIM; string sSingleQuote = "'"; string sRuleTagFormat = "{0}<" + WonkaBizRulesXmlReader.CONST_RULE_TAG + " " + WonkaBizRulesXmlReader.CONST_RULE_ID_ATTR + "=\"{1}\">(N.{2}) {3} {4}</eval>\n"; if (poRule.RuleType == RULE_TYPE.RT_ARITH_LIMIT) { ArithmeticLimitRule ArithLimitRule = (ArithmeticLimitRule)poRule; if (ArithLimitRule.MinValue == Double.MinValue) { sOpName = !poRule.NotOperator ? WonkaBizRulesXmlReader.CONST_AL_LT : WonkaBizRulesXmlReader.CONST_AL_NOT_LT; sRuleValue = Convert.ToString(ArithLimitRule.MaxValue); } else if (ArithLimitRule.MaxValue == Double.MaxValue) { sOpName = !poRule.NotOperator ? WonkaBizRulesXmlReader.CONST_AL_GT : WonkaBizRulesXmlReader.CONST_AL_NOT_GT; sRuleValue = Convert.ToString(ArithLimitRule.MinValue); } else { sOpName = !poRule.NotOperator ? WonkaBizRulesXmlReader.CONST_AL_EQ : WonkaBizRulesXmlReader.CONST_AL_NOT_EQ; sRuleValue = Convert.ToString(ArithLimitRule.MinValue); } } else if (poRule.RuleType == RULE_TYPE.RT_DATE_LIMIT) { DateLimitRule DtLimitRule = (DateLimitRule)poRule; if (DtLimitRule.MinValue == DateTime.MinValue) { sOpName = !poRule.NotOperator ? WonkaBizRulesXmlReader.CONST_DL_IA : WonkaBizRulesXmlReader.CONST_DL_NOT_IA; sRuleValue = DtLimitRule.MaxValue.ToString("MM/dd/yyyy"); } else if (DtLimitRule.MaxValue == DateTime.MaxValue) { sOpName = !poRule.NotOperator ? WonkaBizRulesXmlReader.CONST_DL_IB : WonkaBizRulesXmlReader.CONST_DL_NOT_IB; sRuleValue = DtLimitRule.MinValue.ToString("MM/dd/yyyy"); } else { sOpName = WonkaBizRulesXmlReader.CONST_DL_AROUND; sRuleValue = DtLimitRule.MinValue.ToString("MM/dd/yyyy"); } } else if (poRule.RuleType == RULE_TYPE.RT_POPULATED) { sOpName = !poRule.NotOperator ? WonkaBizRulesXmlReader.CONST_BASIC_OP_POP : WonkaBizRulesXmlReader.CONST_BASIC_OP_NOT_POP; } else if (poRule.RuleType == RULE_TYPE.RT_DOMAIN) { StringBuilder DomainVals = new StringBuilder(); DomainRule DmnRule = (DomainRule)poRule; sOpName = !poRule.NotOperator ? WonkaBizRulesXmlReader.CONST_BASIC_OP_IN : WonkaBizRulesXmlReader.CONST_BASIC_OP_NOT_IN; sRuleValue = BuildDomainValues(DmnRule.DomainValueProps, sDelim, sSingleQuote); } else if (poRule.RuleType == RULE_TYPE.RT_ASSIGNMENT) { StringBuilder DomainVals = new StringBuilder(); AssignmentRule AssignRule = (AssignmentRule)poRule; sOpName = WonkaBizRulesXmlReader.CONST_BASIC_OP_ASSIGN; var ValueProps = new Dictionary <string, WonkaBizRuleValueProps>(); ValueProps[AssignRule.AssignValue] = AssignRule.AssignValueProps; sRuleValue = BuildDomainValues(ValueProps, sDelim, sSingleQuote); } else if (poRule.RuleType == RULE_TYPE.RT_ARITHMETIC) { ArithmeticRule ArithRule = (ArithmeticRule)poRule; if (ArithRule.OpType == ARITH_OP_TYPE.AOT_SUM) { sOpName = WonkaBizRulesXmlReader.CONST_BASIC_OP_ASSIGN_SUM; } else if (ArithRule.OpType == ARITH_OP_TYPE.AOT_DIFF) { sOpName = WonkaBizRulesXmlReader.CONST_BASIC_OP_ASSIGN_DIFF; } else if (ArithRule.OpType == ARITH_OP_TYPE.AOT_PROD) { sOpName = WonkaBizRulesXmlReader.CONST_BASIC_OP_ASSIGN_PROD; } else if (ArithRule.OpType == ARITH_OP_TYPE.AOT_QUOT) { sOpName = WonkaBizRulesXmlReader.CONST_BASIC_OP_ASSIGN_QUOT; } sRuleValue = BuildDomainValues(ArithRule.DomainValueProps, sDelim, sSingleQuote); } else if (poRule.RuleType == RULE_TYPE.RT_CUSTOM_OP) { CustomOperatorRule CustomOpRule = (CustomOperatorRule)poRule; sOpName = CustomOpRule.CustomOpName; sRuleValue = BuildDomainValues(CustomOpRule.DomainValueProps, sDelim, sSingleQuote); } else { throw new WonkaBizRuleException("ERROR! Unsupported Rule Type when writing out the Wonka RuleTree."); } if (!String.IsNullOrEmpty(sRuleValue)) { sRuleValue = "(" + sRuleValue + ")"; } return(String.Format(sRuleTagFormat, poSpaces.ToString(), poRule.DescRuleId, poRule.TargetAttribute.AttrName, sOpName, sRuleValue)); }
public WonkaBizRuleReportNode(WonkaBizRule poRule) : this() { RuleID = poRule.RuleId; TriggerAttrId = poRule.TargetAttribute.AttrId; }