Beispiel #1
0
            /// <summary>
            /// Called when [stage1 complete].
            /// </summary>
            /// <param name="lastResult">The last result.</param>
            /// <param name="instance">The instance.</param>
            /// <param name="isStillSync">if set to <c>true</c> [is still synchronize].</param>
            /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
            private bool OnStage1Complete(IAsyncResult?lastResult, WorkflowApplication instance, bool isStillSync)
            {
                if (lastResult != null)
                {
                    instance.Controller.EndFlushTrackingRecords(lastResult);
                }
                var completionState = instance.Controller.GetCompletionState(out var outputs, out var completionException);

                if (instance.invokeCompletedCallback == null)
                {
                    var handler = instance.Completed;

                    if (handler != null)
                    {
                        instance.handlerThreadId = Thread.CurrentThread.ManagedThreadId;

                        try
                        {
                            instance.isInHandler = true;
                            handler(new WorkflowApplicationCompletedEventArgs(instance, completionException, completionState, outputs));
                        }
                        finally
                        {
                            instance.isInHandler = false;
                        }
                    }
                }

                switch (completionState)
                {
                case ActivityInstanceState.Closed:
                    if (TD.WorkflowApplicationCompletedIsEnabled())
                    {
                        TD.WorkflowApplicationCompleted(instance.Id.ToString());
                    }
                    break;

                case ActivityInstanceState.Canceled:
                    if (TD.WorkflowInstanceCanceledIsEnabled())
                    {
                        TD.WorkflowInstanceCanceled(instance.Id.ToString());
                    }
                    break;

                case ActivityInstanceState.Faulted:
                    if (TD.WorkflowApplicationTerminatedIsEnabled())
                    {
                        TD.WorkflowApplicationTerminated(instance.Id.ToString(), completionException);
                    }
                    break;
                }

                IAsyncResult?result = null;

                Fx.Assert(instance.Controller.IsPersistable, "Should not be in a No Persist Zone once the instance is complete.");
                if (instance.persistenceManager != null || instance.HasPersistenceModule)
                {
                    instance.EventData.NextCallback = this.Stage2Callback;
                    result = instance.BeginInternalPersist(PersistenceOperation.Unload, ActivityDefaults.InternalSaveTimeout, true, EventFrameCallback, instance.EventData);

                    if (!result.CompletedSynchronously)
                    {
                        return(false);
                    }
                }
                else
                {
                    instance.MarkUnloaded();
                }

                return(this.OnStage2Complete(result, instance, isStillSync));
            }