protected override void New() { TransactionDefinition td = (TransactionDefinition)request.TransactionEntityList[0]; td.CreateDate = DateTime.Now; td.CreatedUser = Context.UserName; if (TransactionCache.Instance.Get(td.TranCode, false) != null) { throw new Exception(string.Format("Trancode `{0}` exists", td.TranCode)); } SpCall spCall = new SpCall("COR.TRANSACTION_DEFINITION_INSERT"); spCall.SetVarchar("@TRAN_CODE", td.TranCode); spCall.SetVarchar("@TRAN_DESCRIPTION", td.TranDescription); spCall.SetBit("@IS_CANCELLABLE", td.IsCancellable); spCall.SetInt("@MENU_ID", td.MenuId); spCall.SetVarchar("@GROUP_CODE", td.GroupCode); spCall.SetBit("@QB_RELATED", td.IsQbRelated); spCall.SetVarchar("@CODE_BASE", td.CodeBase); spCall.SetDateTime("@CREATE_DATE", td.CreateDate); spCall.SetVarchar("@CREATE_USER", td.CreatedUser); long id = db.ExecuteScalar <long>(spCall); td.Id = id; Context.TransactionObject = td; }
protected Task <BlockchainOperation> SendTransactionAsync <TParameters>( Address from, TransactionDefinition <TParameters> transactionDefinition) where TParameters : TransactionDefinition <TParameters>, new() { return(SendTransactionAsync ( from, transactionDefinition, ConfirmationLevel.Zero )); }
public void TestPersistentTransactionContextValue() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn }); // transaction commit dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); Assert.Equal(3, dummyCom.InvokeCounter); Assert.Equal(2, dummyCom.ReceivedParameterList.Count); foreach (var itemArr in dummyCom.ReceivedParameterList) { Assert.Equal(dummyCom.TransactionTestGuid, itemArr[0]); } }
public PersistentMethod RegisterTransaction(TransactionDefinition trxDef) { if (this.Transaction != null) { throw new InvalidOperationException("Transaction definition already assigned"); } trxDef.Methods.Add(this); this.Transaction = trxDef; return(this); }
public TransactionBase GetTransaction(string transactionCode) { TransactionDefinition td = TransactionCache.Instance.Get(transactionCode); Type type = Type.GetType(td.CodeBase); if (type == null) { throw new Exception(string.Format("Codebase `{0}` of transaction `{1}` could not be found", td.CodeBase, transactionCode)); } TransactionBase result = (TransactionBase)Activator.CreateInstance(type, new object[] { context }); return(result); }
public static ResponseMessage Add(string codeBase, int menuId, string group, string desc, string tcode) { TransactionDefinition item = new TransactionDefinition() { CodeBase = "Koenig.Maestro.Operation.TransactionRepository." + codeBase, GroupCode = group, IsCancellable = false, IsQbRelated = false, MenuId = menuId, TranCode = tcode, TranDescription = desc }; RequestMessage request = MessagePrepareAgent.GetRequest(action, tranCode, "", new List <ITransactionEntity>(new ITransactionEntity[] { item })); return(new MessageBroker().Execute(request)); }
public PersistentMethod RegisterTransactionCommit(TransactionDefinition trxDef) { if (this.Transaction != null) { throw new InvalidOperationException("Transaction definition already assigned"); } if (trxDef.CommitTransactionMethod != null) { throw new InvalidOperationException("Commit transaction method already assigned!"); } trxDef.CommitTransactionMethod = this; trxDef.Methods.Add(this); this.Transaction = trxDef; return(this); }
protected async Task <BlockchainOperation> SendTransactionAsync <TParameters>( Address from, TransactionDefinition <TParameters> transactionDefinition, ConfirmationLevel minimalConfirmationLevel) where TParameters : TransactionDefinition <TParameters>, new() { var transactionInput = await Web3.Eth .GetContractTransactionHandler <TParameters>() .CreateTransactionInputEstimatingGasAsync ( ContractAddress, (TParameters)transactionDefinition ); transactionInput.From = from; transactionInput.GasPrice = new HexBigInteger(await EstimateGasPriceStrategy.ExecuteAsync()); string transactionHash; if (Web3.TransactionManager.Account != null) { var signedTransaction = await Web3.TransactionManager .SignTransactionAsync(transactionInput); transactionHash = await Web3.Eth.Transactions .SendRawTransaction .SendRequestAsync(signedTransaction); } else { transactionHash = await Web3.Eth.Transactions .SendTransaction .SendRequestAsync(transactionInput); } var blockchainOperationId = BlockchainOperationId.Parse(transactionHash); return(new BlockchainOperation(blockchainOperationId, Web3, minimalConfirmationLevel)); }
protected override void Update() { TransactionDefinition td = (TransactionDefinition)request.TransactionEntityList[0]; td.UpdateDate = DateTime.Now; td.UpdatedUser = Context.UserName; SpCall spCall = new SpCall("COR.TRANSACTION_DEFINITION_UPDATE"); spCall.SetBigInt("ID", td.Id); spCall.SetVarchar("@TRAN_CODE", td.TranCode); spCall.SetVarchar("@TRAN_DESCRIPTION", td.TranDescription); spCall.SetBit("@IS_CANCELLABLE", td.IsCancellable); spCall.SetInt("@MENU_ID", td.MenuId); spCall.SetVarchar("@GROUP_CODE", td.GroupCode); spCall.SetBit("@QB_RELATED", td.IsQbRelated); spCall.SetVarchar("@CODE_BASE", td.CodeBase); spCall.SetDateTime("@UPDATE_DATE", td.UpdateDate); spCall.SetVarchar("@UPDATE_USER", td.UpdatedUser); db.ExecuteNonQuery(spCall); Context.TransactionObject = td; }
public void TestPersistentTransactionContext_FunctionalExceptionOnComplete() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.ResendSuspensionDelay = TimeSpan.Zero; persistComm.ResendSuspensionGracePeriod = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data dummyCom.RaiseFunctionalException = true; Assert.Throws <InvalidOperationException>(() => persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn })); // transaction commit // close connection to release file persistComm.RealUnderlyingSession.Close(); // raise connection again var firstOnlineCallGuid = dummyCom.TransactionTestGuid; dummyCom.TransactionTestGuid = Guid.NewGuid(); // set new Guid dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed (no messages are expected) Thread.Sleep(500); // 4 calls because last online call threw a function exception resulting in a transaction abort Assert.Equal(4, dummyCom.InvokeCounter); }
public void TestPersistentTransactionContext_CompleteOnlineTransactionCalls_NoResendExpected() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.ResendSuspensionDelay = TimeSpan.Zero; persistComm.ResendSuspensionGracePeriod = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn }); // transaction commit // loose connection persistComm.RealUnderlyingSession.Close(); //Thread.Sleep(100); // raise connection again dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); // 5 calls = 5 online transaction calls till first conn lost. No resend expected because commit mehtod was successfully executed during active connection. Assert.Equal(5, dummyCom.InvokeCounter); // expect 4 parameter values (- start method) Assert.Equal(4, dummyCom.ReceivedParameterList.Count); Assert.Equal(dummyCom.TransactionTestGuid, dummyCom.ReceivedParameterList[0][0]); }
public void TestPersistentTransactionContext_LooseConnDuringSend() { IOCTalk.Composition.TalkCompositionHost talkCompositionHost = new Composition.TalkCompositionHost(); PersistentTestCommService dummyCom = new PersistentTestCommService(xUnitLog); dummyCom.RaiseConnectionLost = true; PersistentClientCommunicationHost persistComm = new PersistentClientCommunicationHost(dummyCom); persistComm.ResendDelay = TimeSpan.Zero; persistComm.ResendSuspensionDelay = TimeSpan.Zero; persistComm.ResendSuspensionGracePeriod = TimeSpan.Zero; TransactionDefinition trxDef = new TransactionDefinition("Test Transaction"); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.StartTransactionTest)) .RegisterTransactionBegin(trxDef) .RegisterResendAction(new TrxResendActionUseReturnValue("testSessionId")); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.PushTrxData)) .RegisterTransaction(trxDef); persistComm.RegisterPersistentMethod <ITrxTestService>(nameof(ITrxTestService.CompleteTransactionTest)) .RegisterTransactionCommit(trxDef); persistComm.RegisterContainerHost(talkCompositionHost, null); persistComm.Init(); CleanupPeristentDirectory(persistComm); dummyCom.RaiseConnectionLost = false; dummyCom.RaiseConnectionCreated(); InvokeMethodInfo mInfoBeginTrx = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.StartTransactionTest)); InvokeMethodInfo mInfoTrxData = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.PushTrxData)); InvokeMethodInfo mInfoTrxCommit = new InvokeMethodInfo(typeof(ITrxTestService), nameof(ITrxTestService.CompleteTransactionTest)); ISession session = new BSAG.IOCTalk.Common.Session.Session(dummyCom, 1, "Unit Test Session"); Guid startTrxReturn = (Guid)persistComm.InvokeMethod(this, mInfoBeginTrx, session, new object[0]); // Start transaction call persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data // loose connection persistComm.RealUnderlyingSession.Close(); persistComm.InvokeMethod(this, mInfoTrxData, session, new object[] { startTrxReturn }); // Push transaction data persistComm.InvokeMethod(this, mInfoTrxCommit, session, new object[] { startTrxReturn }); // transaction commit // raise connection again var firstOnlineCallGuid = dummyCom.TransactionTestGuid; dummyCom.TransactionTestGuid = Guid.NewGuid(); // set new Guid dummyCom.RaiseConnectionCreated(); // wait until local pending messages are processed Thread.Sleep(500); // 8 calls = 3 online transaction till first conn lost + 5 calls on complete transaction resend Assert.Equal(8, dummyCom.InvokeCounter); // expect 6 parameter valus (8 - 2 x Start method) Assert.Equal(6, dummyCom.ReceivedParameterList.Count); for (int i = 0; i < dummyCom.ReceivedParameterList.Count; i++) { var itemArr = dummyCom.ReceivedParameterList[i]; if (i <= 1) { Assert.Equal(firstOnlineCallGuid, itemArr[0]); } else { // expect new guid for complete transaction resend Assert.Equal(dummyCom.TransactionTestGuid, itemArr[0]); } } }