コード例 #1
0
        private WonkaRefEnvironment Init(IMetadataRetrievable piMetadataSource)
        {
            WonkaRefEnvironment RefEnv = null;

            try
            {
                RefEnv = WonkaRefEnvironment.GetInstance();
            }
            catch (Exception ex)
            {
                RefEnv = WonkaRefEnvironment.CreateInstance(false, piMetadataSource);
            }

            this.CurrentProductOnDB = null;
            this.TempDirectory      = "C:\tmp";
            this.RetrieveCurrRecord = null;
            this.TransactionState   = null;

            GroveId       = RegistrationId = "";
            GroveIndex    = 0;
            StdOpMap      = new Dictionary <STD_OP_TYPE, RetrieveStdOpValDelegate>();
            SourceMap     = new Dictionary <string, WonkaBreSource>();
            CustomOpMap   = new Dictionary <string, WonkaBreSource>();
            DefaultSource = "";

            OnSuccessTriggers = new List <ISuccessTrigger>();
            OnFailureTriggers = new List <IFailureTrigger>();

            return(RefEnv);
        }
コード例 #2
0
ファイル: WonkaCQSTest.cs プロジェクト: ranjancse26/Wonka
        public WonkaCQSTest(string psSenderAddress, string psPassword, string psContractAddress = null)
        {
            var TmpAssembly = Assembly.GetExecutingAssembly();

            // Read the ABI of the Ethereum contract for the Wonka rules engine and holds our data record
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.abi")))
            {
                msAbiWonka = AbiReader.ReadToEnd();
            }

            // Read the XML markup that lists the business rules (i.e., the RuleTree)
            using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.SimpleAccountCheck.xml")))
            {
                msRulesContents = RulesReader.ReadToEnd();
            }

            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment RefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            msSenderAddress = psSenderAddress;
            msPassword      = psPassword;

            if (psContractAddress == null)
            {
                msContractAddress = DeployContract();
            }
            else
            {
                msContractAddress = psContractAddress;
            }

            // Finally we serialize the data domain to the blockchain
            RefEnv.Serialize(msSenderAddress, msPassword, msSenderAddress, msContractAddress, msAbiWonka);
        }
コード例 #3
0
        public void Execute()
        {
            WonkaRefEnvironment RefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            WonkaRefAttr AccountStsAttr = RefEnv.GetAttributeByAttrName("AccountStatus");

            WonkaProduct NewProduct = GetNewProduct();

            string sStatusValueBefore = GetAttributeValue(NewProduct, AccountStsAttr);

            /*
             * NOT YET READY
             *
             * // Cue the rules engine
             * WonkaBreRulesEngine RulesEngine =
             *  new WonkaBreRulesEngine(CONST_SIMPLE_RULES_FILEPATH, moMetadataSource);
             *
             * RulesEngine.GetCurrentProductDelegate = GetOldProduct;
             *
             * WonkaBre.Reporting.WonkaBreRuleTreeReport Report = RulesEngine.Validate(NewProduct);
             *
             * string sStatusValueAfter = GetAttributeValue(NewProduct, AccountStsAttr);
             *
             * if (Report.GetRuleSetFailureCount() > 0)
             * {
             *  throw new Exception("Oh heavens to Betsy! Something bad happened!");
             * }
             */
        }
コード例 #4
0
        private void Init(IMetadataRetrievable piMetadataSource)
        {
            this.RuleSetIdCounter  = 0;
            this.RuleIdCounter     = 0;
            this.ValSeqIdCounter   = 0;
            this.CustomOpSources   = new Dictionary <string, WonkaBizSource>();
            this.AllParsedRuleSets = new List <WonkaBizRuleSet>();

            this.BasicOps = new HashSet <string>();
            this.BasicOps.Add(CONST_BASIC_OP_NOT_POP);
            this.BasicOps.Add(CONST_BASIC_OP_POP);
            this.BasicOps.Add(CONST_BASIC_OP_NOT_EQ);
            this.BasicOps.Add(CONST_BASIC_OP_EQ);
            this.BasicOps.Add(CONST_BASIC_OP_NOT_IN);
            this.BasicOps.Add(CONST_BASIC_OP_IN);
            this.BasicOps.Add(CONST_BASIC_OP_EXISTS_AS);
            this.BasicOps.Add(CONST_BASIC_OP_DEFAULT);
            this.BasicOps.Add(CONST_BASIC_OP_ASSIGN_SUM);
            this.BasicOps.Add(CONST_BASIC_OP_ASSIGN_DIFF);
            this.BasicOps.Add(CONST_BASIC_OP_ASSIGN_PROD);
            this.BasicOps.Add(CONST_BASIC_OP_ASSIGN);

            this.ArithmeticLimitOps = new HashSet <string>();
            this.ArithmeticLimitOps.Add(CONST_AL_GT);
            this.ArithmeticLimitOps.Add(CONST_AL_NOT_GT);
            this.ArithmeticLimitOps.Add(CONST_AL_LT);
            this.ArithmeticLimitOps.Add(CONST_AL_NOT_LT);
            this.ArithmeticLimitOps.Add(CONST_AL_GE);
            this.ArithmeticLimitOps.Add(CONST_AL_NOT_GE);
            this.ArithmeticLimitOps.Add(CONST_AL_LE);
            this.ArithmeticLimitOps.Add(CONST_AL_NOT_LE);
            this.ArithmeticLimitOps.Add(CONST_AL_EQ);
            this.ArithmeticLimitOps.Add(CONST_AL_NOT_EQ);

            this.DateLimitOps = new HashSet <string>();
            this.DateLimitOps.Add(CONST_DL_IB);
            this.DateLimitOps.Add(CONST_DL_NOT_IB);
            this.DateLimitOps.Add(CONST_DL_IA);
            this.DateLimitOps.Add(CONST_DL_NOT_IA);
            this.DateLimitOps.Add(CONST_DL_ALMOST);

            // NOTE: Will be implemented later, with a defined plan
            // DateLimitOps.Add(CONST_DL_AROUND);

            if (piMetadataSource != null)
            {
                try
                {
                    WonkaRefEnvironment.GetInstance();
                }
                catch (Exception ex)
                {
                    WonkaRefEnvironment.CreateInstance(false, piMetadataSource);
                }
            }
        }
