コード例 #1
0
        protected override void Execute(NativeActivityContext context)
        {
            //Gets the ambient RuntimeTransactionHandle which allows access to the runtime transaction
            RuntimeTransactionHandle rth = context.Properties.Find(typeof(RuntimeTransactionHandle).FullName) as RuntimeTransactionHandle;

            if (rth == null)
            {
                throw new InvalidOperationException("There is no RuntimeTransactionHandle");
            }

            //The runtime transaction
            Transaction t = rth.GetCurrentTransaction(context);

            if (t == null)
            {
                throw new InvalidOperationException("There is no transaction to rollback");
            }

            Exception e = Reason.Get(context);

            if (e == null)
            {
                e = new TransactionException("The Rollback activity was used to rollback the transaction");
            }

            t.Rollback(e);
        }
コード例 #2
0
        protected override void Execute(NativeActivityContext context)
        {
            if (this.Request == null)
            {
                throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new ValidationException(System.ServiceModel.Activities.SR.TransactedReceiveScopeRequiresReceive(base.DisplayName)));
            }
            RuntimeTransactionHandle property = this.transactionHandle.Get(context);

            context.Properties.Add(TransactedReceiveData.TransactedReceiveDataExecutionPropertyName, new TransactedReceiveData());
            RuntimeTransactionHandle handle2 = context.Properties.Find(property.ExecutionPropertyName) as RuntimeTransactionHandle;

            if (handle2 == null)
            {
                context.Properties.Add(property.ExecutionPropertyName, property);
            }
            else
            {
                if (handle2.SuppressTransaction)
                {
                    throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.CannotNestTransactedReceiveScopeWhenAmbientHandleIsSuppressed(base.DisplayName)));
                }
                if (handle2.GetCurrentTransaction(context) != null)
                {
                    property = handle2;
                    this.isNested.Set(context, true);
                }
            }
            context.ScheduleActivity(this.Request, new CompletionCallback(this.OnReceiveCompleted));
        }
コード例 #3
0
 public RuntimeTransactionData(RuntimeTransactionHandle handle, Transaction transaction, ActivityInstance isolationScope)
 {
     this.TransactionHandle   = handle;
     this.OriginalTransaction = transaction;
     this.ClonedTransaction   = transaction.Clone();
     this.IsolationScope      = isolationScope;
     this.TransactionStatus   = TransactionStatus.Active;
 }
コード例 #4
0
        protected override void Execute(NativeActivityContext context)
        {
            //Access to the current transaction in Workflow is through the GetCurrentTransaction method on a RuntimeTransactionHandle
            RuntimeTransactionHandle rth = new RuntimeTransactionHandle();

            rth = context.Properties.Find(rth.ExecutionPropertyName) as RuntimeTransactionHandle;
            Console.WriteLine("    TransactionID: " + rth.GetCurrentTransaction(context).TransactionInformation.LocalIdentifier.ToString());
        }
コード例 #5
0
 private void OnDelayCompletion(NativeActivityContext context, System.Activities.ActivityInstance instance)
 {
     if (instance.State == ActivityInstanceState.Closed)
     {
         RuntimeTransactionHandle handle = context.Properties.Find(runtimeTransactionHandlePropertyName) as RuntimeTransactionHandle;
         handle.GetCurrentTransaction(context).Rollback();
     }
 }
コード例 #6
0
        void GetTransactionFromContext(AsyncCodeActivityContext context)
        {
            RuntimeTransactionHandle transactionHandle = context.GetProperty <RuntimeTransactionHandle>();

            if (transactionHandle != null)
            {
                this.Transaction = transactionHandle.GetCurrentTransaction(context);
            }
        }
コード例 #7
0
 void OnDelayCompletion(NativeActivityContext context, ActivityInstance instance)
 {
     if (instance.State == ActivityInstanceState.Closed)
     {
         RuntimeTransactionHandle handle = context.Properties.Find(runtimeTransactionHandlePropertyName) as RuntimeTransactionHandle;
         Fx.Assert(handle != null, "Internal error.. If we are here, there ought to be an ambient transaction handle");
         handle.GetCurrentTransaction(context).Rollback();
     }
 }
コード例 #8
0
        void GetTransactionFromContext(NativeActivityContext context)
        {
            RuntimeTransactionHandle transactionHandle = context.Properties.Find(typeof(RuntimeTransactionHandle).FullName) as RuntimeTransactionHandle;

            if (transactionHandle != null)
            {
                this.Transaction = transactionHandle.GetCurrentTransaction(context);
            }
        }
