public static Transaction GetTransactionFromTransmitterPropagationToken(byte[] propagationToken)
{
if (null == propagationToken)
{
throw new ArgumentNullException(nameof(propagationToken));
}
if (propagationToken.Length < 24)
{
throw new ArgumentException(SR.InvalidArgument, nameof(propagationToken));
}
TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log;
if (etwLog.IsEnabled())
{
etwLog.MethodEnter(TraceSourceType.TraceSourceDistributed, "TransactionInterop.GetTransactionFromTransmitterPropagationToken");
}
// Extract the transaction guid from the propagation token to see if we already have a
// transaction object for the transaction.
byte[] guidByteArray = new byte[16];
for (int i = 0; i < guidByteArray.Length; i++)
{
// In a propagation token, the transaction guid is preceeded by two version DWORDs.
guidByteArray[i] = propagationToken[i + 8];
}
var txId = new Guid(guidByteArray);
// First check to see if there is a promoted LTM transaction with the same ID. If there is, just return that.
Transaction tx = TransactionManager.FindPromotedTransaction(txId);
if (null != tx)
{
if (etwLog.IsEnabled())
{
etwLog.MethodExit(TraceSourceType.TraceSourceDistributed, "TransactionInterop.GetTransactionFromTransmitterPropagationToken");
}
return tx;
}
DistributedTransaction dTx = GetDistributedTransactionFromTransmitterPropagationToken(propagationToken);
// If a transaction is found then FindOrCreate will Dispose the distributed transaction created.
Transaction returnValue = TransactionManager.FindOrCreatePromotedTransaction(txId, dTx);
if (etwLog.IsEnabled())
{
etwLog.MethodExit(TraceSourceType.TraceSourceDistributed, "TransactionInterop.GetTransactionFromTransmitterPropagationToken");
}
return returnValue;
}