Tiraggo.Interfaces.tgTransactionScope.CommonInit C# (CSharp) Method

CommonInit() protected static method

This is the common constructor logic, tx is "this" from the constructor
protected static CommonInit ( tgTransactionScope tx ) : void
tx tgTransactionScope
return void
        protected static void CommonInit(tgTransactionScope tx)
        {
            Stack<tgTransactionScope> stack;

            // See if our stack is already created (there is only one per thread)
            object obj = Thread.GetData(txSlot);
            if (obj == null)
            {
                stack = new Stack<tgTransactionScope>();
                Thread.SetData(txSlot, stack);
            }
            else
            {
                stack = (Stack<tgTransactionScope>)obj;
            }

            // If this transaction is required we need to set it's root
            if (tx.option == tgTransactionScopeOption.Required)
            {
                foreach (tgTransactionScope esTrans in stack)
                {
                    // The root can be either a Requires or RequiresNew, and a root always points to
                    // itself, therefore, as long as it's not a Suppress and it's pointing to itself
                    // then we know this the next root up on the stack
                    if (esTrans.option != tgTransactionScopeOption.Suppress && esTrans == esTrans.root)
                    {
                        tx.root = esTrans;
                        break;
                    }
                }
            }

            // If we didn't find a root, then we are by definition the root
            if (tx.root == null)
            {
                tx.root = tx;
                tx.transactions = new Dictionary<string, Transaction>();
            }

            stack.Push(tx);
        }