private bool CanHandleException(FaultHandlerActivity exceptionHandler, Type et)
        {
            Type faultType = exceptionHandler.FaultType;

            if (!(et == faultType))
            {
                return(et.IsSubclassOf(faultType));
            }
            return(true);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors   = base.Validate(manager, obj);
            FaultHandlersActivity     activity = obj as FaultHandlersActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(FaultHandlersActivity).FullName }), "obj");
            }
            Hashtable hashtable = new Hashtable();
            ArrayList list      = new ArrayList();
            bool      flag      = false;

            foreach (Activity activity2 in activity.EnabledActivities)
            {
                if (!(activity2 is FaultHandlerActivity))
                {
                    if (!flag)
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_FaultHandlersActivityDeclNotAllFaultHandlerActivityDecl"), 0x51e));
                        flag = true;
                    }
                }
                else
                {
                    FaultHandlerActivity activity3 = (FaultHandlerActivity)activity2;
                    Type faultType = activity3.FaultType;
                    if (faultType != null)
                    {
                        if (hashtable[faultType] == null)
                        {
                            hashtable[faultType] = 1;
                            list.Add(faultType);
                        }
                        else if (((int)hashtable[faultType]) == 1)
                        {
                            errors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ScopeDuplicateFaultHandlerActivityFor"), new object[] { Helpers.GetEnclosingActivity(activity).GetType().Name, faultType.FullName }), 0x520));
                            hashtable[faultType] = 2;
                        }
                        foreach (Type type2 in list)
                        {
                            if ((type2 != faultType) && type2.IsAssignableFrom(faultType))
                            {
                                errors.Add(new ValidationError(SR.GetString("Error_FaultHandlerActivityWrongOrder", new object[] { faultType.Name, type2.Name }), 0x521));
                            }
                        }
                    }
                }
            }
            if (activity.AlternateFlowActivities.Count > 0)
            {
                errors.Add(new ValidationError(SR.GetString("Error_ModelingConstructsCanNotContainModelingConstructs"), 0x61f));
            }
            return(errors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors   = base.Validate(manager, obj);
            FaultHandlerActivity      activity = obj as FaultHandlerActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(FaultHandlerActivity).FullName }), "obj");
            }
            if (!(activity.Parent is FaultHandlersActivity))
            {
                errors.Add(new ValidationError(SR.GetString("Error_FaultHandlerActivityParentNotFaultHandlersActivity"), 0x519));
            }
            if (!(manager.GetService(typeof(ITypeProvider)) is ITypeProvider))
            {
                throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
            }
            ValidationError item = null;

            if (activity.FaultType == null)
            {
                item = new ValidationError(SR.GetString("Error_TypePropertyInvalid", new object[] { "FaultType" }), 0x116)
                {
                    PropertyName = "FaultType"
                };
                errors.Add(item);
            }
            else if (!TypeProvider.IsAssignable(typeof(Exception), activity.FaultType))
            {
                item = new ValidationError(SR.GetString("Error_TypeTypeMismatch", new object[] { "FaultType", typeof(Exception).FullName }), 0x51a)
                {
                    PropertyName = "FaultType"
                };
                errors.Add(item);
            }
            if (activity.EnabledActivities.Count == 0)
            {
                errors.Add(new ValidationError(SR.GetString("Warning_EmptyBehaviourActivity", new object[] { typeof(FaultHandlerActivity).FullName, activity.QualifiedName }), 0x1a3, true));
            }
            if (activity.AlternateFlowActivities.Count > 0)
            {
                errors.Add(new ValidationError(SR.GetString("Error_ModelingConstructsCanNotContainModelingConstructs"), 0x61f));
            }
            return(errors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            FaultHandlersActivity exceptionHandlers = obj as FaultHandlersActivity;

            if (exceptionHandlers == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(FaultHandlersActivity).FullName), "obj");
            }

            Hashtable exceptionTypes                = new Hashtable();
            ArrayList previousExceptionTypes        = new ArrayList();
            bool      bFoundNotFaultHandlerActivity = false;

            foreach (Activity activity in exceptionHandlers.EnabledActivities)
            {
                // All child activities must be FaultHandlerActivity
                if (!(activity is FaultHandlerActivity))
                {
                    if (!bFoundNotFaultHandlerActivity)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlersActivityDeclNotAllFaultHandlerActivityDecl), ErrorNumbers.Error_FaultHandlersActivityDeclNotAllFaultHandlerActivityDecl));
                        bFoundNotFaultHandlerActivity = true;
                    }
                }
                else
                {
                    FaultHandlerActivity exceptionHandler = (FaultHandlerActivity)activity;
                    Type catchType = exceptionHandler.FaultType;
                    if (catchType != null)
                    {
                        if (exceptionTypes[catchType] == null)
                        {
                            exceptionTypes[catchType] = 1;
                            previousExceptionTypes.Add(catchType);
                        }
                        else if ((int)exceptionTypes[catchType] == 1)
                        {
                            /*if (catchType == typeof(System.Exception))
                             *  validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ScopeDuplicateFaultHandlerActivityForAll, exceptionHandlers.EnclosingDataContextActivity.GetType().Name), ErrorNumbers.Error_ScopeDuplicateFaultHandlerActivityForAll));
                             * else*/
                            validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_ScopeDuplicateFaultHandlerActivityFor), new object[] { Helpers.GetEnclosingActivity(exceptionHandlers).GetType().Name, catchType.FullName }), ErrorNumbers.Error_ScopeDuplicateFaultHandlerActivityFor));

                            exceptionTypes[catchType] = 2;
                        }

                        foreach (Type previousType in previousExceptionTypes)
                        {
                            if (previousType != catchType && previousType.IsAssignableFrom(catchType))
                            {
                                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityWrongOrder, catchType.Name, previousType.Name), ErrorNumbers.Error_FaultHandlerActivityWrongOrder));
                            }
                        }
                    }
                }
            }

            // fault handlers can not contain fault handlers, compensation handler and cancellation handler
            if (((ISupportAlternateFlow)exceptionHandlers).AlternateFlowActivities.Count > 0)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs));
            }

            return(validationErrors);
        }
        private bool CanHandleException(FaultHandlerActivity exceptionHandler, Type et)
        {
            Type canHandleType = exceptionHandler.FaultType;

            return(et == canHandleType || et.IsSubclassOf(canHandleType));
        }
