public static async Task <string> ExecuteOnChain(this WonkaEthEngineInitialization poEthEngineInit) { StringBuilder EngineReport = new StringBuilder(); /** ** Classic Way ** ** var EngineContractHandler = ** GetWeb3(poEthEngineInit.EthPassword, poEthEngineInit.Web3HttpUrl).Eth.GetContractHandler(poEthEngineInit.RulesEngineContractAddress); ** ** var ExecWithReportFunction = ** new ExecuteWithReportFunction() { Ruler = poEthEngineInit.EthSenderAddress }; ** ** var EWRTrxReceipt = await EngineContractHandler.SendRequestAndWaitForReceiptAsync(ExecWithReportFunction, null).ConfigureAwait(false); **/ ProgressBarValues.ExecuteProgressBar = 12; var Report = new Wonka.Eth.Extensions.RuleTreeReport(); ProgressBarValues.ExecuteProgressBar = 25; await poEthEngineInit.Engine.RulesEngine.ExecuteOnChainAsync(poEthEngineInit, Report).ConfigureAwait(false); ProgressBarValues.ExecuteProgressBar = 50; string sPrettyPrintReport = await Report.PrettyPrint(poEthEngineInit).ConfigureAwait(false); EngineReport.Append(sPrettyPrintReport); ProgressBarValues.ExecuteProgressBar = 75; return(EngineReport.ToString()); }
/// <summary> /// /// This method will persist all data to files (metadata, rules, current data, report), zip the files, and then upload the .ZIP to IPFS /// /// <param name="poEngine">The instance of the Wonka engine that has just run</param> /// <param name="poEngineInitProps">Various properties of this instance of the Wonka engine</param> /// <param name="poRecord">This record holds the current snapshot of the data being addressed by the metadata (mentioned in WonkaRefEnvironment)</param> /// <param name="poReport">This report holds the verbose results of running the RuleTree</param> /// <param name="psIpfsUrl">This URL points to the IPFS node that acts as the read-only gateway</param> /// <param name="psWriteIpfsUrl">This URL points to the IPFS node that will be used to upload the Zip file of the results</param> /// <param name="psUniqueChronoLogName">This will be the unique name of the ChronoLog entry</param> /// <returns>IPFS ID of the new file</returns> /// </summary> public static async Task <string> UploadInvocationAsync(this WonkaBizRulesEngine poEngine, Wonka.Eth.Init.WonkaEthEngineInitialization poEngineInitProps, WonkaProduct poRecord, Wonka.Eth.Extensions.RuleTreeReport poReport, string psIpfsUrl, string psWriteIpfsUrl, string psUniqueChronoLogName) { string sZipIpfsUrl = ""; var RefEnv = WonkaRefEnvironment.GetInstance(); string sZipFileUrl = poEngine.ZipInvocation(poRecord, poReport, psUniqueChronoLogName); var zipBytes = File.ReadAllBytes(sZipFileUrl); using (MemoryStream zipStream = new MemoryStream(zipBytes)) { var ipfsClient = new IpfsClient(psWriteIpfsUrl); var merkleNode = await ipfsClient.FileSystem.AddFileAsync(sZipFileUrl, new Ipfs.CoreApi.AddFileOptions() { Pin = true }).ConfigureAwait(false); sZipIpfsUrl = psIpfsUrl + "/" + merkleNode.Id.Hash.ToString(); } return(sZipIpfsUrl); }
public RuleTreeReport ExecuteWithReport(WonkaBizRulesEngine poRulesEngine, bool pbValidateWithinTransaction) { WonkaRefEnvironment RefEnv = WonkaRefEnvironment.GetInstance(); WonkaRefAttr CurrValueAttr = RefEnv.GetAttributeByAttrName("AccountCurrValue"); WonkaRefAttr ReviewFlagAttr = RefEnv.GetAttributeByAttrName("AuditReviewFlag"); Dictionary <string, string> PrdKeys = new Dictionary <string, string>(); var contract = GetContract(); var senderAddress = moEthEngineInit.EthSenderAddress; var executeWithReportFunction = contract.GetFunction(CONST_CONTRACT_FUNCTION_EXEC_RPT); RuleTreeReport ruleTreeReport = null; if (pbValidateWithinTransaction) { var FlagSource = poRulesEngine.SourceMap[ReviewFlagAttr.AttrName]; var CurrValSource = poRulesEngine.SourceMap[CurrValueAttr.AttrName]; var executeGetLastReportFunction = contract.GetFunction(CONST_CONTRACT_FUNCTION_GET_LAST_RPT); WonkaProduct OrchContractCurrValues = poRulesEngine.AssembleCurrentProductFromChainSources(new Dictionary <string, string>(), CONST_ONLINE_TEST_CHAIN_URL); // Before invoking the RuleTree, the storage contract should have Review Flag as "" and CurrVal as "999" string sFlagBeforeOrchestrationAssignment = RetrieveValueMethod(FlagSource, ReviewFlagAttr.AttrName); string sValueBeforeOrchestrationAssignment = RetrieveValueMethod(CurrValSource, CurrValueAttr.AttrName); var EthRuleTreeReport = new Wonka.Eth.Extensions.RuleTreeReport(); poRulesEngine.ExecuteOnChain(moEthEngineInit, EthRuleTreeReport); // After invoking the RuleTree, the storage contract should have Review Flag as "???" and CurrVal as "1014" string sFlagAfterOrchestrationAssignment = RetrieveValueMethod(FlagSource, ReviewFlagAttr.AttrName); string sValueAfterOrchestrationAssignment = RetrieveValueMethod(CurrValSource, CurrValueAttr.AttrName); ruleTreeReport = executeGetLastReportFunction.CallDeserializingToObjectAsync <RuleTreeReport>().Result; } else { ruleTreeReport = executeWithReportFunction.CallDeserializingToObjectAsync <RuleTreeReport>(senderAddress).Result; } return(ruleTreeReport); }
public async Task <RuleTreeReport> ExecuteWithReportAsync(WonkaBizRulesEngine poRulesEngine, bool pbValidateWithinTransaction) { WonkaRefEnvironment RefEnv = WonkaRefEnvironment.GetInstance(); WonkaRefAttr CurrValueAttr = RefEnv.GetAttributeByAttrName("AccountCurrValue"); WonkaRefAttr ReviewFlagAttr = RefEnv.GetAttributeByAttrName("AuditReviewFlag"); var contract = GetContract(); var senderAddress = moEthEngineInit.EthSenderAddress; var executeWithReportFunction = contract.GetFunction(CONST_CONTRACT_FUNCTION_EXEC_RPT); RuleTreeReport ruleTreeReport = null; if (pbValidateWithinTransaction) { var FlagSource = poRulesEngine.SourceMap[ReviewFlagAttr.AttrName]; var CurrValSource = poRulesEngine.SourceMap[CurrValueAttr.AttrName]; var executeGetLastReportFunction = contract.GetFunction(CONST_CONTRACT_FUNCTION_GET_LAST_RPT); // Before invoking the RuleTree, the storage contract should have Review Flag as "" and CurrVal as "999" string sFlagBeforeOrchestrationAssignment = await RetrieveValueMethodAsync(FlagSource, ReviewFlagAttr.AttrName).ConfigureAwait(false); string sValueBeforeOrchestrationAssignment = await RetrieveValueMethodAsync(CurrValSource, CurrValueAttr.AttrName).ConfigureAwait(false); var EthRuleTreeReport = new Wonka.Eth.Extensions.RuleTreeReport(); await poRulesEngine.ExecuteOnChainAsync(moEthEngineInit, EthRuleTreeReport).ConfigureAwait(false); // After invoking the RuleTree, the storage contract should have Review Flag as "???" and CurrVal as "1014" string sFlagAfterOrchestrationAssignment = await RetrieveValueMethodAsync(FlagSource, ReviewFlagAttr.AttrName).ConfigureAwait(false); string sValueAfterOrchestrationAssignment = await RetrieveValueMethodAsync(CurrValSource, CurrValueAttr.AttrName).ConfigureAwait(false); ruleTreeReport = await executeGetLastReportFunction.CallDeserializingToObjectAsync <RuleTreeReport>().ConfigureAwait(false); } else { ruleTreeReport = await executeWithReportFunction.CallDeserializingToObjectAsync <RuleTreeReport>(senderAddress).ConfigureAwait(false); } return(ruleTreeReport); }
public void Copy(RuleTreeReport poOriginal) { GasUsed = poOriginal.GasUsed; NumberOfRuleFailures = poOriginal.NumberOfRuleFailures; TransactionHash = poOriginal.TransactionHash; InvokeTrxBlockNumber = poOriginal.InvokeTrxBlockNumber; StartTime = poOriginal.StartTime; EndTime = poOriginal.EndTime; RuleSetIds = poOriginal.RuleSetIds; RuleIds = poOriginal.RuleIds; RuleSetWarnings = poOriginal.RuleSetWarnings; RuleSetFailures = poOriginal.RuleSetFailures; DataSnapshotPrior = new Dictionary <string, string>(poOriginal.DataSnapshotPrior); DataSnapshot = new Dictionary <string, string>(poOriginal.DataSnapshot); RuleSetFailMessages = new Dictionary <string, string>(poOriginal.RuleSetFailMessages); }
public static async Task <string> PrettyPrint(this Wonka.Eth.Extensions.RuleTreeReport poReport, WonkaEthEngineInitialization poEthEngineInit) { StringBuilder PrettyPrintReport = new StringBuilder(); int nRSFailedCount = poReport.GetRuleSetSevereFailureCount(); if (nRSFailedCount == 0) { PrettyPrintReport.Append("Engine completed successfully!\n\n"); } else { PrettyPrintReport.Append("Engine failed, with [" + nRSFailedCount + "] 'severe' leaf RuleSets having failed.\n\n"); PrettyPrintReport.Append("Failed 'severe' RuleSets: [" + String.Join(',', poReport.RuleSetFailures) + "]\n\n"); } string sCurrValsReport = await poEthEngineInit.GetCurrValuesReport().ConfigureAwait(false); PrettyPrintReport.Append(sCurrValsReport); return(PrettyPrintReport.ToString()); }
/// <summary> /// /// After running an instance of the Wonka engine, this method will: /// /// 1.) Persist all data to files (metadata, rules, current data, report), zip the files, and then upload the .ZIP to IPFS /// 2.) Create the hash of the Zip file /// 3.) Create an entry on the ChronoLog contract (including the IPFS URL and hash of the Zip file) /// /// <param name="poEngine">The instance of the Wonka engine that has just run a RuleTree</param> /// <param name="poEngineInitProps">Various properties of this instance of the Wonka engine</param> /// <param name="poRecord">This record holds the current snapshot of the data being addressed by the metadata (mentioned in WonkaRefEnvironment)</param> /// <param name="poReport">This report holds the verbose results of running the RuleTree</param> /// <param name="psIpfsUrl">This URL points to the IPFS node that acts as the read-only gateway</param> /// <param name="psWriteIpfsUrl">This URL points to the IPFS node that will be used to upload the Zip file of the results</param> /// <param name="psChronoLogContractAddr">This address points to an instance of the ChronoLog contract</param> /// <returns>Unique name for entry in the ChronoLog contract</returns> /// </summary> public static async Task <string> StoreWonkaResultsAsync(this WonkaBizRulesEngine poEngine, Wonka.Eth.Init.WonkaEthEngineInitialization poEngineInitProps, WonkaProduct poRecord, Wonka.Eth.Extensions.RuleTreeReport poReport, string psIpfsUrl, string psWriteIpfsUrl, string psChronoLogContractAddr) { var RefEnv = WonkaRefEnvironment.GetInstance(); var signer = new EthereumMessageSigner(); var prodMsgXml = new WonkaProductMsgWriter().WriteWonkaMsg(new WonkaProductMessage(poRecord, true)); var inputSignature = signer.EncodeUTF8AndSign(prodMsgXml, new EthECKey(poEngineInitProps.EthPassword)); string sUniqueChronoLogName = "WI-" + DateTime.Now.ToUniversalTime().ToEpochTime(); string sZipIpfsUrl = await poEngine.UploadInvocationAsync(poEngineInitProps, poRecord, poReport, psIpfsUrl, psWriteIpfsUrl, sUniqueChronoLogName).ConfigureAwait(false); var addChronoLogEventFunction = new Wonka.Eth.Autogen.ChronoLog.AddChronoLogEventFunction() { UniqueName = sUniqueChronoLogName, EType = "WONKA_INVOKE", Desc = "", // Empty for now Data = "", // Empty for now Hash = inputSignature, Url = sZipIpfsUrl }; string sTrxHash = await poReport.WriteToChronoLog(poEngineInitProps, psChronoLogContractAddr, addChronoLogEventFunction).ConfigureAwait(false); return(sUniqueChronoLogName); }
public async Task <RuleTreeReport> ExecuteWithReportAsync(WonkaBizRulesEngine poRulesEngine, bool pbValidateWithinTransaction) { WonkaRefEnvironment RefEnv = WonkaRefEnvironment.GetInstance(); WonkaRefAttr CurrValueAttr = RefEnv.GetAttributeByAttrName("AccountCurrValue"); WonkaRefAttr ReviewFlagAttr = RefEnv.GetAttributeByAttrName("AuditReviewFlag"); var contract = GetContract(); var senderAddress = moEthEngineInit.EthSenderAddress; string sFlagBeforeOrchestrationAssignment = ""; string sValueBeforeOrchestrationAssignment = ""; string sFlagAfterOrchestrationAssignment = ""; string sValueAfterOrchestrationAssignment = ""; var executeWithReportFunction = contract.GetFunction(CONST_CONTRACT_FUNCTION_EXEC_RPT); RuleTreeReport ruleTreeReport = null; if (pbValidateWithinTransaction) { var FlagSource = poRulesEngine.SourceMap[ReviewFlagAttr.AttrName]; var CurrValSource = poRulesEngine.SourceMap[CurrValueAttr.AttrName]; var executeGetLastReportFunction = contract.GetFunction(CONST_CONTRACT_FUNCTION_GET_LAST_RPT); // Before invoking the RuleTree, the storage contract should have Review Flag as "" and CurrVal as "999" sFlagBeforeOrchestrationAssignment = await RetrieveValueMethodAsync(FlagSource, ReviewFlagAttr.AttrName).ConfigureAwait(false); sValueBeforeOrchestrationAssignment = await RetrieveValueMethodAsync(CurrValSource, CurrValueAttr.AttrName).ConfigureAwait(false); System.Console.WriteLine("ExecuteWithReportAsync() -> Flag Before Assignment : (" + sFlagBeforeOrchestrationAssignment + ")"); System.Console.WriteLine("ExecuteWithReportAsync() -> Value Before Assignment : (" + sValueBeforeOrchestrationAssignment + ")"); var EthRuleTreeReport = new Wonka.Eth.Extensions.RuleTreeReport(); await poRulesEngine.ExecuteOnChainAsync(moEthEngineInit, EthRuleTreeReport).ConfigureAwait(false); // After invoking the RuleTree, the storage contract should have Review Flag as "???" and CurrVal as "1014" sFlagAfterOrchestrationAssignment = await RetrieveValueMethodAsync(FlagSource, ReviewFlagAttr.AttrName).ConfigureAwait(false); sValueAfterOrchestrationAssignment = await RetrieveValueMethodAsync(CurrValSource, CurrValueAttr.AttrName).ConfigureAwait(false); System.Console.WriteLine("ExecuteWithReportAsync() -> Flag After Assignment : (" + sFlagAfterOrchestrationAssignment + ")"); System.Console.WriteLine("ExecuteWithReportAsync() -> Value After Assignment : (" + sValueAfterOrchestrationAssignment + ")"); ruleTreeReport = await executeGetLastReportFunction.CallDeserializingToObjectAsync <RuleTreeReport>().ConfigureAwait(false); System.Console.WriteLine("ExecuteWithReportAsync() -> Flag After Assignment : (" + sFlagAfterOrchestrationAssignment + ")"); System.Console.WriteLine("ExecuteWithReportAsync() -> Value After Assignment : (" + sValueAfterOrchestrationAssignment + ")"); if (!String.IsNullOrEmpty(moEthEngineInit.ChronoLogContractAddress)) { var report = new Wonka.Eth.Extensions.RuleTreeReport() { NumberOfRuleFailures = ruleTreeReport.NumberOfRuleFailures , RuleIds = ruleTreeReport.RuleIds , RuleSetIds = ruleTreeReport.RuleSetIds }; var ChronoLogId = await poRulesEngine.StoreWonkaResultsAsync(moEthEngineInit , moProduct , report , CONST_INFURA_IPFS_GATEWAY_URL , CONST_INFURA_IPFS_WRITE_GATEWAY_URL , moEthEngineInit.ChronoLogContractAddress); } } else { ruleTreeReport = await executeWithReportFunction.CallDeserializingToObjectAsync <RuleTreeReport>(senderAddress).ConfigureAwait(false); } return(ruleTreeReport); }
public RuleTreeReport(RuleTreeReport poOriginal) { Copy(poOriginal); }
public void HandleEvents(WonkaBizRulesEngine poRulesEngine, RuleTreeReport poRuleTreeReport) { var ruleTreeLog = RuleTreeEvents.GetFilterChanges <CallRuleTreeEvent>(RuleTreeEventFilter).Result; var ruleSetLog = RuleSetEvents.GetFilterChanges <CallRuleSetEvent>(RuleSetEventFilter).Result; var ruleLog = RuleEvents.GetFilterChanges <CallRuleEvent>(RuleEventFilter).Result; var ruleSetErrLog = RuleSetErrorEvents.GetFilterChanges <RuleSetErrorEvent>(RuleSetErrorEventFilter).Result; /** * if (ruleTreeLog.Count > 0) * System.Console.WriteLine("RuleTree Called that Belongs to : (" + ruleTreeLog[0].Event.TreeOwner + ")"); **/ if (ruleSetLog.Count > 0) { foreach (EventLog <CallRuleSetEvent> TmpRuleSetEvent in ruleSetLog) { if (TmpRuleSetEvent.Event != null) { poRuleTreeReport.RuleSetIds.Add(TmpRuleSetEvent.Event.RuleSetId); } } } if (ruleLog.Count > 0) { foreach (EventLog <CallRuleEvent> TmpRuleEvent in ruleLog) { if (TmpRuleEvent.Event != null) { poRuleTreeReport.RuleIds.Add(TmpRuleEvent.Event.RuleId); // TmpRuleEvent.Event.RuleType } } } if (ruleSetErrLog.Count > 0) { foreach (EventLog <RuleSetErrorEvent> TmpRuleSetError in ruleSetErrLog) { if (TmpRuleSetError.Event != null) { if (TmpRuleSetError.Event.SevereFailure) { poRuleTreeReport.RuleSetFailures.Add(TmpRuleSetError.Event.RuleSetId); } else { poRuleTreeReport.RuleSetWarnings.Add(TmpRuleSetError.Event.RuleSetId); } } } } if (poRulesEngine.AllRuleSets != null) { foreach (string sTmpCustomId in poRuleTreeReport.RuleSetFailures) { WonkaBizRuleSet FoundRuleSet = poRulesEngine.AllRuleSets.Where(x => x.CustomId == sTmpCustomId).FirstOrDefault(); if (!String.IsNullOrEmpty(FoundRuleSet.CustomId)) { poRuleTreeReport.RuleSetFailMessages[FoundRuleSet.CustomId] = FoundRuleSet.CustomFailureMsg; } } } }