コード例 #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
        public WonkaERC20Service(string psSenderAddress,
                                 string psPassword,
                                 string psContractAddress,
                                 StringBuilder poRulesContentsBuilder            = null,
                                 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 ((poRulesContentsBuilder != null) && (poRulesContentsBuilder.Length > 0))
            {
                msRulesContents = poRulesContentsBuilder.ToString();
            }

            var bInitSuccess = Init().Result;
        }
コード例 #3
0
        public WonkaBreRulesEngine(StringBuilder psRules,
                                   Dictionary <string, WonkaBreSource> poSourceMap,
                                   Dictionary <string, WonkaBreSource> poCustomOpBlockchainSources,
                                   IMetadataRetrievable piMetadataSource = null,
                                   bool pbAddToRegistry = true)
        {
            if ((psRules == null) || (psRules.Length <= 0))
            {
                throw new WonkaBreException("ERROR!  Provided rules are null or empty!");
            }

            UsingOrchestrationMode = true;
            AddToRegistry          = pbAddToRegistry;

            RefEnvHandle = Init(piMetadataSource);

            WonkaBreXmlReader BreXmlReader = new WonkaBreXmlReader(psRules, piMetadataSource, this);

            foreach (string sKey in poCustomOpBlockchainSources.Keys)
            {
                WonkaBreSource oTargetSource = poCustomOpBlockchainSources[sKey];

                BreXmlReader.AddCustomOperator(sKey, oTargetSource);
            }

            RuleTreeRoot = BreXmlReader.ParseRuleTree();
            SourceMap    = poSourceMap;
            CustomOpMap  = poCustomOpBlockchainSources;
            AllRuleSets  = BreXmlReader.AllParsedRuleSets;

            this.RetrieveCurrRecord = AssembleCurrentProduct;
        }
コード例 #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
 private void CacheImport(string psDatabaseTable, IMetadataRetrievable poSource)
 {
     if (!String.IsNullOrEmpty(psDatabaseTable) && (poSource != null))
     {
         moCachedImports[psDatabaseTable] = poSource;
     }
     else
     {
         throw new WonkaBizRuleException(0, 0, "ERROR!  Could not cache the schema for the database table.");
     }
 }
コード例 #6
0
        static public WonkaRefEnvironment CreateInstance(bool bAllMetadataData, IMetadataRetrievable pMetadataRetrievable)
        {
            lock (mLock)
            {
                if (mInstance == null)
                {
                    mInstance = new WonkaRefEnvironment(bAllMetadataData, pMetadataRetrievable);
                }

                return(mInstance);
            }
        }
コード例 #7
0
ファイル: WonkaBreXmlReader.cs プロジェクト: anegg0/Wonka
        public WonkaBreXmlReader(StringBuilder psBreXml, IMetadataRetrievable piMetadataSource = null)
        {
            if ((psBreXml == null) || (psBreXml.Length <= 0))
            {
                throw new WonkaBreException(-1, -1, "ERROR!  The rules file provided is null.");
            }

            BreXmlFilepath = null;
            BreXmlContents = psBreXml.ToString();

            Init(piMetadataSource);
        }
コード例 #8
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);
                }
            }
        }
コード例 #9
0
        public WonkaBizRulesXmlReader(StringBuilder psBreXml, IMetadataRetrievable piMetadataSource = null, WonkaBizRulesEngine poRulesHostEngine = null)
        {
            if ((psBreXml == null) || (psBreXml.Length <= 0))
            {
                throw new WonkaBizRuleException(-1, -1, "ERROR!  The rules file provided is null.");
            }

            this.BreXmlFilepath  = null;
            this.BreXmlContents  = psBreXml.ToString();
            this.RulesHostEngine = poRulesHostEngine;

            this.Init(piMetadataSource);
        }
コード例 #10
0
 public WonkaEthRulesEngine(StringBuilder psRules,
                            Dictionary <string, WonkaBizSource> poSourceMap,
                            WonkaEthEngineInitialization poEthEngineInit,
                            IMetadataRetrievable piMetadataSource,
                            bool pbAddToRegistry = true)
     : base(psRules,
            poSourceMap,
            poEthEngineInit.InitializeTokenOpMap(),
            piMetadataSource,
            pbAddToRegistry)
 {
     // NOTE: Should anything be done here?
 }