コード例 #9
0
        protected override void Execute(NativeActivityContext context)
        {
            RuntimeTransactionHandle transactionHandle = this.runtimeTransactionHandle.Get(context);

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

            if (!(context.Properties.Find(runtimeTransactionHandlePropertyName) is RuntimeTransactionHandle foundHandle))
            {
                //Note, once the property is registered, we cannot change the state of this flag
                transactionHandle.AbortInstanceOnTransactionFailure = this.AbortInstanceOnTransactionFailure;
                context.Properties.Add(transactionHandle.ExecutionPropertyName, transactionHandle);
            }
コード例 #10
0
        private void OnCompletion(NativeActivityContext context, System.Activities.ActivityInstance instance)
        {
            RuntimeTransactionHandle handle = this.runtimeTransactionHandle.Get(context);

            if (this.delayWasScheduled.Get(context))
            {
                handle.CompleteTransaction(context, new BookmarkCallback(this.OnTransactionComplete));
            }
            else
            {
                handle.CompleteTransaction(context);
            }
        }
コード例 #11
0
        void OnCompletion(NativeActivityContext context, ActivityInstance instance)
        {
            RuntimeTransactionHandle transactionHandle = this.runtimeTransactionHandle.Get(context);

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

            if (this.delayWasScheduled.Get(context))
            {
                transactionHandle.CompleteTransaction(context, new BookmarkCallback(OnTransactionComplete));
            }
            else
            {
                transactionHandle.CompleteTransaction(context);
            }
        }
コード例 #12
0
        protected override void Execute(NativeActivityContext context)
        {
            if (this.Body != null)
            {
                RuntimeTransactionHandle handle = rth.Get(context);

                // Must set before adding the handle to the execution properties
                handle.SuppressTransaction = true;

                // Adding a new RuntimeTransactionHanlde rather than using the existing one so that suppression is scoped to this activity. Also,
                // because modifying the property of a registered (added to execution properties) RuntimeTransactionHandle is not allowed.
                context.Properties.Add(handle.ExecutionPropertyName, handle);
                context.ScheduleActivity(this.Body);
            }
        }
コード例 #13
0
        protected override void Execute(NativeActivityContext context)
        {
            RuntimeTransactionHandle rth   = context.Properties.Find(typeof(RuntimeTransactionHandle).FullName) as RuntimeTransactionHandle;
            Transaction runtimeTransaction = rth.GetCurrentTransaction(context);

            if (runtimeTransaction != null)
            {
                TransactionInformation tx = runtimeTransaction.TransactionInformation;

                Console.WriteLine("    Runtime transaction DistroID: " + tx.DistributedIdentifier);
            }
            else
            {
                Console.WriteLine("  No runtime transaction");
            }
        }
コード例 #14
0
        protected override void Execute(NativeActivityContext context)
        {
            // Get the connection string
            DBExtension ext = context.GetExtension <DBExtension>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Create a data context
            LeadDataDataContext dc = new LeadDataDataContext(ext.ConnectionString);

            // Enlist on the current transaction
            RuntimeTransactionHandle rth = new RuntimeTransactionHandle();

            rth = context.Properties.Find(rth.ExecutionPropertyName)
                  as RuntimeTransactionHandle;
            if (rth != null)
            {
                Transaction t = rth.GetCurrentTransaction(context);

                // Open the connection, if necessary
                if (dc.Connection.State == System.Data.ConnectionState.Closed)
                {
                    dc.Connection.Open();
                }

                dc.Connection.EnlistTransaction(t);
            }

            // Create an Assignment class and populate its properties
            Assignment a = new Assignment();

            dc.Assignments.InsertOnSubmit(a);

            a.WorkflowID   = context.WorkflowInstanceId;
            a.LeadID       = LeadID.Get(context);
            a.DateAssigned = DateTime.Now;
            a.AssignedTo   = AssignedTo.Get(context);
            a.Status       = "Assigned";
            a.DateDue      = DateTime.Now + TimeSpan.FromDays(5);

            dc.SubmitChanges();
        }
コード例 #15
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);
            }
        }
コード例 #16
0
        protected override void Execute(NativeActivityContext context)
        {
            // Get the connection string
            DBExtension ext = context.GetExtension <DBExtension>();

            if (ext == null)
            {
                throw new InvalidProgramException("No connection string available");
            }

            // Query the Lead table
            LeadDataDataContext dc = new LeadDataDataContext(ext.ConnectionString);

            dc.Refresh(RefreshMode.OverwriteCurrentValues, dc.Leads);
            Lead l = dc.Leads.SingleOrDefault <Lead>
                         (x => x.WorkflowID == context.WorkflowInstanceId);

            if (l == null)
            {
                throw new InvalidProgramException
                          ("The Lead was not found in the database");
            }

            l.AssignedTo = AssignedTo.Get(context);
            l.Status     = "Assigned";

            // Enlist on the current transaction
            RuntimeTransactionHandle rth = new RuntimeTransactionHandle();

            rth = context.Properties.Find(rth.ExecutionPropertyName)
                  as RuntimeTransactionHandle;
            if (rth != null)
            {
                Transaction t = rth.GetCurrentTransaction(context);
                dc.Connection.EnlistTransaction(t);
            }

            dc.SubmitChanges();

            // Store the request in the OutArgument
            Lead.Set(context, l);
        }