コード例 #5
0
ファイル: WonkaBreXmlReader.cs プロジェクト: anegg0/Wonka
        private void Init(IMetadataRetrievable piMetadataSource)
        {
            RuleSetIdCounter  = 0;
            RuleIdCounter     = 0;
            ValSeqIdCounter   = 0;
            CustomOpSources   = new Dictionary <string, WonkaBreSource>();
            AllParsedRuleSets = new List <WonkaBreRuleSet>();

            BasicOps = new HashSet <string>();
            BasicOps.Add(CONST_BASIC_OP_NOT_POP);
            BasicOps.Add(CONST_BASIC_OP_POP);
            BasicOps.Add(CONST_BASIC_OP_NOT_EQ);
            BasicOps.Add(CONST_BASIC_OP_EQ);
            BasicOps.Add(CONST_BASIC_OP_NOT_IN);
            BasicOps.Add(CONST_BASIC_OP_IN);
            BasicOps.Add(CONST_BASIC_OP_EXISTS_AS);
            BasicOps.Add(CONST_BASIC_OP_DEFAULT);
            BasicOps.Add(CONST_BASIC_OP_ASSIGN_SUM);
            BasicOps.Add(CONST_BASIC_OP_ASSIGN_DIFF);
            BasicOps.Add(CONST_BASIC_OP_ASSIGN_PROD);
            BasicOps.Add(CONST_BASIC_OP_ASSIGN);

            ArithmeticLimitOps = new HashSet <string>();
            ArithmeticLimitOps.Add(CONST_AL_GT);
            ArithmeticLimitOps.Add(CONST_AL_NOT_GT);
            ArithmeticLimitOps.Add(CONST_AL_LT);
            ArithmeticLimitOps.Add(CONST_AL_NOT_LT);
            ArithmeticLimitOps.Add(CONST_AL_GE);
            ArithmeticLimitOps.Add(CONST_AL_NOT_GE);
            ArithmeticLimitOps.Add(CONST_AL_LE);
            ArithmeticLimitOps.Add(CONST_AL_NOT_LE);
            ArithmeticLimitOps.Add(CONST_AL_EQ);
            ArithmeticLimitOps.Add(CONST_AL_NOT_EQ);

            DateLimitOps = new HashSet <string>();
            DateLimitOps.Add(CONST_DL_IB);
            DateLimitOps.Add(CONST_DL_NOT_IB);
            DateLimitOps.Add(CONST_DL_IA);
            DateLimitOps.Add(CONST_DL_NOT_IA);

            if (piMetadataSource != null)
            {
                try
                {
                    WonkaRefEnvironment.GetInstance();
                }
                catch (Exception ex)
                {
                    WonkaRefEnvironment.CreateInstance(false, piMetadataSource);
                }
            }
        }
コード例 #6
0
ファイル: WonkaRefExtensions.cs プロジェクト: crazyants/Wonka
        /// <summary>
        ///
        /// This method will deserialize the data domain of the WonkaRevEnvironment from a provided string.
        ///
        /// <param name="poDataDomainPayload">The string payload that needs to be deserialized</param>
        /// <returns>The WonkaRefEnvironment instantiated from the data domain file</returns>
        /// </summary>
        public static WonkaRefEnvironment DeserializeRefEnvFromStringPayload(this string psDataDomainPayload)
        {
            WonkaRefEnvironment RefEnv = null;

            if (String.IsNullOrEmpty(psDataDomainPayload))
            {
                throw new WonkaRefException("ERROR!  Reference to data domain payload is invalid.");
            }

            RefEnv = WonkaRefEnvironment.CreateInstance(false, new WonkaRefDeserializeLocalSource(psDataDomainPayload));

            return(RefEnv);
        }
