Example #1
0
            private bool Persist()
            {
                IAsyncResult result = null;

                try
                {
                    if (this.data == null)
                    {
                        this.data = PersistenceManager.GenerateInitialData(this.instance);
                    }

                    if (this.context == null)
                    {
                        this.context = new WorkflowPersistenceContext(this.pipeline != null && this.pipeline.IsSaveTransactionRequired,
                                                                      this.dependentTransaction, this.timeoutHelper.OriginalTimeout);
                    }

                    using (this.PrepareTransactionalCall(this.context.PublicTransaction))
                    {
                        result = this.instance.persistenceManager.BeginSave(this.data, this.operation, this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(persistedCallback), this);
                    }
                }
                finally
                {
                    if (result == null && this.context != null)
                    {
                        this.context.Abort();
                    }
                }
                return(this.SyncContinue(result));
            }
Example #2
0
            private bool Load()
            {
                var          success = false;
                IAsyncResult result  = null;

                try
                {
                    var transactionRequired = this.application != null?this.application.IsLoadTransactionRequired() : false;

                    this.context = new WorkflowPersistenceContext(transactionRequired,
                                                                  this.dependentTransaction, this.timeoutHelper.OriginalTimeout);

                    // Values is null if this is an initial load from the database. It is non-null
                    // if we already loaded values into a WorkflowApplicationInstance, and are now
                    // loading from that WAI.
                    if (this.values == null)
                    {
                        using (this.PrepareTransactionalCall(this.context.PublicTransaction))
                        {
                            if (this.loadAny)
                            {
                                result = this.persistenceManager.BeginTryLoad(this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(loadCompleteCallback), this);
                            }
                            else
                            {
                                result = this.persistenceManager.BeginLoad(this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(loadCompleteCallback), this);
                            }
                        }
                    }
                    success = true;
                }
                finally
                {
                    if (!success && this.context != null)
                    {
                        this.context.Abort();
                    }
                }

                if (result == null)
                {
                    return(this.LoadValues(null));
                }
                else
                {
                    return(this.SyncContinue(result));
                }
            }
Example #3
0
            private bool Save()
            {
                if (this.pipeline != null)
                {
                    IAsyncResult result = null;
                    try
                    {
                        if (this.context == null)
                        {
                            this.context = new WorkflowPersistenceContext(this.pipeline.IsSaveTransactionRequired,
                                                                          this.dependentTransaction, this.timeoutHelper.RemainingTime());
                        }

                        this.instance.persistencePipelineInUse = this.pipeline;
                        Thread.MemoryBarrier();
                        if (this.instance.state == WorkflowApplicationState.Aborted)
                        {
                            throw FxTrace.Exception.AsError(new OperationCanceledException(SR.DefaultAbortReason));
                        }

                        using (this.PrepareTransactionalCall(this.context.PublicTransaction))
                        {
                            result = this.pipeline.BeginSave(this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(savedCallback), this);
                        }
                    }
                    finally
                    {
                        if (result == null)
                        {
                            this.instance.persistencePipelineInUse = null;
                            if (this.context != null)
                            {
                                this.context.Abort();
                            }
                        }
                    }
                    return(this.SyncContinue(result));
                }
                else
                {
                    return(this.CompleteContext());
                }
            }
            bool NotifyCompletion()
            {
                if (this.isUnloaded && this.instance.Controller.State == WorkflowInstanceState.Complete && this.instance.creationContext != null)
                {
                    IAsyncResult result = null;
                    try
                    {
                        if (this.context == null)
                        {
                            this.context = new WorkflowPersistenceContext(this.instance, this.isCompletionTransactionRequired,
                                this.dependentTransaction, this.instance.persistTimeout);
                        }

                        using (PrepareTransactionalCall(this.context.PublicTransaction))
                        {
                            result = this.instance.creationContext.OnBeginWorkflowCompleted(this.instance.completionState, this.instance.workflowOutputs, this.instance.terminationException,
                                this.timeoutHelper.RemainingTime(), PrepareInnerAsyncCompletion(notifyCompletionCallback), this);
                            if (result == null)
                            {
                                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowCompletionAsyncResultCannotBeNull));
                            }
                        }
                    }
                    finally
                    {
                        if (result == null && this.context != null)
                        {
                            this.context.Abort();
                        }
                    }
                    return SyncContinue(result);
                }
                else
                {
                    return CompleteContext();
                }
            }
            bool Save()
            {
                if (this.pipeline != null)
                {
                    IAsyncResult result = null;
                    try
                    {
                        if (this.context == null)
                        {
                            this.context = new WorkflowPersistenceContext(this.instance, this.pipeline.IsSaveTransactionRequired || this.isCompletionTransactionRequired,
                                this.dependentTransaction, this.instance.persistTimeout);
                        }

                        this.instance.persistencePipelineInUse = this.pipeline;
                        Thread.MemoryBarrier();
                        if (this.instance.abortingExtensions)
                        {
                            throw FxTrace.Exception.AsError(new OperationCanceledException(SR.DefaultAbortReason));
                        }

                        using (PrepareTransactionalCall(this.context.PublicTransaction))
                        {
                            result = this.pipeline.BeginSave(this.timeoutHelper.RemainingTime(), PrepareInnerAsyncCompletion(savedCallback), this);
                        }
                    }
                    finally
                    {
                        if (result == null)
                        {
                            this.instance.persistencePipelineInUse = null;
                            if (this.context != null)
                            {
                                this.context.Abort();
                            }
                        }
                    }
                    return SyncContinue(result);
                }
                else
                {
                    return NotifyCompletion();
                }
            }
            bool Persist()
            {
                IAsyncResult result = null;
                try
                {
                    if (this.operation == PersistenceOperation.Delete)
                    {
                        this.saveStatus = SaveStatus.Completed;
                    }

                    if (this.context == null)
                    {
                        this.context = new WorkflowPersistenceContext(this.instance, (this.pipeline != null && this.pipeline.IsSaveTransactionRequired) || this.isCompletionTransactionRequired,
                            this.dependentTransaction, this.instance.persistTimeout);
                    }

                    using (PrepareTransactionalCall(this.context.PublicTransaction))
                    {
                        result = this.instance.persistenceContext.BeginSave(this.data, this.saveStatus, this.instance.persistTimeout, PrepareInnerAsyncCompletion(persistedCallback), this);
                    }
                }
                catch (InstancePersistenceException)
                {
                    this.updateState = false;
                    throw;
                }
                finally
                {
                    if (result == null && this.context != null)
                    {
                        this.context.Abort();
                    }
                }

                return SyncContinue(result);
            }