Example #1
0
            protected override void Execute(NativeActivityContext context)
            {
                IEnumerable <Activity> enumerable = this.ParentChain.Get(context);
                Rethrow  rethrow = this.RethrowActivity.Get(context);
                Activity item    = rethrow;
                bool     flag    = false;

                foreach (Activity activity2 in enumerable)
                {
                    if (activity2.ImplementationChildren.Contains(item))
                    {
                        flag = true;
                    }
                    TryCatch @catch = activity2 as TryCatch;
                    if ((@catch != null) && (item != null))
                    {
                        foreach (Catch catch2 in @catch.Catches)
                        {
                            ActivityDelegate action = catch2.GetAction();
                            if ((action != null) && (action.Handler == item))
                            {
                                if (flag)
                                {
                                    Constraint.AddValidationError(context, new ValidationError(System.Activities.SR.RethrowMustBeAPublicChild(rethrow.DisplayName), rethrow));
                                }
                                return;
                            }
                        }
                    }
                    item = activity2;
                }
                Constraint.AddValidationError(context, new ValidationError(System.Activities.SR.RethrowNotInATryCatch(rethrow.DisplayName), rethrow));
            }
Example #2
0
            protected override void Execute(NativeActivityContext context)
            {
                IEnumerable <Activity> parentChain = this.ParentChain.Get(context);
                Rethrow  rethrowActivity           = this.RethrowActivity.Get(context);
                Activity previousActivity          = rethrowActivity;
                bool     privateRethrow            = false;

                // TryCatch with Rethrow is usually authored in the following way:
                //
                // TryCatch
                // {
                //   Try = DoWork
                //   Catch Handler = Sequence
                //                   {
                //                     ProcessException,
                //                     Rethrow
                //                   }
                // }
                // Notice that the chain of Activities is TryCatch->Sequence->Rethrow
                // We want to validate that Rethrow is in the catch block of TryCatch
                // We walk up the parent chain until we find TryCatch.  Then we check if one the catch handlers points to Sequence(the previous activity in the tree)
                foreach (Activity parent in parentChain)
                {
                    // Rethrow is only allowed under the public children of a TryCatch activity.
                    // If any of the activities in the tree is a private child, report a constraint violation.
                    if (parent.ImplementationChildren.Contains(previousActivity))
                    {
                        privateRethrow = true;
                    }

                    TryCatch tryCatch = parent as TryCatch;
                    if (tryCatch != null)
                    {
                        if (previousActivity != null)
                        {
                            foreach (Catch catchHandler in tryCatch.Catches)
                            {
                                ActivityDelegate catchAction = catchHandler.GetAction();
                                if (catchAction != null && catchAction.Handler == previousActivity)
                                {
                                    if (privateRethrow)
                                    {
                                        Constraint.AddValidationError(context, new ValidationError(SR.RethrowMustBeAPublicChild(rethrowActivity.DisplayName), rethrowActivity));
                                    }
                                    return;
                                }
                            }
                        }
                    }

                    previousActivity = parent;
                }

                Constraint.AddValidationError(context, new ValidationError(SR.RethrowNotInATryCatch(rethrowActivity.DisplayName), rethrowActivity));
            }