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);
        }
Esempio n. 2
0
         private void InitializeComponent() 
         {
            this.CanModifyActivities = true;
            this.faultHandlersActivity1 = new FaultHandlersActivity();
            //
            //faultHandlersActivity1
            //
            this.faultHandlersActivity1.Name = "faultHandlersActivity1";
            //
            //FisBaseFlow
            //
            this.Activities.Add(this.faultHandlersActivity1);
            this.Name = "BaseFlow";
            this.CanModifyActivities = false;

        }
        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);
        }