Ejemplo n.º 6
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            FaultHandlerActivity exceptionHandler = obj as FaultHandlerActivity;

            if (exceptionHandler == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(FaultHandlerActivity).FullName), "obj");
            }

            // check parent must be exception handler
            if (!(exceptionHandler.Parent is FaultHandlersActivity))
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityParentNotFaultHandlersActivity), ErrorNumbers.Error_FaultHandlerActivityParentNotFaultHandlersActivity));
            }

            // validate exception property
            ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;

            if (typeProvider == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
            }

            // Validate the required Type property
            ValidationError error = null;

            if (exceptionHandler.FaultType == null)
            {
                error = new ValidationError(SR.GetString(SR.Error_TypePropertyInvalid, "FaultType"), ErrorNumbers.Error_PropertyNotSet);
                error.PropertyName = "FaultType";
                validationErrors.Add(error);
            }
            else if (!TypeProvider.IsAssignable(typeof(Exception), exceptionHandler.FaultType))
            {
                error = new ValidationError(SR.GetString(SR.Error_TypeTypeMismatch, new object[] { "FaultType", typeof(Exception).FullName }), ErrorNumbers.Error_TypeTypeMismatch);
                error.PropertyName = "FaultType";
                validationErrors.Add(error);
            }

            // Generate a warning for unrechable code, if the catch type is all and this is not the last exception handler.

            /*if (exceptionHandler.FaultType == typeof(System.Exception) && exceptionHandler.Parent is FaultHandlersActivity && ((FaultHandlersActivity)exceptionHandler.Parent).Activities.IndexOf(exceptionHandler) != ((FaultHandlersActivity)exceptionHandler.Parent).Activities.Count - 1)
             * {
             *  error = new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityAllMustBeLast), ErrorNumbers.Error_FaultHandlerActivityAllMustBeLast, true);
             *  error.PropertyName = "FaultType";
             *  validationErrors.Add(error);
             * }*/

            if (exceptionHandler.EnabledActivities.Count == 0)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Warning_EmptyBehaviourActivity, typeof(FaultHandlerActivity).FullName, exceptionHandler.QualifiedName), ErrorNumbers.Warning_EmptyBehaviourActivity, true));
            }

            // fault handler can not contain fault handlers, compensation handler and cancellation handler
            if (((ISupportAlternateFlow)exceptionHandler).AlternateFlowActivities.Count > 0)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs));
            }

            return(validationErrors);
        }