示例#1
0
        void OnTryComplete(NativeActivityContext context, ActivityInstance completedInstance)
        {
            TryCatchState state = this.state.Get(context);

            // We only allow the Try to be canceled.
            state.SuppressCancel = true;

            if (state.CaughtException != null)
            {
                Catch toSchedule = FindCatch(state.CaughtException.Exception);

                if (toSchedule != null)
                {
                    state.ExceptionHandled = true;
                    if (toSchedule.GetAction() != null)
                    {
                        context.Properties.Add(FaultContextId, state.CaughtException, true);
                        toSchedule.ScheduleAction(context, state.CaughtException.Exception, new CompletionCallback(OnCatchComplete), this.ExceptionFromCatchOrFinallyHandler);
                        return;
                    }
                }
            }

            OnCatchComplete(context, null);
        }
示例#2
0
        void OnFinallyComplete(NativeActivityContext context, ActivityInstance completedInstance)
        {
            TryCatchState state = this.state.Get(context);

            if (context.IsCancellationRequested && !state.ExceptionHandled)
            {
                context.MarkCanceled();
            }
        }
示例#3
0
        protected override void Cancel(NativeActivityContext context)
        {
            TryCatchState state = this.state.Get(context);

            if (!state.SuppressCancel)
            {
                context.CancelChildren();
            }
        }
示例#4
0
        void OnExceptionFromCatchOrFinally(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            if (TD.TryCatchExceptionFromCatchOrFinallyIsEnabled())
            {
                TD.TryCatchExceptionFromCatchOrFinally(this.DisplayName);
            }

            // We allow cancel through if there is an exception from the catch or finally
            TryCatchState state = this.state.Get(context);

            state.SuppressCancel = false;
        }
示例#5
0
        protected override void UpdateInstance(NativeActivityUpdateContext updateContext)
        {
            TryCatchState state = updateContext.GetValue(this.state);

            if (state != null && !state.SuppressCancel && state.CaughtException != null && this.FindCatch(state.CaughtException.Exception) == null)
            {
                // This is a very small window of time in which we want to block update inside TryCatch.
                // This is in between OnExceptionFromTry faultHandler and OnTryComplete completionHandler.
                // A Catch handler could be found at OnExceptionFromTry before update, yet that appropriate Catch handler could have been removed during update and not be found at OnTryComplete.
                // In such case, the exception can be unintentionally ----ed without ever propagating it upward.
                // Such TryCatch state is detected by inspecting the TryCatchState private variable for SuppressCancel == false && CaughtException != Null && this.FindCatch(state.CaughtException.Exception) == null.
                updateContext.DisallowUpdate(SR.TryCatchInvalidStateForUpdate(state.CaughtException.Exception));
            }
        }
示例#6
0
        void OnExceptionFromTry(NativeActivityFaultContext context, Exception propagatedException, ActivityInstance propagatedFrom)
        {
            if (propagatedFrom.IsCancellationRequested)
            {
                if (TD.TryCatchExceptionDuringCancelationIsEnabled())
                {
                    TD.TryCatchExceptionDuringCancelation(this.DisplayName);
                }

                // The Try activity threw an exception during Cancel; abort the workflow
                context.Abort(propagatedException);
                context.HandleFault();
            }
            else
            {
                Catch catchHandler = FindCatch(propagatedException);
                if (catchHandler != null)
                {
                    if (TD.TryCatchExceptionFromTryIsEnabled())
                    {
                        TD.TryCatchExceptionFromTry(this.DisplayName, propagatedException.GetType().ToString());
                    }

                    context.CancelChild(propagatedFrom);
                    TryCatchState state = this.state.Get(context);

                    // If we are not supposed to persist exceptions, enter our noPersistScope
                    ExceptionPersistenceExtension extension = context.GetExtension <ExceptionPersistenceExtension>();
                    if ((extension != null) && !extension.PersistExceptions)
                    {
                        NoPersistProperty noPersistProperty = (NoPersistProperty)context.Properties.FindAtCurrentScope(NoPersistProperty.Name);
                        if (noPersistProperty != null)
                        {
                            // The property will be exited when the activity completes or aborts.
                            noPersistProperty.Enter();
                        }
                    }

                    state.CaughtException = context.CreateFaultContext();
                    context.HandleFault();
                }
            }
        }
        private void OnCatchComplete(NativeActivityContext context, System.Activities.ActivityInstance completedInstance)
        {
            TryCatchState state = this.state.Get(context);

            state.SuppressCancel = true;
            if ((completedInstance != null) && (completedInstance.State != ActivityInstanceState.Closed))
            {
                state.ExceptionHandled = false;
            }
            context.Properties.Remove("{35ABC8C3-9AF1-4426-8293-A6DDBB6ED91D}");
            if (this.Finally != null)
            {
                context.ScheduleActivity(this.Finally, new CompletionCallback(this.OnFinallyComplete), this.ExceptionFromCatchOrFinallyHandler);
            }
            else
            {
                this.OnFinallyComplete(context, null);
            }
        }
        private void OnTryComplete(NativeActivityContext context, System.Activities.ActivityInstance completedInstance)
        {
            TryCatchState state = this.state.Get(context);

            state.SuppressCancel = true;
            if (state.CaughtException != null)
            {
                Catch @catch = this.FindCatch(state.CaughtException.Exception);
                if (@catch != null)
                {
                    state.ExceptionHandled = true;
                    if (@catch.GetAction() != null)
                    {
                        context.Properties.Add("{35ABC8C3-9AF1-4426-8293-A6DDBB6ED91D}", state.CaughtException, true);
                        @catch.ScheduleAction(context, state.CaughtException.Exception, new CompletionCallback(this.OnCatchComplete), this.ExceptionFromCatchOrFinallyHandler);
                        return;
                    }
                }
            }
            this.OnCatchComplete(context, null);
        }
示例#9
0
        void OnCatchComplete(NativeActivityContext context, ActivityInstance completedInstance)
        {
            // Start suppressing cancel for the finally activity
            TryCatchState state = this.state.Get(context);

            state.SuppressCancel = true;

            if (completedInstance != null && completedInstance.State != ActivityInstanceState.Closed)
            {
                state.ExceptionHandled = false;
            }

            context.Properties.Remove(FaultContextId);

            if (this.Finally != null)
            {
                context.ScheduleActivity(this.Finally, new CompletionCallback(OnFinallyComplete), this.ExceptionFromCatchOrFinallyHandler);
            }
            else
            {
                OnFinallyComplete(context, null);
            }
        }