コード例 #11
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
            };
        }
コード例 #12
0
ファイル: WonkaSimpleTest.cs プロジェクト: anegg0/Wonka
        public WonkaSimpleTest()
        {
            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();
            }

            // 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();
        }
コード例 #13
0
ファイル: WonkaBreXmlReader.cs プロジェクト: anegg0/Wonka
        public WonkaBreXmlReader(string psBreXmlFilepath, IMetadataRetrievable piMetadataSource = null)
        {
            if (String.IsNullOrEmpty(psBreXmlFilepath))
            {
                throw new WonkaBreException(-1, -1, "ERROR!  The rules file provided is null.");
            }

            if (!File.Exists(psBreXmlFilepath))
            {
                throw new WonkaBreException(-1, -1, "ERROR!  The rules file(" + psBreXmlFilepath + ") does not exist.");
            }

            BreXmlFilepath = psBreXmlFilepath;
            BreXmlContents = null;

            Init(piMetadataSource);
        }
コード例 #14
0
        public WonkaBreRulesEngine(StringBuilder psRules, IMetadataRetrievable piMetadataSource = null, bool pbAddToRegistry = false)
        {
            if ((psRules == null) || (psRules.Length <= 0))
            {
                throw new WonkaBreException("ERROR!  Provided rules are null or empty!");
            }

            UsingOrchestrationMode = false;
            AddToRegistry          = pbAddToRegistry;

            RefEnvHandle = Init(piMetadataSource);

            WonkaBreXmlReader BreXmlReader = new WonkaBreXmlReader(psRules, piMetadataSource, this);

            RuleTreeRoot = BreXmlReader.ParseRuleTree();
            AllRuleSets  = BreXmlReader.AllParsedRuleSets;
        }
コード例 #15
0
        public IMetadataRetrievable ImportSource(HashSet <Type> poDataStructList)
        {
            WonkaImportSource NewAggregateSource = new WonkaImportSource();

            if (poDataStructList != null)
            {
                foreach (Type TempType in poDataStructList)
                {
                    IMetadataRetrievable TempSource = ImportSource(TempType);

                    TempSource.GetAttrCache().ForEach(x => NewAggregateSource.AddAttribute(x));
                    TempSource.GetGroupCache().ForEach(x => NewAggregateSource.AddGroup(x));
                }
            }

            return(NewAggregateSource);
        }
コード例 #16
0
        public WonkaBizRulesXmlReader(string psBreXmlFilepath, IMetadataRetrievable piMetadataSource = null, WonkaBizRulesEngine poRulesHostEngine = null)
        {
            if (string.IsNullOrEmpty(psBreXmlFilepath))
            {
                throw new WonkaBizRuleException(-1, -1, "ERROR!  The rules file provided is null.");
            }

            if (!File.Exists(psBreXmlFilepath))
            {
                throw new WonkaBizRuleException(-1, -1, "ERROR!  The rules file(" + psBreXmlFilepath + ") does not exist.");
            }

            this.BreXmlFilepath  = psBreXmlFilepath;
            this.BreXmlContents  = null;
            this.RulesHostEngine = poRulesHostEngine;

            this.Init(piMetadataSource);
        }
コード例 #17
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);
        }
コード例 #18
0
        public WonkaBreRulesEngine(string psRulesFilepath, IMetadataRetrievable piMetadataSource = null, bool pbAddToRegistry = false)
        {
            if (String.IsNullOrEmpty(psRulesFilepath))
            {
                throw new WonkaBreException("ERROR!  Provided rules file is null or empty!");
            }

            if (!File.Exists(psRulesFilepath))
            {
                throw new WonkaBreException("ERROR!  Provided rules file(" + psRulesFilepath + ") does not exist on the filesystem.");
            }

            UsingOrchestrationMode = false;
            AddToRegistry          = pbAddToRegistry;

            RefEnvHandle = Init(piMetadataSource);

            WonkaBreXmlReader BreXmlReader = new WonkaBreXmlReader(psRulesFilepath, piMetadataSource, this);

            RuleTreeRoot = BreXmlReader.ParseRuleTree();
            AllRuleSets  = BreXmlReader.AllParsedRuleSets;
        }
