Exemplo n.º 1
0
        protected override void Execute(NativeActivityContext context)
        {
            RuntimeTransactionHandle property = this.runtimeTransactionHandle.Get(context);
            RuntimeTransactionHandle handle2  = context.Properties.Find(runtimeTransactionHandlePropertyName) as RuntimeTransactionHandle;

            if (handle2 == null)
            {
                property.AbortInstanceOnTransactionFailure = this.AbortInstanceOnTransactionFailure;
                context.Properties.Add(property.ExecutionPropertyName, property);
            }
            else
            {
                if ((!handle2.IsRuntimeOwnedTransaction && this.abortInstanceFlagWasExplicitlySet) && (handle2.AbortInstanceOnTransactionFailure != this.AbortInstanceOnTransactionFailure))
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.AbortInstanceOnTransactionFailureDoesNotMatch));
                }
                if (handle2.SuppressTransaction)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.CannotNestTransactionScopeWhenAmbientHandleIsSuppressed(base.DisplayName)));
                }
                property = handle2;
            }
            Transaction currentTransaction = property.GetCurrentTransaction(context);

            if (currentTransaction == null)
            {
                property.RequestTransactionContext(context, new Action <NativeActivityTransactionContext, object>(this.OnContextAcquired), null);
            }
            else
            {
                if (currentTransaction.IsolationLevel != this.IsolationLevel)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.IsolationLevelValidation));
                }
                if (this.isTimeoutSetExplicitly)
                {
                    TimeSpan span = this.Timeout.Get(context);
                    this.delayWasScheduled.Set(context, true);
                    this.nestedScopeTimeout.Set(context, span);
                    this.nestedScopeTimeoutActivityInstance.Set(context, context.ScheduleActivity(this.NestedScopeTimeoutWorkflow, new CompletionCallback(this.OnDelayCompletion)));
                }
                this.ScheduleBody(context);
            }
        }
Exemplo n.º 2
0
        protected override void Execute(NativeActivityContext context)
        {
            RuntimeTransactionHandle transactionHandle = this.runtimeTransactionHandle.Get(context);

            Fx.Assert(transactionHandle != null, "RuntimeTransactionHandle is null");

            RuntimeTransactionHandle foundHandle = context.Properties.Find(runtimeTransactionHandlePropertyName) as RuntimeTransactionHandle;

            if (foundHandle == null)
            {
                //Note, once the property is registered, we cannot change the state of this flag
                transactionHandle.AbortInstanceOnTransactionFailure = this.AbortInstanceOnTransactionFailure;
                context.Properties.Add(transactionHandle.ExecutionPropertyName, transactionHandle);
            }
            else
            {
                //nested case
                //foundHandle.IsRuntimeOwnedTransaction will be true only in the Invoke case within an ambient Sys.Tx transaction.
                //If this TSA is nested inside the ambient transaction from Invoke, then the AbortInstanceFlag is always false since the RTH corresponding to the ambient
                //transaction has this flag as false. In this case, we ignore if this TSA has this flag explicitly set to true.
                if (!foundHandle.IsRuntimeOwnedTransaction && this.abortInstanceFlagWasExplicitlySet && (foundHandle.AbortInstanceOnTransactionFailure != this.AbortInstanceOnTransactionFailure))
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.AbortInstanceOnTransactionFailureDoesNotMatch));
                }

                if (foundHandle.SuppressTransaction)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CannotNestTransactionScopeWhenAmbientHandleIsSuppressed(this.DisplayName)));
                }
                transactionHandle = foundHandle;
            }

            Transaction transaction = transactionHandle.GetCurrentTransaction(context);

            //Check if there is already a transaction (Requires Semantics)
            if (transaction == null)
            {
                //If not, request one..
                transactionHandle.RequestTransactionContext(context, OnContextAcquired, null);
            }
            else
            {
                //Most likely, you are inside a nested TSA
                if (transaction.IsolationLevel != this.IsolationLevel)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.IsolationLevelValidation));
                }

                //Check if the nested TSA had a timeout specified explicitly
                if (this.isTimeoutSetExplicitly)
                {
                    TimeSpan timeout = this.Timeout.Get(context);
                    this.delayWasScheduled.Set(context, true);
                    this.nestedScopeTimeout.Set(context, timeout);

                    this.nestedScopeTimeoutActivityInstance.Set(context, context.ScheduleActivity(this.NestedScopeTimeoutWorkflow, new CompletionCallback(OnDelayCompletion)));
                }

                //execute the Body under the current runtime transaction
                ScheduleBody(context);
            }
        }