コード例 #7
0
        public WonkaSimpleNethereumTest(string psSenderAddress, string psPassword, string psContractAddress)
        {
            msSenderAddress   = psSenderAddress;
            msPassword        = psPassword;
            msContractAddress = psContractAddress;

            // Create an instance of the class that will provide us with PmdRefAttributes (i.e., the data domain)
            // that define our data records
            moMetadataSource = new WonkaMetadataTestSource();

            var TmpAssembly = Assembly.GetExecutingAssembly();

            // Read the ABI of the Ethereum contract which holds our old (i.e., existing) data record
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.abi")))
            {
                msAbiWonka = AbiReader.ReadToEnd();
            }

            // Read the bytecodes of the Ethereum contract which holds our old (i.e., existing) data record
            using (var ByteCodeReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.bin")))
            {
                msByteCodeWonka = ByteCodeReader.ReadToEnd();
            }

            // Read the XML markup that lists the business rules
            using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.SimpleAccountCheck.xml")))
            {
                msRulesContents = RulesReader.ReadToEnd();
            }

            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment WonkaRefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            WonkaRefAttr AccountIDAttr       = WonkaRefEnv.GetAttributeByAttrName("BankAccountID");
            WonkaRefAttr AccountNameAttr     = WonkaRefEnv.GetAttributeByAttrName("BankAccountName");
            WonkaRefAttr AccountStsAttr      = WonkaRefEnv.GetAttributeByAttrName("AccountStatus");
            WonkaRefAttr AccountCurrValAttr  = WonkaRefEnv.GetAttributeByAttrName("AccountCurrValue");
            WonkaRefAttr AccountTypeAttr     = WonkaRefEnv.GetAttributeByAttrName("AccountType");
            WonkaRefAttr AccountCurrencyAttr = WonkaRefEnv.GetAttributeByAttrName("AccountCurrency");

            // We create a target list of the Attributes of the old (i.e., existing) record that currently exists on the blockchain
            // and which we want to pull back during the engine's execution
            moTargetAttrList = new List <WonkaRefAttr>();

            moTargetAttrList =
                new List <WonkaRefAttr>()
            {
                AccountIDAttr, AccountNameAttr, AccountStsAttr, AccountCurrValAttr, AccountTypeAttr, AccountCurrencyAttr
            };
        }
コード例 #8
0
        private void Init(T poCommand, OrchestrationInitData poOrchInitData)
        {
            WonkaRefEnvironment WonkaRefEnv = null;

            if (poOrchInitData == null)
            {
                throw new WonkaOrchestratorException("ERROR!  Initialization for orchestration has not been provided.");
            }

            if (poOrchInitData.AttributesMetadataSource == null)
            {
                throw new WonkaOrchestratorException("ERROR!  Initialization data for metadata retrieval has not been provided.");
            }

            if ((poOrchInitData.BlockchainDataSources == null) || (poOrchInitData.BlockchainDataSources.Count == 0))
            {
                if (poOrchInitData.DefaultBlockchainDataSource != null)
                {
                    Dictionary <string, WonkaBizSource> BlockchainDataSources = new Dictionary <string, WonkaBizSource>();

                    Dictionary <PropertyInfo, WonkaRefAttr> PropMap = poCommand.GetPropertyMap();

                    // Set Commentary Attributes
                    foreach (PropertyInfo TmpProperty in PropMap.Keys)
                    {
                        WonkaRefAttr TempAttr = PropMap[TmpProperty];

                        BlockchainDataSources[TempAttr.AttrName] = poOrchInitData.DefaultBlockchainDataSource;
                    }

                    poOrchInitData.BlockchainDataSources = BlockchainDataSources;
                }
            }

            if ((poOrchInitData.BlockchainDataSources == null) || (poOrchInitData.BlockchainDataSources.Count == 0))
            {
                throw new WonkaOrchestratorException("ERROR!  Initialization for data retrieval metadata has not been provided.");
            }

            try
            {
                WonkaRefEnv = WonkaRefEnvironment.GetInstance();
            }
            catch (Exception ex)
            {
                WonkaRefEnv = WonkaRefEnvironment.CreateInstance(false, poOrchInitData.AttributesMetadataSource);

                // NOTE: Should/could contract be deployed here along with metadata (i.e., Attributes)?
            }
        }
コード例 #9
0
        public BasicWonkaTests()
        {
            var metadataSource =
                new Wonka.BizRulesEngine.Samples.WonkaBreMetadataTestSource();

            _refEnvHandle = WonkaRefEnvironment.CreateInstance(false, metadataSource);

            using (var client = new System.Net.Http.HttpClient())
            {
                var sIpfsUrl       = String.Format("{0}/{1}", CONST_INFURA_IPFS_GATEWAY_URL, "QmXcsGDQthxbGW8C3Sx9r4tV9PGSj4MxJmtXF7dnXN5XUT");
                var sRulesContents = client.GetStringAsync(sIpfsUrl).Result;

                _rulesEngine = new WonkaBizRulesEngine(new StringBuilder(sRulesContents), metadataSource);
            }

            _client = new Mock <IOrchestrate>();
        }
コード例 #10
0
ファイル: WonkaRefExtensions.cs プロジェクト: crazyants/Wonka
        /// <summary>
        ///
        /// This method will deserialize the data domain of the WonkaRevEnvironment from a local file.
        ///
        /// <param name="poDataDomainFile">The file location where the data domain exists to be deserialized</param>
        /// <returns>The WonkaRefEnvironment instantiated from the data domain file</returns>
        /// </summary>
        public static WonkaRefEnvironment DeserializeRefEnvFromLocalFile(this FileInfo poDataDomainFile)
        {
            WonkaRefEnvironment RefEnv = null;

            if (poDataDomainFile == null)
            {
                throw new WonkaRefException("ERROR!  Reference to data domain file is invalid.");
            }

            if (!poDataDomainFile.Exists)
            {
                throw new WonkaRefException("ERROR!  Data domain file does not exist.");
            }

            RefEnv = WonkaRefEnvironment.CreateInstance(false, new WonkaRefDeserializeLocalSource(poDataDomainFile));

            return(RefEnv);
        }
コード例 #11
0
        private async Task <bool> Init()
        {
            bool bResult = true;

            if (String.IsNullOrEmpty(msRulesContents))
            {
                msRulesContents = CONST_DEFAULT_WONKA_DEFI_RULES;
            }

            if (moMetadataSource == null)
            {
                moMetadataSource = new WonkaDeFiDefaultMetadata();
            }

            WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            await InitEngineAsync(mbInitChainEnv).ConfigureAwait(false);

            return(bResult);
        }
コード例 #12
0
        public WonkaNoviceOnlineChainTestAsync(string psContractAddress, bool pbInitChainEnv = true)
        {
            msSenderAddress = "0x12890D2cce102216644c59daE5baed380d84830c";
            msPassword      = "******";

            mbInitChainEnv    = pbInitChainEnv;
            msContractAddress = psContractAddress;

            msAbiWonka         = WonkaEth.Autogen.WonkaEngine.WonkaEngineDeployment.ABI;
            msByteCodeWonka    = WonkaEth.Autogen.WonkaEngine.WonkaEngineDeployment.BYTECODE;
            msAbiRegistry      = WonkaEth.Autogen.WonkaRegistry.WonkaRegistryDeployment.ABI;
            msByteCodeRegistry = WonkaEth.Autogen.WonkaRegistry.WonkaRegistryDeployment.BYTECODE;
            msAbiOrchTest      = WonkaEth.Autogen.WonkaTestContract.WonkaTestContractDeployment.ABI;
            msByteCodeOrchTest = WonkaEth.Autogen.WonkaTestContract.WonkaTestContractDeployment.BYTECODE;

            // Create an instance of the class that will provide us with PmdRefAttributes (i.e., the data domain)
            // that define our data record
            moMetadataSource = new WonkaBre.Samples.WonkaBreMetadataTestSource();
            WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            moProduct = GetNewProduct();
        }
コード例 #13
0
        private void WonkaRibbon_Load(object sender, RibbonUIEventArgs e)
        {
            refEnvHandle =
                WonkaRefEnvironment.CreateInstance(false, metadataSource);

            WonkaRefAttr AccountIDAttr       = refEnvHandle.GetAttributeByAttrName("BankAccountID");
            WonkaRefAttr AccountNameAttr     = refEnvHandle.GetAttributeByAttrName("BankAccountName");
            WonkaRefAttr AccountStsAttr      = refEnvHandle.GetAttributeByAttrName("AccountStatus");
            WonkaRefAttr AccountCurrValAttr  = refEnvHandle.GetAttributeByAttrName("AccountCurrValue");
            WonkaRefAttr AccountTypeAttr     = refEnvHandle.GetAttributeByAttrName("AccountType");
            WonkaRefAttr AccountCurrencyAttr = refEnvHandle.GetAttributeByAttrName("AccountCurrency");
            WonkaRefAttr RvwFlagAttr         = refEnvHandle.GetAttributeByAttrName("AuditReviewFlag");
            WonkaRefAttr CreationDtAttr      = refEnvHandle.GetAttributeByAttrName("CreationDt");

            using (var client = new System.Net.Http.HttpClient())
            {
                wonkaRules = client.GetStringAsync(currRulesUrl).Result;
            }

            rulesEngine =
                new WonkaBizRulesEngine(new StringBuilder(wonkaRules));
        }
コード例 #14
0
        private WonkaEthRulesEngine AssembleWonkaEthEngine(string psWonkaRules)
        {
            refEnvHandle =
                WonkaRefEnvironment.CreateInstance(false, metadataSource);

            string sContractAddr  = "";
            string sContractABI   = "";
            string sGetMethodName = "";
            string sSetMethodName = "";

            WonkaBizSource.RetrieveDataMethod retrieveMethod = null;

            var SourceMap = new Dictionary <string, WonkaBizSource>();

            foreach (var TmpAttr in refEnvHandle.AttrCache)
            {
                var TmpSource =
                    new WonkaBizSource(TmpAttr.AttrName,
                                       CONST_ACCT_PUBLIC_KEY,
                                       CONST_ACCT_PASSWORD,
                                       sContractAddr,
                                       sContractABI,
                                       sGetMethodName,
                                       sSetMethodName,
                                       retrieveMethod);

                SourceMap[TmpAttr.AttrName] = TmpSource;
            }

            WonkaEthEngineInitialization EngineInit =
                new WonkaEthEngineInitialization()
            {
                EthSenderAddress = CONST_ACCT_PUBLIC_KEY,
                EthPassword      = CONST_ACCT_PASSWORD,
                Web3HttpUrl      = CONST_TEST_INFURA_URL
            };

            return(new WonkaEthRulesEngine(new StringBuilder(psWonkaRules), SourceMap, EngineInit, metadataSource, false));
        }
コード例 #15
0
        public WonkaERC20Service(string psSenderAddress,
                                 string psPassword,
                                 string psContractAddress,
                                 string psRulesContentsHttpUrl,
                                 IMetadataRetrievable poMetadata = null,
                                 Dictionary <string, WonkaBizSource> poSourceMap = null,
                                 bool pbInitChainEnv  = false,
                                 string psWeb3HttpUrl = null)
        {
            msSenderAddress = psSenderAddress;
            msPassword      = psPassword;
            msWeb3HttpUrl   = psWeb3HttpUrl;

            mbInitChainEnv    = pbInitChainEnv;
            msContractAddress = psContractAddress;

            // Create an instance of the class that will provide us with PmdRefAttributes (i.e., the data domain)
            // that define our data record, if one is not provided
            if (poMetadata != null)
            {
                moMetadataSource = poMetadata;
            }

            moSourceMap = poSourceMap;

            if (!String.IsNullOrEmpty(psRulesContentsHttpUrl))
            {
                using (var client = new System.Net.Http.HttpClient())
                {
                    msRulesContents = client.GetStringAsync(psRulesContentsHttpUrl).Result;
                }
            }

            WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            var bInitSuccess = Init().Result;
        }
コード例 #16
0
ファイル: WonkaSimpleTest.cs プロジェクト: anegg0/Wonka
        public void Execute()
        {
            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment RefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            // To test whether the data domain has been created, we pull back one attribute
            WonkaRefAttr AccountStsAttr = RefEnv.GetAttributeByAttrName("AccountStatus");

            // Creating an instance of the rules engine using our rules and the metadata
            WonkaBreRulesEngine RulesEngine =
                new WonkaBreRulesEngine(new StringBuilder(msRulesContents), moMetadataSource);

            // Gets a predefined data record that will be our analog for new data coming into the system
            WonkaProduct NewProduct = GetNewProduct();

            // Check that the data has been populated correctly on the "new" record
            string sStatusValueBefore = GetAttributeValue(NewProduct, AccountStsAttr);

            // Since the rules can reference values from different records (like O.Price for the existing
            // record's price and N.Price for the new record's price), we need to provide the delegate
            // that can pull the existing (i.e., old) record using a key
            RulesEngine.GetCurrentProductDelegate = GetOldProduct;

            // Validate the new record using our rules engine and its initialized RuleTree
            WonkaBre.Reporting.WonkaBreRuleTreeReport Report = RulesEngine.Validate(NewProduct);

            // Now retrieve the AccountStatus value and see if the rules have altered it (which should
            // not be the case)
            string sStatusValueAfter = GetAttributeValue(NewProduct, AccountStsAttr);

            if (Report.GetRuleSetFailureCount() > 0)
            {
                throw new Exception("Oh heavens to Betsy! Something bad happened!");
            }
        }
コード例 #17
0
        private void Init()
        {
            WonkaRefEnvironment WonkaRefEnv = null;

            try
            {
                WonkaRefEnv = WonkaRefEnvironment.GetInstance();
            }
            catch (Exception ex)
            {
                WonkaRefEnv = WonkaRefEnvironment.CreateInstance(false, new WonkaMetadataTestSource());

                // NOTE: Should/could contract be deployed here along with metadata (i.e., Attributes)?

                /*
                 * WonkaRefAttr AccountIDAttr       = WonkaRefEnv.GetAttributeByAttrName("BankAccountID");
                 * WonkaRefAttr AccountNameAttr     = WonkaRefEnv.GetAttributeByAttrName("BankAccountName");
                 * WonkaRefAttr AccountStsAttr      = WonkaRefEnv.GetAttributeByAttrName("AccountStatus");
                 * WonkaRefAttr AccountCurrValAttr  = WonkaRefEnv.GetAttributeByAttrName("AccountCurrValue");
                 * WonkaRefAttr AccountTypeAttr     = WonkaRefEnv.GetAttributeByAttrName("AccountType");
                 * WonkaRefAttr AccountCurrencyAttr = WonkaRefEnv.GetAttributeByAttrName("AccountCurrency");
                 */
            }
        }
コード例 #18
0
ファイル: WonkaCQSOrchTest.cs プロジェクト: ranjancse26/Wonka
        // This constructor will be called in the case that we wish to initialize the framework
        // with provided parameters
        public WonkaCQSOrchTest(string psSenderAddress, string psPassword, string psWonkaContractAddress, string psOrchContractAddress)
        {
            var TmpAssembly = Assembly.GetExecutingAssembly();

            moAttrSourceMap = new Dictionary <string, WonkaBizSource>();
            moCustomOpMap   = new Dictionary <string, WonkaBizSource>();

            // Read the ABI of the Ethereum contract for the Wonka rules engine
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.abi")))
            {
                msAbiWonka = AbiReader.ReadToEnd();
            }

            // Read the ABI of the Ethereum contract that will demonstrate both our Custom Operator functionality and our Orchestration functionality
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.OrchTest.abi")))
            {
                msAbiOrchContract = AbiReader.ReadToEnd();
            }

            // Read the XML markup that lists the business rules
            using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.VATCalculationExample.xml")))
            {
                msRulesContents = RulesReader.ReadToEnd();
            }

            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment RefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            msSenderAddress = psSenderAddress;
            msPassword      = psPassword;

            moMetadataSource = new WonkaMetadataTestSource();

            if (psWonkaContractAddress == null)
            {
                msWonkaContractAddress = DeployWonkaContract();
            }
            else
            {
                msWonkaContractAddress = psWonkaContractAddress;
            }

            if (psOrchContractAddress == null)
            {
                msOrchContractAddress = DeployOrchestrationContract();
            }
            else
            {
                msOrchContractAddress = psOrchContractAddress;
            }

            // Serialize the data domain to the blockchain
            RefEnv.Serialize(msSenderAddress, msPassword, msSenderAddress, msWonkaContractAddress, msAbiWonka);

            moDefaultSource =
                new WonkaBizSource(CONST_ORCH_CONTRACT_MARKUP_ID,
                                   msSenderAddress,
                                   msPassword,
                                   psOrchContractAddress,
                                   msAbiOrchContract,
                                   CONST_ORCH_CONTRACT_GET_METHOD,
                                   CONST_ORCH_CONTRACT_SET_METHOD,
                                   RetrieveValueMethod);

            // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
            // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
            foreach (WonkaRefAttr TempAttr in RefEnv.AttrCache)
            {
                moAttrSourceMap[TempAttr.AttrName] = moDefaultSource;
            }

            Dictionary <string, WonkaBizSource> CustomOpSourceMap = new Dictionary <string, WonkaBizSource>();

            // Here a mapping is created, where each Custom Operator points to a specific contract and its "implementation" method
            // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
            WonkaBizSource CustomOpSource =
                new WonkaBizSource(CONST_CUSTOM_OP_MARKUP_ID,
                                   msSenderAddress,
                                   msPassword,
                                   psOrchContractAddress,
                                   msAbiOrchContract,
                                   LookupVATDenominator,
                                   CONST_CUSTOM_OP_CONTRACT_METHOD);

            moCustomOpMap[CONST_CUSTOM_OP_MARKUP_ID] = CustomOpSource;
        }
コード例 #19
0
        public WonkaSimpleCustomOpsTest(string psSenderAddress, string psPassword, string psContractAddress, bool pbSerializeMetadataToBlockchain = true)
        {
            msSenderAddress   = psSenderAddress;
            msPassword        = psPassword;
            msContractAddress = psContractAddress;

            // Create an instance of the class that will provide us with PmdRefAttributes (i.e., the data domain)
            // that define our data record
            moMetadataSource = new WonkaMetadataVATSource();

            var TmpAssembly = Assembly.GetExecutingAssembly();

            // Read the ABI of the Ethereum contract for the Wonka rules engine
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.abi")))
            {
                msAbiWonka = AbiReader.ReadToEnd();
            }

            // Read the bytecodes of the Ethereum contract for the Wonka rules engine
            using (var ByteCodeReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.bin")))
            {
                msByteCodeWonka = ByteCodeReader.ReadToEnd();
            }

            // Read the ABI of the Ethereum contract that will demonstrate both our Custom Operator functionality and our Orchestration functionality
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.OrchTest.abi")))
            {
                msAbiOrchTest = AbiReader.ReadToEnd();
            }

            // Read the bytecodes of the Ethereum contract that will hold our data record and provide Custom Operator functionality
            using (var ByteCodeReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.OrchTest.bin")))
            {
                msByteCodeOrchTest = ByteCodeReader.ReadToEnd();
            }

            // Read the XML markup that lists the business rules
            using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.VATCalculationExample.xml")))
            {
                msRulesContents = RulesReader.ReadToEnd();
            }

            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment WonkaRefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            WonkaRefAttr NewSalesTransSeqAttr    = WonkaRefEnv.GetAttributeByAttrName("NewSalesTransSeq");
            WonkaRefAttr NewSaleVATRateDenomAttr = WonkaRefEnv.GetAttributeByAttrName("NewSaleVATRateDenom");
            WonkaRefAttr NewSaleItemTypeAttr     = WonkaRefEnv.GetAttributeByAttrName("NewSaleItemType");
            WonkaRefAttr CountryOfSaleAttr       = WonkaRefEnv.GetAttributeByAttrName("CountryOfSale");
            WonkaRefAttr NewSalePriceAttr        = WonkaRefEnv.GetAttributeByAttrName("NewSalePrice");
            WonkaRefAttr PrevSellTaxAmountAttr   = WonkaRefEnv.GetAttributeByAttrName("PrevSellTaxAmount");
            WonkaRefAttr NewSellTaxAmountAttr    = WonkaRefEnv.GetAttributeByAttrName("NewSellTaxAmount");
            WonkaRefAttr NewVATAmountForHMRCAttr = WonkaRefEnv.GetAttributeByAttrName("NewVATAmountForHMRC");
            WonkaRefAttr NewSaleEANAttr          = WonkaRefEnv.GetAttributeByAttrName("NewSaleEAN");

            // We create a target list of the Attributes of the old (i.e., existing) record that currently exists on the blockchain
            // and which we want to pull back during the engine's execution
            moTargetAttrList = new List <WonkaRefAttr>();

            moTargetAttrList =
                new List <WonkaRefAttr>()
            {
                NewSalesTransSeqAttr, NewSaleVATRateDenomAttr, NewSaleItemTypeAttr,
                CountryOfSaleAttr, NewSalePriceAttr, PrevSellTaxAmountAttr,
                NewSellTaxAmountAttr, NewVATAmountForHMRCAttr, NewSaleEANAttr
            };

            if (pbSerializeMetadataToBlockchain)
            {
                SerializeMetadataToBlockchain();
            }
        }
コード例 #20
0
        public WonkaNoviceOnlineChainTest(string psContractAddress, bool pbInitChainEnv = true, bool pbRetrieveMarkupFromIpfs = false)
        {
            msSenderAddress = "0x12890D2cce102216644c59daE5baed380d84830c";
            msPassword      = "******";

            msAbiWonka         = Wonka.Eth.Autogen.WonkaEngine.WonkaEngineDeploymentClassic.ABI;
            msByteCodeWonka    = Wonka.Eth.Autogen.WonkaEngine.WonkaEngineDeploymentClassic.BYTECODE;
            msAbiRegistry      = Wonka.Eth.Autogen.WonkaRegistry.WonkaRegistryDeployment.ABI;
            msByteCodeRegistry = Wonka.Eth.Autogen.WonkaRegistry.WonkaRegistryDeployment.BYTECODE;
            msAbiOrchTest      = Wonka.Eth.Autogen.WonkaTestContract.WonkaTestContractDeployment.ABI;
            msByteCodeOrchTest = Wonka.Eth.Autogen.WonkaTestContract.WonkaTestContractDeployment.BYTECODE;

            // Create an instance of the class that will provide us with PmdRefAttributes (i.e., the data domain)
            // that define our data record
            moMetadataSource = new Wonka.BizRulesEngine.Samples.WonkaBreMetadataTestSource();
            WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            // NOTE: As a reminder, you must have a IPFS daemon configured and running (perhaps on your machine)
            // in order for the Ipfs.Api to work successfully
            if (pbRetrieveMarkupFromIpfs)
            {
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    string sIpfsUrl = String.Format("{0}/{1}", CONST_INFURA_IPFS_GATEWAY_URL, "QmXcsGDQthxbGW8C3Sx9r4tV9PGSj4MxJmtXF7dnXN5XUT");

                    msRulesContents = client.DownloadString(sIpfsUrl);
                }
            }
            else
            {
                var TmpAssembly = Assembly.GetExecutingAssembly();

                // Read the XML markup that lists the business rules
                using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.SimpleAccountCheck.xml")))
                {
                    msRulesContents = RulesReader.ReadToEnd();
                }
            }

            // By setting the addresses to NULL, we indicates that we want the API to deploy the contracts for us
            if (psContractAddress == null)
            {
                msEngineContractAddress   = null;
                msRegistryContractAddress = null;
                msTestContractAddress     = null;
            }
            // By using the indicator "DEPLOY" here, we will manually deploy the contracts ourselves
            else if (psContractAddress == "DEPLOY")
            {
                msEngineContractAddress = DeployWonka();
            }
            // Else, we will use existing contracts on the test chain
            else
            {
                if (psContractAddress == "")
                {
                    msEngineContractAddress = "0xfB419DEA1f28283edAD89103fc1f1272f7573E6A";
                }
                else
                {
                    msEngineContractAddress = psContractAddress;
                }

                msRegistryContractAddress = "0x7E618a3948F6a5D2EA6b92D8Ce6723a468540CaA";
                msTestContractAddress     = "0x4092bc250ef6c384804af2f871Af9c679b672d0B";
            }

            Init(pbInitChainEnv);
        }
コード例 #21
0
        /// <summary>
        ///
        /// This method will initialize an instance of the Wonka.Net engine, using all the data provided.
        ///
        /// <returns>None</returns>
        /// </summary>
        public static async Task <bool> InitEngineAsync(this WonkaEthEngineInitialization poEngineInitData, bool pbRequireRetrieveValueMethod = true)
        {
            bool bResult = true;

            var EngineProps = poEngineInitData.Engine;

            if (EngineProps == null)
            {
                throw new Exception("ERROR!  No engine properties provided.");
            }

            if ((EngineProps.RulesEngine == null) && !String.IsNullOrEmpty(EngineProps.RulesMarkupXml))
            {
                if (pbRequireRetrieveValueMethod && (EngineProps.DotNetRetrieveMethod == null))
                {
                    throw new WonkaEthInitException("ERROR!  Retrieve method not provided for the Wonka.NET engine.", poEngineInitData);
                }

                if (EngineProps.MetadataSource == null)
                {
                    throw new WonkaEthInitException("ERROR!  No metadata source has been provided.", poEngineInitData);
                }

                // Using the metadata source, we create an instance of a defined data domain
                WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.CreateInstance(false, EngineProps.MetadataSource);

                // The old version of deployment, pushing out a contract with all methods (i.e., library)
                // bool bDeploySuccess = poEngineInitData.DeployContractsClassicAsync().Result;

                // The new version of deployment, pushing out the contract with a link to a library
                bool bDeploySuccess = poEngineInitData.DeployContractsAsync().Result;

                if (bDeploySuccess)
                {
                    if ((EngineProps.SourceMap == null) || (EngineProps.SourceMap.Count == 0))
                    {
                        EngineProps.SourceMap = new Dictionary <string, WonkaBizSource>();

                        // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
                        // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
                        foreach (WonkaRefAttr TempAttr in WonkaRefEnv.AttrCache)
                        {
                            WonkaBizSource TempSource =
                                new WonkaBizSource(poEngineInitData.StorageDefaultSourceId,
                                                   poEngineInitData.EthSenderAddress,
                                                   poEngineInitData.EthPassword,
                                                   poEngineInitData.StorageContractAddress,
                                                   poEngineInitData.StorageContractABI,
                                                   poEngineInitData.StorageGetterMethod,
                                                   poEngineInitData.StorageSetterMethod,
                                                   EngineProps.DotNetRetrieveMethod);

                            EngineProps.SourceMap[TempAttr.AttrName] = TempSource;
                        }
                    }

                    EngineProps.RulesEngine =
                        new WonkaBizRulesEngine(new StringBuilder(EngineProps.RulesMarkupXml), EngineProps.SourceMap, EngineProps.MetadataSource);

                    EngineProps.RulesEngine.DefaultSource = poEngineInitData.StorageDefaultSourceId;

                    //NOTE: These Ethereum ops will not currently execute correctly within .NET during Async mode, since the Wonka.NET must then also be refactored to execute in Async
                    //EngineProps.RulesEngine.SetDefaultStdOps(poEngineInitData.EthPassword, poEngineInitData.Web3HttpUrl);
                }
                else
                {
                    throw new Exception("ERROR!  Deployment of Wonka contracts has failed!");
                }
            }

            return(bResult);
        }
コード例 #22
0
        /// <summary>
        ///
        /// This method will initialize an instance of the Wonka.Net engine, using all the data provided.
        ///
        /// <returns>None</returns>
        /// </summary>
        public static async Task <bool> InitEngineAsync(this WonkaEthEngineInitialization poEngineInitData, bool pbRequireRetrieveValueMethod = true)
        {
            bool bResult = true;

            var EngineProps = poEngineInitData.Engine;

            if (EngineProps == null)
            {
                throw new Exception("ERROR!  No engine properties provided.");
            }

            if ((EngineProps.RulesEngine == null) && !String.IsNullOrEmpty(EngineProps.RulesMarkupXml))
            {
                if (pbRequireRetrieveValueMethod && (EngineProps.DotNetRetrieveMethod == null))
                {
                    throw new WonkaEthInitException("ERROR!  Retrieve method not provided for the Wonka.NET engine.", poEngineInitData);
                }

                if (EngineProps.MetadataSource == null)
                {
                    throw new WonkaEthInitException("ERROR!  No metadata source has been provided.", poEngineInitData);
                }

                // Using the metadata source, we create an instance of a defined data domain
                WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.CreateInstance(false, EngineProps.MetadataSource);

                var account = new Account(poEngineInitData.EthPassword);

                Nethereum.Web3.Web3 web3 = null;
                if (!String.IsNullOrEmpty(poEngineInitData.Web3HttpUrl))
                {
                    web3 = new Nethereum.Web3.Web3(account, poEngineInitData.Web3HttpUrl);
                }
                else
                {
                    web3 = new Nethereum.Web3.Web3(account);
                }

                if (String.IsNullOrEmpty(poEngineInitData.RulesEngineContractAddress))
                {
                    var EngineDeployment = new Autogen.WonkaEngine.WonkaEngineDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_ENGINE_CONTRACT_GAS_COST);

                    poEngineInitData.RulesEngineContractAddress =
                        await EngineDeployment.DeployContractAsync(web3, poEngineInitData.RulesEngineABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if (String.IsNullOrEmpty(poEngineInitData.RegistryContractAddress))
                {
                    var RegistryDeployment = new Autogen.WonkaRegistry.WonkaRegistryDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.RegistryContractAddress =
                        await RegistryDeployment.DeployContractAsync(web3, poEngineInitData.RegistryContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if (String.IsNullOrEmpty(poEngineInitData.StorageContractAddress))
                {
                    var TestContractDeployment = new Autogen.WonkaTestContract.WonkaTestContractDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.StorageContractAddress =
                        await TestContractDeployment.DeployContractAsync(web3, poEngineInitData.StorageContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if ((EngineProps.SourceMap == null) || (EngineProps.SourceMap.Count == 0))
                {
                    EngineProps.SourceMap = new Dictionary <string, WonkaBizSource>();

                    // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
                    // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
                    foreach (WonkaRefAttr TempAttr in WonkaRefEnv.AttrCache)
                    {
                        WonkaBizSource TempSource =
                            new WonkaBizSource(poEngineInitData.StorageDefaultSourceId,
                                               poEngineInitData.EthSenderAddress,
                                               poEngineInitData.EthPassword,
                                               poEngineInitData.StorageContractAddress,
                                               poEngineInitData.StorageContractABI,
                                               poEngineInitData.StorageGetterMethod,
                                               poEngineInitData.StorageSetterMethod,
                                               EngineProps.DotNetRetrieveMethod);

                        EngineProps.SourceMap[TempAttr.AttrName] = TempSource;
                    }
                }

                EngineProps.RulesEngine =
                    new WonkaBizRulesEngine(new StringBuilder(EngineProps.RulesMarkupXml), EngineProps.SourceMap, EngineProps.MetadataSource);

                EngineProps.RulesEngine.DefaultSource = poEngineInitData.StorageDefaultSourceId;

                //NOTE: These Ethereum ops will not currently execute correctly within .NET during Async mode, since the Wonka.NET must then also be refactored to execute in Async
                //EngineProps.RulesEngine.SetDefaultStdOps(poEngineInitData.EthPassword, poEngineInitData.Web3HttpUrl);
            }

            return(bResult);
        }
コード例 #23
0
ファイル: WonkaCQSOrchTest.cs プロジェクト: ranjancse26/Wonka
        // This constructor will be called in the case that we wish to initialize the framework
        // with configuration files locally (embedded resources, local filesystem, etc.)
        public WonkaCQSOrchTest()
        {
            moAttrSourceMap = new Dictionary <string, WonkaBizSource>();
            moCustomOpMap   = new Dictionary <string, WonkaBizSource>();

            var TmpAssembly = Assembly.GetExecutingAssembly();

            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment RefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            // Read the XML markup that lists the business rules (i.e., the RuleTree)
            using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.VATCalculationExample.xml")))
            {
                msRulesContents = RulesReader.ReadToEnd();
            }

            // Read the configuration file that contains all the initialization details regarding the rules engine
            // (like addresses of contracts, senders, passwords, etc.)
            using (var XmlReader = new System.IO.StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.VATCalculationExample.init.xml")))
            {
                string sInitXml = XmlReader.ReadToEnd();

                // We deserialize/parse the contents of the config file
                System.Xml.Serialization.XmlSerializer WonkaEthSerializer =
                    new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthInitialization),
                                                               new System.Xml.Serialization.XmlRootAttribute("Wonka.EthInitialization"));

                Wonka.Eth.Init.WonkaEthInitialization WonkaInit =
                    WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitXml)) as Wonka.Eth.Init.WonkaEthInitialization;

                // Here, any embeddeded resources mentioned in the config file (instead of simple file URLs) are accessed here
                WonkaInit.RetrieveEmbeddedResources(TmpAssembly);

                // The initialization data is transformed into a structure used by the Wonka.Eth namespace
                moOrchInitData = WonkaInit.TransformIntoOrchestrationInit(moMetadataSource);

                System.Console.WriteLine("Number of custom operators: (" + WonkaInit.CustomOperatorList.Length + ").");
            }

            // Read the configuration file that contains all the initialization details regarding the rules registry
            // (like Ruletree info, Grove info, etc.) - this information will allow us to add our RuleTree to the
            // Registry so that it can be discovered by users and so it can be added to a Grove (where it can be executed
            // as a member of a collection)
            using (var XmlReader = new System.IO.StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaRegistry.init.xml")))
            {
                string sInitRegistryXml = XmlReader.ReadToEnd();

                // We deserialize/parse the contents of the config file
                System.Xml.Serialization.XmlSerializer WonkaEthSerializer =
                    new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthRegistryInitialization),
                                                               new System.Xml.Serialization.XmlRootAttribute("Wonka.EthRegistryInitialization"));

                moWonkaRegistryInit =
                    WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitRegistryXml)) as Wonka.Eth.Init.WonkaEthRegistryInitialization;

                // Here, any embeddeded resources mentioned in the config file (instead of simple file URLs) are accessed here
                moWonkaRegistryInit.RetrieveEmbeddedResources(TmpAssembly);
            }

            // Here, we save all data from the config files to member properties
            // This region and the usage of member properties isn't necessary, but it's useful for debugging
            #region Set Class Member Variables
            msSenderAddress = moOrchInitData.BlockchainEngine.SenderAddress;
            msPassword      = moOrchInitData.BlockchainEngine.Password;

            if (moOrchInitData.BlockchainEngine.ContractAddress == null)
            {
                msWonkaContractAddress = DeployWonkaContract();
            }
            else
            {
                msWonkaContractAddress = moOrchInitData.BlockchainEngine.ContractAddress;
            }

            if (moOrchInitData.DefaultBlockchainDataSource.ContractAddress == null)
            {
                msOrchContractAddress = DeployOrchestrationContract();
            }
            else
            {
                msOrchContractAddress = moOrchInitData.DefaultBlockchainDataSource.ContractAddress;
            }

            msAbiWonka        = moOrchInitData.BlockchainEngine.ContractABI;
            msAbiOrchContract = moOrchInitData.DefaultBlockchainDataSource.ContractABI;

            moDefaultSource =
                new WonkaBizSource(moOrchInitData.DefaultBlockchainDataSource.SourceId,
                                   moOrchInitData.DefaultBlockchainDataSource.SenderAddress,
                                   moOrchInitData.DefaultBlockchainDataSource.Password,
                                   moOrchInitData.DefaultBlockchainDataSource.ContractAddress,
                                   moOrchInitData.DefaultBlockchainDataSource.ContractABI,
                                   moOrchInitData.DefaultBlockchainDataSource.MethodName,
                                   moOrchInitData.DefaultBlockchainDataSource.SetterMethodName,
                                   RetrieveValueMethod);

            foreach (WonkaRefAttr TempAttr in RefEnv.AttrCache)
            {
                moAttrSourceMap[TempAttr.AttrName] = moDefaultSource;
            }

            moCustomOpMap = moOrchInitData.BlockchainCustomOpFunctions;
            #endregion

            // We initialize the proxy that will be used to communicate with the Registry on the blockchain
            Wonka.Eth.Contracts.WonkaRuleTreeRegistry WonkaRegistry =
                Wonka.Eth.Contracts.WonkaRuleTreeRegistry.CreateInstance(moWonkaRegistryInit.BlockchainRegistry.ContractSender,
                                                                         moWonkaRegistryInit.BlockchainRegistry.ContractPassword,
                                                                         moWonkaRegistryInit.BlockchainRegistry.ContractAddress,
                                                                         moWonkaRegistryInit.BlockchainRegistry.ContractABI,
                                                                         moWonkaRegistryInit.Web3HttpUrl);

            // Here, the data domain is serialized to the blockchain for use by the RuleTree(s)
            RefEnv.Serialize(moOrchInitData.BlockchainEngineOwner, msPassword, msSenderAddress, msWonkaContractAddress, msAbiWonka, moOrchInitData.Web3HttpUrl);
        }
コード例 #24
0
ファイル: WonkaCQSOrchTest.cs プロジェクト: ranjancse26/Wonka
        // This constructor will be called in the case that we wish to initialize the framework
        // with configuration files that will be accessed through IPFS
        public WonkaCQSOrchTest(StringBuilder psPeerKeyId, string psRulesMarkupFile, string psRulesInitFile, string psRegistryInitFile)
        {
            moAttrSourceMap = new Dictionary <string, WonkaBizSource>();
            moCustomOpMap   = new Dictionary <string, WonkaBizSource>();

            var TmpAssembly = Assembly.GetExecutingAssembly();

            WonkaRefEnvironment RefEnv = WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            Wonka.IpfsW.WonkaIpfsEnvironment IpfsEnv = Wonka.IpfsW.WonkaIpfsEnvironment.CreateInstance();

            // Read the XML markup that lists the business rules
            msRulesContents = IpfsEnv.GetFile(psPeerKeyId.ToString(), psRulesMarkupFile);

            // Read the configuration file that contains all the initialization details regarding the rules engine
            // (like addresses of contracts, senders, passwords, etc.)
            string sInitXml = IpfsEnv.GetFile(psPeerKeyId.ToString(), psRulesInitFile);

            if (!String.IsNullOrEmpty(sInitXml))
            {
                System.Xml.Serialization.XmlSerializer WonkaEthSerializer =
                    new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthInitialization),
                                                               new System.Xml.Serialization.XmlRootAttribute("Wonka.EthInitialization"));

                Wonka.Eth.Init.WonkaEthInitialization WonkaInit =
                    WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitXml)) as Wonka.Eth.Init.WonkaEthInitialization;

                WonkaInit.RetrieveEmbeddedResources(TmpAssembly);

                moOrchInitData = WonkaInit.TransformIntoOrchestrationInit(moMetadataSource);

                System.Console.WriteLine("Number of custom operators: (" + WonkaInit.CustomOperatorList.Length + ").");
            }

            // Read the configuration file that contains all the initialization details regarding the rules registry
            // (like Ruletree info, Grove info, etc.)
            string sInitRegistryXml = IpfsEnv.GetFile(psPeerKeyId.ToString(), psRegistryInitFile);

            if (!String.IsNullOrEmpty(sInitRegistryXml))
            {
                System.Xml.Serialization.XmlSerializer WonkaEthSerializer =
                    new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthRegistryInitialization),
                                                               new System.Xml.Serialization.XmlRootAttribute("Wonka.EthRegistryInitialization"));

                moWonkaRegistryInit =
                    WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitRegistryXml)) as Wonka.Eth.Init.WonkaEthRegistryInitialization;

                moWonkaRegistryInit.RetrieveEmbeddedResources(TmpAssembly);
            }

            #region Set Class Member Variables
            msSenderAddress = moOrchInitData.BlockchainEngine.SenderAddress;
            msPassword      = moOrchInitData.BlockchainEngine.Password;

            if (moOrchInitData.BlockchainEngine.ContractAddress == null)
            {
                msWonkaContractAddress = DeployWonkaContract();
            }
            else
            {
                msWonkaContractAddress = moOrchInitData.BlockchainEngine.ContractAddress;
            }

            if (moOrchInitData.DefaultBlockchainDataSource.ContractAddress == null)
            {
                msOrchContractAddress = DeployOrchestrationContract();
            }
            else
            {
                msOrchContractAddress = moOrchInitData.DefaultBlockchainDataSource.ContractAddress;
            }

            msAbiWonka        = moOrchInitData.BlockchainEngine.ContractABI;
            msAbiOrchContract = moOrchInitData.DefaultBlockchainDataSource.ContractABI;

            moDefaultSource =
                new WonkaBizSource(moOrchInitData.DefaultBlockchainDataSource.SourceId,
                                   moOrchInitData.DefaultBlockchainDataSource.SenderAddress,
                                   moOrchInitData.DefaultBlockchainDataSource.Password,
                                   moOrchInitData.DefaultBlockchainDataSource.ContractAddress,
                                   moOrchInitData.DefaultBlockchainDataSource.ContractABI,
                                   moOrchInitData.DefaultBlockchainDataSource.MethodName,
                                   moOrchInitData.DefaultBlockchainDataSource.SetterMethodName,
                                   RetrieveValueMethod);

            // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
            // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
            foreach (WonkaRefAttr TempAttr in RefEnv.AttrCache)
            {
                moAttrSourceMap[TempAttr.AttrName] = moDefaultSource;
            }

            // Here a mapping is created, where each Custom Operator points to a specific contract and its "implementation" method
            // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
            moCustomOpMap = moOrchInitData.BlockchainCustomOpFunctions;

            #endregion

            Wonka.Eth.Contracts.WonkaRuleTreeRegistry WonkaRegistry =
                Wonka.Eth.Contracts.WonkaRuleTreeRegistry.CreateInstance(moWonkaRegistryInit.BlockchainRegistry.ContractSender,
                                                                         moWonkaRegistryInit.BlockchainRegistry.ContractPassword,
                                                                         moWonkaRegistryInit.BlockchainRegistry.ContractAddress,
                                                                         moWonkaRegistryInit.BlockchainRegistry.ContractABI,
                                                                         moWonkaRegistryInit.Web3HttpUrl);

            RefEnv.Serialize(moOrchInitData.BlockchainEngineOwner, msPassword, msSenderAddress, msWonkaContractAddress, msAbiWonka, moOrchInitData.Web3HttpUrl);
        }