コード例 #19
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();
        }
コード例 #20
0
        public WonkaBreRulesEngine(StringBuilder psRules,
                                   Dictionary <string, WonkaBreSource> poSourceMap,
                                   IMetadataRetrievable piMetadataSource = null,
                                   bool pbAddToRegistry = false)
        {
            if ((psRules == null) || (psRules.Length <= 0))
            {
                throw new WonkaBreException("ERROR!  Provided rules are null or empty!");
            }

            UsingOrchestrationMode = true;
            AddToRegistry          = pbAddToRegistry;

            RefEnvHandle = Init(piMetadataSource);

            WonkaBreXmlReader BreXmlReader = new WonkaBreXmlReader(psRules, piMetadataSource, this);

            RuleTreeRoot = BreXmlReader.ParseRuleTree();
            SourceMap    = poSourceMap;
            AllRuleSets  = BreXmlReader.AllParsedRuleSets;

            this.RetrieveCurrRecord = AssembleCurrentProduct;
        }
コード例 #21
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;
        }
コード例 #22
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();
            }
        }
コード例 #23
0
        static public string CreateRulesSampleFile(IMetadataRetrievable piMetadata, string psRulesOutputFile)
        {
            StringBuilder sbRulesBody = new StringBuilder();

            if (piMetadata != null)
            {
                var AttrCache = piMetadata.GetAttrCache();

                if (AttrCache.Count >= 2)
                {
                    string sChildBranch1 = "";
                    string sChildBranch2 = "";

                    var AttrNumCache = AttrCache.Where(x => x.IsDecimal || x.IsNumeric);
                    var AttrStrCache = AttrCache.Where(x => !x.IsDecimal && !x.IsNumeric);

                    if (AttrNumCache.Count() >= 2)
                    {
                        sChildBranch1 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY1,
                                          AttrNumCache.ElementAt(0).AttrName,
                                          AttrNumCache.ElementAt(1).AttrName);
                    }
                    else if (AttrNumCache.Count() == 1)
                    {
                        sChildBranch1 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY1,
                                          AttrNumCache.ElementAt(0).AttrName,
                                          AttrNumCache.ElementAt(0).AttrName);
                    }

                    if (AttrStrCache.Count() >= 4)
                    {
                        sChildBranch2 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY2,
                                          AttrStrCache.ElementAt(2).AttrName,
                                          AttrStrCache.ElementAt(3).AttrName);
                    }
                    else if (AttrStrCache.Count() == 3)
                    {
                        sChildBranch2 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY2,
                                          AttrStrCache.ElementAt(1).AttrName,
                                          AttrStrCache.ElementAt(2).AttrName);
                    }
                    else
                    {
                        sChildBranch2 =
                            String.Format(CONST_SAMPLE_RULE_FORMAT_SUB_BODY2,
                                          AttrStrCache.ElementAt(0).AttrName,
                                          AttrStrCache.ElementAt(1).AttrName);
                    }

                    string sParentBranch =
                        String.Format(CONST_SAMPLE_RULE_FORMAT_MAIN_BODY,
                                      AttrCache[0].AttrName,
                                      AttrCache[1].AttrName,
                                      sChildBranch1,
                                      sChildBranch2);

                    sbRulesBody.Append(sParentBranch);
                }
            }

            if (!String.IsNullOrEmpty(psRulesOutputFile))
            {
                FileInfo OutputFile = new FileInfo(psRulesOutputFile);

                if (OutputFile.Directory.Exists)
                {
                    File.WriteAllText(psRulesOutputFile, sbRulesBody.ToString());
                }
            }

            return(sbRulesBody.ToString());
        }
コード例 #24
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();
            }
        }
コード例 #25
0
 public WonkaSimpleTest()
 {
     moMetadataSource = new WonkaMetadataTestSource();
 }
コード例 #26
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;
        }
コード例 #27
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);
        }
