public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection  errors   = base.Validate(manager, obj);
            EventHandlingScopeActivity activity = obj as EventHandlingScopeActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(EventHandlingScopeActivity).FullName }), "obj");
            }
            int num  = 0;
            int num2 = 0;

            foreach (Activity activity2 in activity.EnabledActivities)
            {
                if (activity2 is EventHandlersActivity)
                {
                    num2++;
                }
                else
                {
                    num++;
                }
            }
            if (num > 1)
            {
                errors.Add(new ValidationError(SR.GetString("Error_MoreThanTwoActivitiesInEventHandlingScope", new object[] { activity.QualifiedName }), 0x61e));
            }
            if (num2 > 1)
            {
                errors.Add(new ValidationError(SR.GetString("Error_MoreThanOneEventHandlersDecl", new object[] { activity.GetType().Name }), 0x527));
            }
            return(errors);
        }
Exemplo n.º 2
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            EventHandlingScopeActivity compositeActivity = obj as EventHandlingScopeActivity;

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

            //we only allow one activity to be inserted
            int childCount         = 0;
            int eventHandlersCount = 0;

            foreach (Activity child in compositeActivity.EnabledActivities)
            {
                if (child is EventHandlersActivity)
                {
                    eventHandlersCount++;
                }
                else
                {
                    childCount++;
                }
            }

            // check if more than two activities inside the collection
            if (childCount > 1)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanTwoActivitiesInEventHandlingScope, compositeActivity.QualifiedName), ErrorNumbers.Error_MoreThanTwoActivitiesInEventHandlingScope));
            }

            // check if more than one EventHandlers
            if (eventHandlersCount > 1)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanOneEventHandlersDecl, compositeActivity.GetType().Name), ErrorNumbers.Error_ScopeMoreThanOneEventHandlersDecl));
            }

            return(validationErrors);
        }