public virtual bool Orchestrate(ICommand instance, bool pbSimulationMode)
        {
            bool bValid = true;

            var contract = GetContract(moInitData.BlockchainEngine);

            var callRuleTreeEvent = contract.GetEvent(CONST_EVENT_CALL_RULE_TREE);
            var callRuleSetEvent  = contract.GetEvent(CONST_EVENT_CALL_RULE_SET);
            var callRuleEvent     = contract.GetEvent(CONST_EVENT_CALL_RULE);

            var filterCRTAll = callRuleTreeEvent.CreateFilterAsync().Result;
            var filterCRSAll = callRuleSetEvent.CreateFilterAsync().Result;
            var filterCRAll  = callRuleEvent.CreateFilterAsync().Result;

            var gas = new Nethereum.Hex.HexTypes.HexBigInteger(2000000);

            var executeWithReportFunction    = contract.GetFunction(CONST_CONTRACT_FUNCTION_EXEC_RPT);
            var executeGetLastReportFunction = contract.GetFunction(CONST_CONTRACT_FUNCTION_GET_LAST_RPT);

            WonkaRuleTreeReport ruleTreeReport = new WonkaRuleTreeReport();

            if (pbSimulationMode)
            {
                // Now, we get a full report on the execution of the rules engine, including the possibility of any failures
                ruleTreeReport = executeWithReportFunction.CallDeserializingToObjectAsync <WonkaRuleTreeReport>(moInitData.BlockchainEngine.SenderAddress, gas, null, moInitData.BlockchainEngine.SenderAddress).Result;
            }
            else
            {
                // Next, we execute the rules engine within a transaction, so that the any persistence will actually change the state of the blockchain
                var receiptAddAttribute =
                    executeWithReportFunction.SendTransactionAsync(moInitData.BlockchainEngineOwner, gas, null, moInitData.BlockchainEngine.SenderAddress).Result;

                // Now, we get a full report on the execution of the rules engine, including the possibility of any failures
                ruleTreeReport = executeGetLastReportFunction.CallDeserializingToObjectAsync <WonkaRuleTreeReport>().Result;
            }

            // Finally, we handle any events that have been issued during the execution of the rules engine
            // HandleEvents(callRuleTreeEvent, callRuleSetEvent, callRuleEvent, filterCRTAll, filterCRSAll, filterCRAll);

            if (ruleTreeReport.NumberOfRuleFailures <= 0)
            {
                bValid = true;
            }
            else
            {
                throw new WonkaOrchestratorException(ruleTreeReport);
            }

            return(bValid);
        }
Example #2
0
 public WonkaOrchestratorException(WonkaRuleTreeReport poReport)
 {
     RuleTreeReport = poReport;
 }