public Transaction(TransactionType transactionType) : this() { Xid = new TransactionXid(); Status = TransactionStatus.TRYING; TransactionType = transactionType; }
public Transaction(string uniqueIdentity, TransactionType transactionType) : this() { Xid = new TransactionXid(uniqueIdentity); Status = TransactionStatus.TRYING; TransactionType = transactionType; }
protected override ITransaction DoFindOne(TransactionXid xid) { var id = xid.ToString(); // be careful the cache data. var entity = _dbSet.FirstOrDefault(x => x.TransactionId == id); return(ToTransaction(entity)); }
public ITransaction FindByXid(TransactionXid xid) { var transaction = FindFromCache(xid); if (transaction == null) { transaction = DoFindOne(xid); if (transaction != null) { PutToCache(transaction); } } return(transaction); }
private void EnlistParticipant(IMethodInvocation invocation) { var methodInfo = invocation.Method; var target = invocation.TargetObject; var targetType = invocation.TargetObject.GetType(); var arguments = invocation.Arguments; var compensable = methodInfo.GetCustomAttributes(false).OfType <ICompensable>().FirstOrDefault(); if (compensable == null) { throw new TransactionException($"Method {methodInfo.Name} is not marked as Compensable"); } var confirmMethodName = compensable.ConfirmMethod; var cancelMethodName = compensable.CancelMethod; var transaction = _transactionManager.Current; var xid = new TransactionXid(transaction.Xid.GlobalTransactionId); // random branch transaction ID // Set the value of the parameter [TransactionContext] in the [Try] method var transactionContextEditor = _serviceProvider.GetRequiredService <ITransactionContextEditor>(); if (transactionContextEditor.GetContext(target, methodInfo, arguments) == null) { transactionContextEditor.SetContext(new TransactionContext(xid, TransactionStatus.TRYING), target, methodInfo, arguments); } var parameterTypes = methodInfo.GetParameterTypes(); var confirmInvocation = new InvocationContext(targetType, confirmMethodName, parameterTypes, arguments); var cancelInvocation = new InvocationContext(targetType, cancelMethodName, parameterTypes, arguments); var participant = _serviceProvider.GetRequiredService <IParticipant>(); participant.Xid = xid; participant.ConfirmInvocationContext = confirmInvocation; participant.CancelInvocationContext = cancelInvocation; _transactionManager.AddParticipant(participant); }
private ITransaction FindFromCache(TransactionXid transactionXid) { Check.NotNull(transactionXid, nameof(transactionXid)); return((ITransaction)Cache.Get(transactionXid.ToString())); }
protected abstract ITransaction DoFindOne(TransactionXid xid);