コード例 #25
0
        public WonkaSimpleOrchestrationTest(string psSenderAddress, string psPassword, string psContractAddress, bool pbSerializeMetadataToBlockchain = true)
        {
            msSenderAddress   = psSenderAddress;
            msPassword        = psPassword;
            msContractAddress = psContractAddress;

            // Create an instance of the class that will provide us with PmdRefAttributes (i.e., the data domain)
            // that define our data record
            moMetadataSource = new WonkaMetadataTestSource();

            var TmpAssembly = Assembly.GetExecutingAssembly();

            // Read the ABI of the Ethereum contract for the Wonka rules engine
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.abi")))
            {
                msAbiWonka = AbiReader.ReadToEnd();
            }

            // Read the bytecodes of the Ethereum contract for the Wonka rules engine
            using (var ByteCodeReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.bin")))
            {
                msByteCodeWonka = ByteCodeReader.ReadToEnd();
            }

            // Read the ABI of the Ethereum contract that will demonstrate our Orchestration functionality by getting/setting Attribute values
            using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.OrchTest.abi")))
            {
                msAbiOrchTest = AbiReader.ReadToEnd();
            }

            // Read the bytecodes of the Ethereum contract that will hold our data record
            using (var ByteCodeReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.OrchTest.bin")))
            {
                msByteCodeOrchTest = ByteCodeReader.ReadToEnd();
            }

            // Read the XML markup that lists the business rules
            using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.SimpleAccountCheck.xml")))
            {
                msRulesContents = RulesReader.ReadToEnd();
            }

            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment WonkaRefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            WonkaRefAttr AccountIDAttr       = WonkaRefEnv.GetAttributeByAttrName("BankAccountID");
            WonkaRefAttr AccountNameAttr     = WonkaRefEnv.GetAttributeByAttrName("BankAccountName");
            WonkaRefAttr AccountStsAttr      = WonkaRefEnv.GetAttributeByAttrName("AccountStatus");
            WonkaRefAttr AccountCurrValAttr  = WonkaRefEnv.GetAttributeByAttrName("AccountCurrValue");
            WonkaRefAttr AccountTypeAttr     = WonkaRefEnv.GetAttributeByAttrName("AccountType");
            WonkaRefAttr AccountCurrencyAttr = WonkaRefEnv.GetAttributeByAttrName("AccountCurrency");
            WonkaRefAttr RvwFlagAttr         = WonkaRefEnv.GetAttributeByAttrName("AuditReviewFlag");
            WonkaRefAttr CreationDtAttr      = WonkaRefEnv.GetAttributeByAttrName("CreationDt");

            // We create a target list of the Attributes of the old (i.e., existing) record that currently exists on the blockchain
            // and which we want to pull back during the engine's execution
            moTargetAttrList = new List <WonkaRefAttr>();

            moTargetAttrList =
                new List <WonkaRefAttr>()
            {
                AccountIDAttr, AccountNameAttr, AccountStsAttr, AccountCurrValAttr, AccountTypeAttr, AccountCurrencyAttr, RvwFlagAttr, CreationDtAttr
            };

            // Serialize the data domain to the blockchain
            if (pbSerializeMetadataToBlockchain)
            {
                SerializeMetadataToBlockchain();
            }
        }
コード例 #26
0
        public void Execute()
        {
            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment RefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            var sWeb3Url       = "https://mainnet.infura.io/v3/7238211010344719ad14a89db874158c";
            var sSenderAddress = "0x12890D2cce102216644c59daE5baed380d84830c";
            var sPassword      = "******";
            var sERC20Address  = "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2";

            // To test whether the data domain has been created, we pull back one attribute
            WonkaRefAttr AccountStsAttr   = RefEnv.GetAttributeByAttrName("AccountStatus");
            WonkaRefAttr AuditRvwFlagAttr = RefEnv.GetAttributeByAttrName("AuditReviewFlag");

            Dictionary <string, WonkaBizSource> SourceMap = new Dictionary <string, WonkaBizSource>();

            /*
             * WonkaBizSource DefaultSource =
             *  new WonkaBizSource(sContractSourceId, msSenderAddress, msPassword, sContractAddress, sContractAbi, sOrchGetterMethod, sOrchSetterMethod, RetrieveValueMethod);
             */

            WonkaBizSource DefaultSource =
                new WonkaBizSource("", "", "", "", null);

            // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
            // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
            foreach (WonkaRefAttr TempAttr in RefEnv.AttrCache)
            {
                SourceMap[TempAttr.AttrName] = DefaultSource;
            }

            var WonkaEthEngInit =
                new WonkaEthEngineInitialization()
            {
                EthSenderAddress      = sSenderAddress,
                EthPassword           = sPassword,
                ERC20ContractAddress  = sERC20Address,
                ERC721ContractAddress = "",
                Web3HttpUrl           = sWeb3Url
            };

            // Creating an instance of the rules engine using our rules and the metadata
            WonkaBizRulesEngine RulesEngine =
                new WonkaEthRulesEngine(new StringBuilder(msRulesContents), SourceMap, WonkaEthEngInit, moMetadataSource);

            // Gets a predefined data record that will be our analog for new data coming into the system
            WonkaProduct NewProduct = GetNewProduct();

            // Check that the data has been populated correctly on the "new" record
            string sStatusValueBefore = GetAttributeValue(NewProduct, AccountStsAttr);

            // RulesEngine.GetCurrentProductDelegate = GetOldProduct;

            // Validate the new record using our rules engine and its initialized RuleTree
            Wonka.BizRulesEngine.Reporting.WonkaBizRuleTreeReport Report = RulesEngine.Validate(NewProduct);

            // Now retrieve the AccountStatus value and see if the rules have altered it (which should
            // not be the case)
            string sStatusValueAfter  = GetAttributeValue(NewProduct, AccountStsAttr);
            string sAuditRvwFlagAfter = GetAttributeValue(NewProduct, AuditRvwFlagAttr);

            if (Report.GetRuleSetFailureCount() > 0)
            {
                throw new Exception("Oh heavens to Betsy! Something bad happened!");
            }
        }