Exemplo n.º 1
0
            private void NotifyOperationComplete()
            {
                var localInstanceOperation = this.instanceOperation;

                this.instanceOperation = null;
                this.instance.NotifyOperationComplete(localInstanceOperation);
            }
Exemplo n.º 2
0
            public UnloadOrPersistAsyncResult(WorkflowApplication instance, TimeSpan timeout, PersistenceOperation operation,
                                              bool isWorkflowThread, bool isInternalPersist, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.instance          = instance;
                this.timeoutHelper     = new TimeoutHelper(timeout);
                this.operation         = operation;
                this.isInternalPersist = isInternalPersist;
                this.isUnloaded        = (operation == PersistenceOperation.Unload || operation == PersistenceOperation.Complete);

                this.OnCompleting = UnloadOrPersistAsyncResult.completeCallback;

                bool completeSelf;
                var  success = false;

                // Save off the current transaction in case we have an async operation before we end
                // up creating the WorkflowPersistenceContext and create it on another thread. Do a
                // blocking dependent clone that we will complete when we are completed.
                //
                // This will throw TransactionAbortedException by design, if the transaction is
                // already rolled back.
                var currentTransaction = Transaction.Current;

                if (currentTransaction != null)
                {
                    this.dependentTransaction = currentTransaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
                }

                try
                {
                    if (isWorkflowThread)
                    {
                        Fx.Assert(this.instance.Controller.IsPersistable, "The runtime won't schedule this work item unless we've passed the guard");

                        // We're an internal persistence on the workflow thread which means that we
                        // are passed the guard already, we have the lock, and we know we aren't detached.

                        completeSelf = this.InitializeProvider();
                        success      = true;
                    }
                    else
                    {
                        this.instanceOperation = new RequiresPersistenceOperation();
                        try
                        {
                            if (this.instance.WaitForTurnAsync(this.instanceOperation, this.timeoutHelper.RemainingTime(), waitCompleteCallback, this))
                            {
                                completeSelf = this.ValidateState();
                            }
                            else
                            {
                                completeSelf = false;
                            }
                            success = true;
                        }
                        finally
                        {
                            if (!success)
                            {
                                this.NotifyOperationComplete();
                            }
                        }
                    }
                }
                finally
                {
                    // If we had an exception, we need to complete the dependent transaction.
                    if (!success)
                    {
                        if (this.dependentTransaction != null)
                        {
                            this.dependentTransaction.Complete();
                        }
                    }
                }

                if (completeSelf)
                {
                    this.Complete(true);
                }
            }