コード例 #28
0
        private WonkaRefEnvironment(bool bAllMetadata, IMetadataRetrievable pMetadataRetrievable)
        {
            DebugLevel = 1;

            DefaultCommitThreshold = 500;

            IdXref = new WonkaRefIdXref();

            AttrCache           = pMetadataRetrievable.GetAttrCache();
            AttrCollectionCache = pMetadataRetrievable.GetAttrCollectionCache();
            CurrencyCache       = pMetadataRetrievable.GetCurrencyCache();
            FieldCache          = pMetadataRetrievable.GetFieldCache();
            GroupCache          = pMetadataRetrievable.GetGroupCache();
            SourceCache         = pMetadataRetrievable.GetSourceCache();
            SourceFieldCache    = pMetadataRetrievable.GetSourceFieldCache();
            StandardCache       = pMetadataRetrievable.GetStandardCache();

            // NOTE: To be implemented later
            // CodeDefCache           = pMetadataRetrievable.GetCodeDefCache();

            AttrKeys       = new List <WonkaRefAttr>();
            AttrMap        = new Dictionary <int, WonkaRefAttr>();
            FieldMap       = new Dictionary <int, WonkaRefField>();
            GroupMap       = new Dictionary <int, WonkaRefGroup>();
            SourceMap      = new Dictionary <int, WonkaRefSource>();
            SourceFieldMap = new Dictionary <int, WonkaRefSourceField>();

            foreach (WonkaRefAttr TmpAttribute in AttrCache)
            {
                if (TmpAttribute.IsKey)
                {
                    AttrKeys.Add(TmpAttribute);
                }

                if (!IdXref.FieldIdToAttrIds.Keys.Contains(TmpAttribute.FieldId))
                {
                    IdXref.FieldIdToAttrIds[TmpAttribute.FieldId] = new HashSet <int>();
                }

                IdXref.FieldIdToAttrIds[TmpAttribute.FieldId].Add(TmpAttribute.AttrId);

                if (!IdXref.GroupIdToAttrIds.Keys.Contains(TmpAttribute.GroupId))
                {
                    IdXref.GroupIdToAttrIds[TmpAttribute.GroupId] = new HashSet <int>();
                }

                IdXref.GroupIdToAttrIds[TmpAttribute.GroupId].Add(TmpAttribute.AttrId);

                if (!IdXref.GroupIdToFieldIds.Keys.Contains(TmpAttribute.GroupId))
                {
                    IdXref.GroupIdToFieldIds[TmpAttribute.GroupId] = new HashSet <int>();
                }

                IdXref.GroupIdToFieldIds[TmpAttribute.GroupId].Add(TmpAttribute.FieldId);

                if (!String.IsNullOrEmpty(TmpAttribute.ColName) && (TmpAttribute.ColName == GetStandardByStdName("GSCName").StandardValue))
                {
                    IdXref.GroupIdToGroupSeqAttrId[TmpAttribute.GroupId] = TmpAttribute.AttrId;
                }

                AttrMap[TmpAttribute.AttrId] = TmpAttribute;
            }

            foreach (WonkaRefGroup TmpGroup in GroupCache)
            {
                if (TmpGroup.KeyTabCols.Count > 0)
                {
                    IdXref.GroupIdToKeyAttrIds[TmpGroup.GroupId] = new HashSet <int>();

                    foreach (string sTmpKeyTabCol in TmpGroup.KeyTabCols)
                    {
                        int nTargetAttrId = GetAttributeByTabColName(sTmpKeyTabCol).AttrId;
                        IdXref.GroupIdToKeyAttrIds[TmpGroup.GroupId].Add(nTargetAttrId);
                    }
                }

                GroupMap[TmpGroup.GroupId] = TmpGroup;
            }

            foreach (WonkaRefField TmpField in FieldCache)
            {
                FieldMap[TmpField.FieldId] = TmpField;
            }

            foreach (WonkaRefSource TmpSource in SourceCache)
            {
                SourceMap[TmpSource.SourceId] = TmpSource;
            }

            foreach (WonkaRefSourceField TmpSrcField in SourceFieldCache)
            {
                SourceFieldMap[TmpSrcField.SourceFieldId] = TmpSrcField;
            }

            if (bAllMetadata)
            {
                AttrCollectionCache = pMetadataRetrievable.GetAttrCollectionCache();

                // NOTE: To be implemented later
                // CodeDependencyCache    = pMetadataRetrievable.GetCodeDependencyCache();
                // CodeDependencyDefCache = pMetadataRetrievable.GetCodeDependencyDefCache();
            }
        }