コード例 #17
0
        protected override void Execute(NativeActivityContext context)
        {
            //Access to the current transaction in Workflow is through the runtime transaction handle
            //Because workflow is not guaranteed to always run on the same thread the runtime maintains a clone
            //of the current transaction. The thread on which the workflow is currently executing will be set
            //up so that the transaction may be accessed using Transaction.Current the best practice is to use
            //the runtime's transaction by calling GetCurrentTransaction on the runtime transaction handle.
            RuntimeTransactionHandle rth = new RuntimeTransactionHandle();

            rth = context.Properties.Find(rth.ExecutionPropertyName) as RuntimeTransactionHandle;
            if (rth != null)
            {
                TransactionInformation ti = rth.GetCurrentTransaction(context).TransactionInformation;
                Console.WriteLine("Transaction: {0} is {1}.", ti.DistributedIdentifier.ToString(), ti.Status);
            }
            else
            {
                Console.WriteLine("There is no runtime transaction.");
            }
        }
コード例 #18
0
        protected override void Execute(NativeActivityContext context)
        {
            RuntimeTransactionHandle rth = context.Properties.Find(typeof(RuntimeTransactionHandle).FullName) as RuntimeTransactionHandle;

            if (rth == null)
            {
                Console.WriteLine("There is no ambient RuntimeTransactionHandle");
            }

            Transaction t = rth.GetCurrentTransaction(context);

            if (t == null)
            {
                Console.WriteLine("There is no ambient transaction");
            }
            else
            {
                Console.WriteLine("Transaction: {0} is {1}", t.TransactionInformation.LocalIdentifier, t.TransactionInformation.Status);
            }
        }
コード例 #19
0
        private void SetupTransaction(NativeActivityContext executionContext, ReceiveMessageInstanceData instance)
        {
            WorkflowOperationContext workflowOperationContext = instance.CorrelationResponseContext.WorkflowOperationContext;

            if (workflowOperationContext.CurrentTransaction != null)
            {
                RuntimeTransactionHandle handle = null;
                handle = executionContext.Properties.Find(runtimeTransactionHandlePropertyName) as RuntimeTransactionHandle;
                if (handle == null)
                {
                    throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.ReceiveNotWithinATransactedReceiveScope));
                }
                TransactedReceiveData data = executionContext.Properties.Find(TransactedReceiveData.TransactedReceiveDataExecutionPropertyName) as TransactedReceiveData;
                if ((data != null) && this.AdditionalData.IsFirstReceiveOfTransactedReceiveScopeTree)
                {
                    data.InitiatingTransaction = workflowOperationContext.OperationContext.TransactionFacet.Current;
                }
                Transaction currentTransaction = handle.GetCurrentTransaction(executionContext);
                if (currentTransaction != null)
                {
                    if (!currentTransaction.Equals(workflowOperationContext.CurrentTransaction))
                    {
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.FlowedTransactionDifferentFromAmbient));
                    }
                    this.ServerScheduleOnReceivedMessage(executionContext, instance);
                }
                else
                {
                    ReceiveMessageState state = new ReceiveMessageState {
                        CurrentTransaction = workflowOperationContext.CurrentTransaction.Clone(),
                        Instance           = instance
                    };
                    handle.RequireTransactionContext(executionContext, new Action <NativeActivityTransactionContext, object>(this.RequireContextCallback), state);
                }
            }
            else
            {
                this.ServerScheduleOnReceivedMessage(executionContext, instance);
            }
        }
コード例 #20
0
            protected override void Execute(NativeActivityContext context)
            {
                //In workflow access to the current transaction is through the runtime transaction handle
                RuntimeTransactionHandle rth = new RuntimeTransactionHandle();
                Transaction tx = null;

                rth = context.Properties.Find(rth.ExecutionPropertyName) as RuntimeTransactionHandle;

                if (rth != null)
                {
                    tx = rth.GetCurrentTransaction(context);
                }

                if (tx == null)
                {
                    Console.WriteLine("    Workflow - There is no current transaction.");
                }
                else
                {
                    Console.WriteLine("    Workflow - Tx local ID: " + rth.GetCurrentTransaction(context).TransactionInformation.LocalIdentifier);
                }
            }
コード例 #21
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));
        }
コード例 #22
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);
            }
        }