예제 #1
0
        protected override void Execute(NativeActivityContext context)
        {
            if (this.Request == null)
            {
                throw FxTrace.Exception.AsError(new ValidationException(SR2.TransactedReceiveScopeRequiresReceive(this.DisplayName)));
            }
            // we have to do this in code since we aren't fully modeled (in order for
            // dynamic update to work correctly)
            RuntimeTransactionHandle handleInstance = this.transactionHandle.Get(context);

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

            //This is used by InternalReceiveMessage to update the InitiatingTransaction so that we can later call Commit/Complete on it
            context.Properties.Add(TransactedReceiveData.TransactedReceiveDataExecutionPropertyName, new TransactedReceiveData());

            RuntimeTransactionHandle foundHandle = context.Properties.Find(handleInstance.ExecutionPropertyName) as RuntimeTransactionHandle;

            if (foundHandle == null)
            {
                context.Properties.Add(handleInstance.ExecutionPropertyName, handleInstance);
            }
            else
            {
                //nested case
                if (foundHandle.SuppressTransaction)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.CannotNestTransactedReceiveScopeWhenAmbientHandleIsSuppressed(this.DisplayName)));
                }

                // Verify if TRS is root and if the foundHandle is not from the parent HandleScope<RTH>
                if (foundHandle.GetCurrentTransaction(context) != null)
                {
                    handleInstance = foundHandle;
                    this.isNested.Set(context, true);
                }
            }
            context.ScheduleActivity(this.Request, new CompletionCallback(OnReceiveCompleted));
        }