public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            CompositeActivity compositeActivity = obj as CompositeActivity;

            if (compositeActivity == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(CompositeActivity).FullName), "obj");
            }
            if (Helpers.IsActivityLocked(compositeActivity))
            {
                return(new ValidationErrorCollection());
            }

            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            // check if more than one cancellation handler or compensation or fault handlers are specified
            int cancelHandlerCount       = 0;
            int exceptionHandlersCount   = 0;
            int compensationHandlerCount = 0;

            foreach (Activity activity in ((ISupportAlternateFlow)compositeActivity).AlternateFlowActivities)
            {
                cancelHandlerCount       += (activity is CancellationHandlerActivity) ? 1 : 0;
                exceptionHandlersCount   += (activity is FaultHandlersActivity) ? 1 : 0;
                compensationHandlerCount += (activity is CompensationHandlerActivity) ? 1 : 0;
            }
            // check cancellation handlers
            if (cancelHandlerCount > 1)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanOneCancelHandler, compositeActivity.GetType().Name), ErrorNumbers.Error_ScopeMoreThanOneEventHandlersDecl));
            }

            // check exception handlers
            if (exceptionHandlersCount > 1)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanOneFaultHandlersActivityDecl, compositeActivity.GetType().Name), ErrorNumbers.Error_ScopeMoreThanOneFaultHandlersActivityDecl));
            }

            // check compensation handlers
            if (compensationHandlerCount > 1)
            {
                validationErrors.Add(new ValidationError(SR.GetString(SR.Error_MoreThanOneCompensationDecl, compositeActivity.GetType().Name), ErrorNumbers.Error_ScopeMoreThanOneCompensationDecl));
            }


            if (manager.ValidateChildActivities)
            {
                foreach (Activity childActivity in Helpers.GetAllEnabledActivities(compositeActivity))
                {
                    validationErrors.AddRange(ValidationHelpers.ValidateActivity(manager, childActivity));
                }
            }
            return(validationErrors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            Activity context = obj as Activity;

            if (context == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj");
            }
            if (manager.Context == null)
            {
                throw new ArgumentException("manager", SR.GetString("Error_MissingContextProperty"));
            }
            manager.Context.Push(context);
            ValidationErrorCollection errors = new ValidationErrorCollection();

            errors.AddRange(base.Validate(manager, obj));
            if (context.Parent == null)
            {
                errors.AddRange(ValidationHelpers.ValidateUniqueIdentifiers(context));
                if (!context.Enabled)
                {
                    ValidationError item = new ValidationError(SR.GetString("Error_RootIsNotEnabled"), 0x628)
                    {
                        PropertyName = "Enabled"
                    };
                    errors.Add(item);
                }
            }
            Activity rootActivity = Helpers.GetRootActivity(context);

            if (context != rootActivity)
            {
                ValidationError error2 = ValidationHelpers.ValidateNameProperty("Name", manager, context.Name);
                if (error2 != null)
                {
                    errors.Add(error2);
                }
            }
            try
            {
                errors.AddRange(this.ValidateProperties(manager, obj));
            }
            finally
            {
                manager.Context.Pop();
            }
            return(errors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            Activity activity = obj as Activity;

            if (activity == null)
            {
                return(validationErrors);
            }

            ICollection <string> synchronizationHandles = activity.GetValue(Activity.SynchronizationHandlesProperty) as ICollection <string>;

            if (synchronizationHandles != null)
            {
                foreach (string handle in synchronizationHandles)
                {
                    ValidationError error = ValidationHelpers.ValidateIdentifier("SynchronizationHandles", manager, handle);
                    if (error != null)
                    {
                        validationErrors.Add(error);
                    }
                }
            }
            return(validationErrors);
        }
예제 #4
0
        private static ValidationErrorCollection ValidateIdentifiers(IServiceProvider serviceProvider, Activity activity)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();
            Dictionary <string, int>  names            = new Dictionary <string, int>();

            Walker walker = new Walker();

            walker.FoundActivity += delegate(Walker walker2, WalkerEventArgs e)
            {
                Activity currentActivity = e.CurrentActivity;
                if (!currentActivity.Enabled)
                {
                    e.Action = WalkerAction.Skip;
                    return;
                }

                ValidationError identifierError = null;

                if (names.ContainsKey(currentActivity.QualifiedName))
                {
                    if (names[currentActivity.QualifiedName] != 1)
                    {
                        identifierError = new ValidationError(SR.GetString(SR.Error_DuplicatedActivityID, currentActivity.QualifiedName), ErrorNumbers.Error_DuplicatedActivityID, false, "Name");
                        identifierError.UserData[typeof(Activity)] = currentActivity;
                        validationErrors.Add(identifierError);
                        names[currentActivity.QualifiedName] = 1;
                    }

                    return;
                }
                // Undone: AkashS - remove this check when we allow root activities to not have a name.
                if (!string.IsNullOrEmpty(currentActivity.Name))
                {
                    names[currentActivity.Name] = 0;
                    identifierError             = ValidationHelpers.ValidateIdentifier("Name", serviceProvider, currentActivity.Name);
                    if (identifierError != null)
                    {
                        identifierError.UserData[typeof(Activity)] = currentActivity;
                        validationErrors.Add(identifierError);
                    }
                }
            };

            walker.Walk(activity as Activity);
            return(validationErrors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);
            PropertyBind bind = obj as PropertyBind;

            if (bind == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(PropertyBind).FullName }), "obj");
            }
            PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;

            if (validationContext == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name }));
            }
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
            }
            ValidationError item = null;

            if (string.IsNullOrEmpty(bind.Name))
            {
                item = new ValidationError(SR.GetString("Error_PropertyNotSet", new object[] { "Name" }), 0x116)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
            }
            else
            {
                BindValidationContext context2 = manager.Context[typeof(BindValidationContext)] as BindValidationContext;
                if (context2 == null)
                {
                    Type baseType = BindHelpers.GetBaseType(manager, validationContext);
                    if (baseType != null)
                    {
                        AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext);
                        context2 = new BindValidationContext(baseType, accessType);
                    }
                }
                if (context2 != null)
                {
                    Type targetType = context2.TargetType;
                    if (item == null)
                    {
                        errors.AddRange(this.ValidateBindProperty(manager, activity, bind, new BindValidationContext(targetType, context2.Access)));
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
예제 #6
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            CompositeActivity activity = obj as CompositeActivity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(CompositeActivity).FullName }), "obj");
            }
            if (Helpers.IsActivityLocked(activity))
            {
                return(new ValidationErrorCollection());
            }
            ValidationErrorCollection errors = base.Validate(manager, obj);
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            foreach (Activity activity2 in ((ISupportAlternateFlow)activity).AlternateFlowActivities)
            {
                num  += (activity2 is CancellationHandlerActivity) ? 1 : 0;
                num2 += (activity2 is FaultHandlersActivity) ? 1 : 0;
                num3 += (activity2 is CompensationHandlerActivity) ? 1 : 0;
            }
            if (num > 1)
            {
                errors.Add(new ValidationError(SR.GetString("Error_MoreThanOneCancelHandler", new object[] { activity.GetType().Name }), 0x527));
            }
            if (num2 > 1)
            {
                errors.Add(new ValidationError(SR.GetString("Error_MoreThanOneFaultHandlersActivityDecl", new object[] { activity.GetType().Name }), 0x52a));
            }
            if (num3 > 1)
            {
                errors.Add(new ValidationError(SR.GetString("Error_MoreThanOneCompensationDecl", new object[] { activity.GetType().Name }), 0x52b));
            }
            if (manager.ValidateChildActivities)
            {
                foreach (Activity activity3 in Helpers.GetAllEnabledActivities(activity))
                {
                    errors.AddRange(ValidationHelpers.ValidateActivity(manager, activity3));
                }
            }
            return(errors);
        }
예제 #7
0
        private ValidationErrorCollection ValidateEvent(Activity activity, DependencyProperty dependencyProperty, object propValue, ValidationManager manager)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();

            if (propValue is string && !string.IsNullOrEmpty((string)propValue))
            {
                bool     handlerExists     = false;
                Type     objType           = null;
                Activity rootActivity      = Helpers.GetRootActivity(activity);
                Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
                string   typeName          = rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
                if (rootActivity == enclosingActivity && !string.IsNullOrEmpty(typeName))
                {
                    ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                    if (typeProvider == null)
                    {
                        throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName));
                    }

                    objType = typeProvider.GetType(typeName);
                }
                else
                {
                    objType = enclosingActivity.GetType();
                }

                if (objType != null)
                {
                    MethodInfo invokeMethod = dependencyProperty.PropertyType.GetMethod("Invoke");
                    if (invokeMethod != null)
                    {
                        // resolve the method
                        List <Type> paramTypes = new List <Type>();
                        foreach (ParameterInfo paramInfo in invokeMethod.GetParameters())
                        {
                            paramTypes.Add(paramInfo.ParameterType);
                        }

                        MethodInfo methodInfo = Helpers.GetMethodExactMatch(objType, propValue as string, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, paramTypes.ToArray(), null);
                        if (methodInfo != null && TypeProvider.IsAssignable(invokeMethod.ReturnType, methodInfo.ReturnType))
                        {
                            handlerExists = true;
                        }
                    }
                }

                if (!handlerExists)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_CantResolveEventHandler, dependencyProperty.Name, propValue as string), ErrorNumbers.Error_CantResolveEventHandler);
                    error.PropertyName = GetFullPropertyName(manager);
                    validationErrors.Add(error);
                }
            }

            return(validationErrors);
        }
        internal static ValidationErrorCollection MorphIntoFriendlyValidationErrors(IEnumerable <ValidationError> errors)
        {
            ValidationErrorCollection errors2 = new ValidationErrorCollection();

            foreach (ValidationError error in errors)
            {
                if (error != null)
                {
                    if (error.GetType() == typeof(ValidationError))
                    {
                        ValidationError item = new ValidationError(GetPrettifiedErrorText(error), error.ErrorNumber, error.IsWarning);
                        errors2.Add(item);
                    }
                    else
                    {
                        errors2.Add(error);
                    }
                }
            }
            return(errors2);
        }
예제 #9
0
        private static ValidationErrorCollection ValidateIdentifiers(IServiceProvider serviceProvider, Activity activity)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();
            Dictionary <string, int>  names            = new Dictionary <string, int>();
            Walker walker = new Walker();

            walker.FoundActivity += delegate(Walker walker2, WalkerEventArgs e) {
                Activity currentActivity = e.CurrentActivity;
                if (!currentActivity.Enabled)
                {
                    e.Action = WalkerAction.Skip;
                }
                else
                {
                    ValidationError item = null;
                    if (names.ContainsKey(currentActivity.QualifiedName))
                    {
                        if (names[currentActivity.QualifiedName] != 1)
                        {
                            item = new ValidationError(SR.GetString("Error_DuplicatedActivityID", new object[] { currentActivity.QualifiedName }), 0x602, false, "Name");
                            item.UserData[typeof(Activity)] = currentActivity;
                            validationErrors.Add(item);
                            names[currentActivity.QualifiedName] = 1;
                        }
                    }
                    else if (!string.IsNullOrEmpty(currentActivity.Name))
                    {
                        names[currentActivity.Name] = 0;
                        item = ValidationHelpers.ValidateIdentifier("Name", serviceProvider, currentActivity.Name);
                        if (item != null)
                        {
                            item.UserData[typeof(Activity)] = currentActivity;
                            validationErrors.Add(item);
                        }
                    }
                }
            };
            walker.Walk(activity);
            return(validationErrors);
        }
        private ValidationErrorCollection ValidateEvent(Activity activity, DependencyProperty dependencyProperty, object propValue, ValidationManager manager)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            if ((propValue is string) && !string.IsNullOrEmpty((string)propValue))
            {
                bool     flag              = false;
                Type     type              = null;
                Activity rootActivity      = Helpers.GetRootActivity(activity);
                Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
                string   str = rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string;
                if ((rootActivity == enclosingActivity) && !string.IsNullOrEmpty(str))
                {
                    ITypeProvider service = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                    if (service == null)
                    {
                        throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                    }
                    type = service.GetType(str);
                }
                else
                {
                    type = enclosingActivity.GetType();
                }
                if (type != null)
                {
                    MethodInfo method = dependencyProperty.PropertyType.GetMethod("Invoke");
                    if (method != null)
                    {
                        List <Type> list = new List <Type>();
                        foreach (ParameterInfo info2 in method.GetParameters())
                        {
                            list.Add(info2.ParameterType);
                        }
                        MethodInfo info3 = Helpers.GetMethodExactMatch(type, propValue as string, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, list.ToArray(), null);
                        if ((info3 != null) && TypeProvider.IsAssignable(method.ReturnType, info3.ReturnType))
                        {
                            flag = true;
                        }
                    }
                }
                if (!flag)
                {
                    ValidationError item = new ValidationError(SR.GetString("Error_CantResolveEventHandler", new object[] { dependencyProperty.Name, propValue as string }), 0x60f)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                    errors.Add(item);
                }
            }
            return(errors);
        }
예제 #11
0
        internal static ValidationErrorCollection MorphIntoFriendlyValidationErrors(IEnumerable <ValidationError> errors)
        {
            ValidationErrorCollection friendlyErrors = new ValidationErrorCollection();

            foreach (ValidationError error in errors)
            {
                if (error == null)
                {
                    continue;
                }

                if (error.GetType() == typeof(ValidationError))
                {
                    ValidationError error2 = new ValidationError(GetPrettifiedErrorText(error), error.ErrorNumber, error.IsWarning);
                    friendlyErrors.Add(error2);
                }
                else
                {
                    friendlyErrors.Add(error);
                }
            }

            return(friendlyErrors);
        }
예제 #12
0
        internal static ValidationErrorCollection ValidateUniqueIdentifiers(Activity rootActivity)
        {
            if (rootActivity == null)
            {
                throw new ArgumentNullException("rootActivity");
            }

            Hashtable identifiers = new Hashtable();
            ValidationErrorCollection validationErrors = new ValidationErrorCollection();
            Queue activities = new Queue();

            activities.Enqueue(rootActivity);
            while (activities.Count > 0)
            {
                Activity activity = (Activity)activities.Dequeue();
                if (activity.Enabled)
                {
                    if (identifiers.ContainsKey(activity.QualifiedName))
                    {
                        ValidationError duplicateError = new ValidationError(SR.GetString(SR.Error_DuplicatedActivityID, activity.QualifiedName), ErrorNumbers.Error_DuplicatedActivityID);
                        duplicateError.PropertyName = "Name";
                        duplicateError.UserData[typeof(Activity)] = activity;
                        validationErrors.Add(duplicateError);
                    }
                    else
                    {
                        identifiers.Add(activity.QualifiedName, activity);
                    }

                    if (activity is CompositeActivity && ((activity.Parent == null) || !Helpers.IsCustomActivity(activity as CompositeActivity)))
                    {
                        foreach (Activity child in Helpers.GetAllEnabledActivities((CompositeActivity)activity))
                        {
                            activities.Enqueue(child);
                        }
                    }
                }
            }

            return(validationErrors);
        }
예제 #13
0
        private ValidationErrorCollection ValidateActivityBind(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);
            ActivityBind bind = obj as ActivityBind;
            PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;

            if (validationContext == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name }));
            }
            if (!(manager.Context[typeof(Activity)] is Activity))
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
            }
            ValidationError       item     = null;
            BindValidationContext context2 = manager.Context[typeof(BindValidationContext)] as BindValidationContext;

            if (context2 == null)
            {
                Type baseType = BindHelpers.GetBaseType(manager, validationContext);
                if (baseType != null)
                {
                    AccessTypes accessType = BindHelpers.GetAccessType(manager, validationContext);
                    context2 = new BindValidationContext(baseType, accessType);
                }
            }
            if (context2 != null)
            {
                Type targetType = context2.TargetType;
                if (item == null)
                {
                    errors.AddRange(this.ValidateActivity(manager, bind, new BindValidationContext(targetType, context2.Access)));
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
        internal static ValidationErrorCollection ValidateUniqueIdentifiers(Activity rootActivity)
        {
            if (rootActivity == null)
            {
                throw new ArgumentNullException("rootActivity");
            }
            Hashtable hashtable = new Hashtable();
            ValidationErrorCollection errors = new ValidationErrorCollection();
            Queue queue = new Queue();

            queue.Enqueue(rootActivity);
            while (queue.Count > 0)
            {
                Activity activity = (Activity)queue.Dequeue();
                if (activity.Enabled)
                {
                    if (hashtable.ContainsKey(activity.QualifiedName))
                    {
                        ValidationError item = new ValidationError(SR.GetString("Error_DuplicatedActivityID", new object[] { activity.QualifiedName }), 0x602)
                        {
                            PropertyName = "Name"
                        };
                        item.UserData[typeof(Activity)] = activity;
                        errors.Add(item);
                    }
                    else
                    {
                        hashtable.Add(activity.QualifiedName, activity);
                    }
                    if ((activity is CompositeActivity) && ((activity.Parent == null) || !Helpers.IsCustomActivity(activity as CompositeActivity)))
                    {
                        foreach (Activity activity2 in Helpers.GetAllEnabledActivities((CompositeActivity)activity))
                        {
                            queue.Enqueue(activity2);
                        }
                    }
                }
            }
            return(errors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);
            Activity activity = obj as Activity;

            if (activity != null)
            {
                ICollection <string> is2 = activity.GetValue(Activity.SynchronizationHandlesProperty) as ICollection <string>;
                if (is2 == null)
                {
                    return(errors);
                }
                foreach (string str in is2)
                {
                    ValidationError item = ValidationHelpers.ValidateIdentifier("SynchronizationHandles", manager, str);
                    if (item != null)
                    {
                        errors.Add(item);
                    }
                }
            }
            return(errors);
        }
예제 #16
0
        private ValidationErrorCollection ValidateMethod(ValidationManager manager, Activity activity, MethodBind bind, BindValidationContext validationBindContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            if ((validationBindContext.Access & AccessTypes.Write) != 0)
            {
                ValidationError item = new ValidationError(SR.GetString("Error_HandlerReadOnly"), 0x133)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
                errors.Add(item);
                return(errors);
            }
            if (!TypeProvider.IsAssignable(typeof(Delegate), validationBindContext.TargetType))
            {
                ValidationError error2 = new ValidationError(SR.GetString("Error_TypeNotDelegate", new object[] { validationBindContext.TargetType.FullName }), 0x134)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
                errors.Add(error2);
                return(errors);
            }
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);

            if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
            {
                enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (enclosingActivity == null)
            {
                ValidationError error3 = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error3);
                return(errors);
            }
            string errorText       = string.Empty;
            int    errorNumber     = -1;
            Type   dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);

            if (dataSourceClass == null)
            {
                errorText   = SR.GetString("Error_TypeNotResolvedInMethodName", new object[] { base.GetFullPropertyName(manager) + ".Name" });
                errorNumber = 0x135;
            }
            else
            {
                try
                {
                    ValidationHelpers.ValidateIdentifier(manager, name);
                }
                catch (Exception exception)
                {
                    errors.Add(new ValidationError(exception.Message, 0x119));
                }
                MethodInfo method = validationBindContext.TargetType.GetMethod("Invoke");
                if (method == null)
                {
                    throw new Exception(SR.GetString("Error_DelegateNoInvoke", new object[] { validationBindContext.TargetType.FullName }));
                }
                List <Type> list = new List <Type>();
                foreach (ParameterInfo info2 in method.GetParameters())
                {
                    list.Add(info2.ParameterType);
                }
                MethodInfo info3 = Helpers.GetMethodExactMatch(dataSourceClass, name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, null, list.ToArray(), null);
                if (info3 == null)
                {
                    if (dataSourceClass.GetMethod(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance) != null)
                    {
                        errorText   = SR.GetString("Error_MethodSignatureMismatch", new object[] { base.GetFullPropertyName(manager) + ".Name" });
                        errorNumber = 310;
                    }
                    else
                    {
                        errorText   = SR.GetString("Error_MethodNotExists", new object[] { base.GetFullPropertyName(manager) + ".Name", bind.Name });
                        errorNumber = 0x137;
                    }
                }
                else if (!method.ReturnType.Equals(info3.ReturnType))
                {
                    errorText   = SR.GetString("Error_MethodReturnTypeMismatch", new object[] { base.GetFullPropertyName(manager), method.ReturnType.FullName });
                    errorNumber = 0x139;
                }
            }
            if (errorText.Length > 0)
            {
                ValidationError error4 = new ValidationError(errorText, errorNumber)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
                errors.Add(error4);
            }
            return(errors);
        }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            Activity activity = obj as Activity;

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

            WorkflowTransactionOptions atomicTransaction = TransactedContextFilter.GetTransactionOptions(activity);

            if (atomicTransaction != null)
            {
                // Atomic scopes can't have exception handlers.
                CompositeActivity exceptionHandlers = FaultAndCancellationHandlingFilter.GetFaultHandlers(activity);
                if (exceptionHandlers != null)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_AtomicScopeWithFaultHandlersActivityDecl, activity.Name), ErrorNumbers.Error_AtomicScopeWithFaultHandlersActivityDecl);
                    validationErrors.Add(error);
                }

                // Atomic scopes can't have cancel handlers.
                Activity cancellationHandler = FaultAndCancellationHandlingFilter.GetCancellationHandler(activity);
                if (cancellationHandler != null)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_AtomicScopeWithCancellationHandlerActivity, activity.Name), ErrorNumbers.Error_AtomicScopeWithCancellationHandlerActivity);
                    validationErrors.Add(error);
                }

                // check that this transaction scope is not nested inside another transaction scope
                Activity parent = activity.Parent;
                while (parent != null)
                {
                    if (parent.SupportsTransaction)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_AtomicScopeNestedInNonLRT), ErrorNumbers.Error_AtomicScopeNestedInNonLRT));
                        break;
                    }
                    parent = parent.Parent;
                }

                // check that an activity with PersistOnClose/SupportsTransaction/ICompensatableActivity attribute is not nested inside the transaction scope
                Queue <Activity> nestedEnabledActivities = new Queue <Activity>(Helpers.GetAllEnabledActivities((CompositeActivity)activity));
                while (nestedEnabledActivities.Count > 0)
                {
                    Activity nestedEnabledActivity = nestedEnabledActivities.Dequeue();
                    if (nestedEnabledActivity.PersistOnClose)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_LRTScopeNestedInNonLRT), ErrorNumbers.Error_LRTScopeNestedInNonLRT));
                        break;
                    }
                    if (nestedEnabledActivity is ICompensatableActivity)
                    {
                        validationErrors.Add(new ValidationError(SR.GetString(SR.Error_NestedCompensatableActivity, nestedEnabledActivity.QualifiedName), ErrorNumbers.Error_NestedCompensatableActivity));
                        break;
                    }

                    if (nestedEnabledActivity is CompositeActivity)
                    {
                        foreach (Activity nestedEnabledActivity2 in Helpers.GetAllEnabledActivities((CompositeActivity)nestedEnabledActivity))
                        {
                            nestedEnabledActivities.Enqueue(nestedEnabledActivity2);
                        }
                    }
                }

                // check timeout property
                if (atomicTransaction.TimeoutDuration.Ticks < 0)
                {
                    ValidationError timeoutError = new ValidationError(SR.GetString(SR.Error_NegativeValue, new object[] { atomicTransaction.TimeoutDuration.ToString(), "TimeoutDuration" }), ErrorNumbers.Error_NegativeValue);
                    timeoutError.PropertyName = "TimeoutDuration";
                    validationErrors.Add(timeoutError);
                }
            }
            return(validationErrors);
        }
        private ValidationErrorCollection ValidateBindProperty(ValidationManager manager, Activity activity, PropertyBind bind, BindValidationContext validationContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);
            Activity refActivity       = enclosingActivity;

            if ((name.IndexOf('.') != -1) && (refActivity != null))
            {
                refActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (refActivity == null)
            {
                ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error);
                return(errors);
            }
            ValidationError item         = null;
            PropertyInfo    property     = null;
            Type            activityType = null;

            if (property == null)
            {
                activityType = BindValidatorHelper.GetActivityType(manager, refActivity);
                if (activityType != null)
                {
                    property = activityType.GetProperty(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                }
            }
            if (activityType == null)
            {
                item = new ValidationError(SR.GetString("Error_TypeNotResolvedInPropertyName", new object[] { "Name" }), 0x163)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x164)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (!property.CanRead)
            {
                item = new ValidationError(SR.GetString("Error_PropertyReferenceNoGetter", new object[] { base.GetFullPropertyName(manager), name }), 360)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property.GetGetMethod() == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyReferenceGetterNoAccess", new object[] { base.GetFullPropertyName(manager), name }), 0x60a)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (((refActivity != enclosingActivity) && !property.GetGetMethod().IsAssembly) && !property.GetGetMethod().IsPublic)
            {
                item = new ValidationError(SR.GetString("Error_PropertyNotAccessible", new object[] { base.GetFullPropertyName(manager), name }), 0x165)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else if (property.PropertyType == null)
            {
                item = new ValidationError(SR.GetString("Error_PropertyTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 0x166)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else
            {
                MemberInfo memberInfo = property;
                if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, property.PropertyType, validationContext.Access)))
                {
                    item = new ValidationError(SR.GetString("Error_PropertyTypeMismatch", new object[] { base.GetFullPropertyName(manager), property.PropertyType.FullName, validationContext.TargetType.FullName }), 0x167)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else if (!string.IsNullOrEmpty(bind.Path))
                {
                    memberInfo = MemberBind.GetMemberInfo(property.PropertyType, bind.Path);
                    if (memberInfo == null)
                    {
                        item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300)
                        {
                            PropertyName = base.GetFullPropertyName(manager) + ".Path"
                        };
                    }
                    else
                    {
                        using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                        {
                            if (WorkflowCompilationContext.Current.CheckTypes)
                            {
                                item = MemberBind.ValidateTypesInPath(property.PropertyType, bind.Path);
                                if (item != null)
                                {
                                    item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                                }
                            }
                        }
                        if (item == null)
                        {
                            Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                            if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                    }
                }
                if (item == null)
                {
                    if (memberInfo is PropertyInfo)
                    {
                        PropertyInfo info3 = memberInfo as PropertyInfo;
                        if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                    else if (memberInfo is FieldInfo)
                    {
                        FieldInfo info4 = memberInfo as FieldInfo;
                        if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                        {
                            item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
예제 #19
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);
            Activity activity = obj as Activity;

            if (activity == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(Activity).FullName }), "obj");
            }
            WorkflowTransactionOptions transactionOptions = TransactedContextFilter.GetTransactionOptions(activity);

            if (transactionOptions != null)
            {
                if (FaultAndCancellationHandlingFilter.GetFaultHandlers(activity) != null)
                {
                    ValidationError item = new ValidationError(SR.GetString("Error_AtomicScopeWithFaultHandlersActivityDecl", new object[] { activity.Name }), 0x52c);
                    errors.Add(item);
                }
                if (FaultAndCancellationHandlingFilter.GetCancellationHandler(activity) != null)
                {
                    ValidationError error2 = new ValidationError(SR.GetString("Error_AtomicScopeWithCancellationHandlerActivity", new object[] { activity.Name }), 0x575);
                    errors.Add(error2);
                }
                for (Activity activity4 = activity.Parent; activity4 != null; activity4 = activity4.Parent)
                {
                    if (activity4.SupportsTransaction)
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_AtomicScopeNestedInNonLRT"), 0x52e));
                        break;
                    }
                }
                Queue <Activity> queue = new Queue <Activity>(Helpers.GetAllEnabledActivities((CompositeActivity)activity));
                while (queue.Count > 0)
                {
                    Activity activity5 = queue.Dequeue();
                    if (activity5.PersistOnClose)
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_LRTScopeNestedInNonLRT"), 0x52f));
                        break;
                    }
                    if (activity5 is ICompensatableActivity)
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_NestedCompensatableActivity", new object[] { activity5.QualifiedName }), 0x1a6));
                        break;
                    }
                    if (activity5 is CompositeActivity)
                    {
                        foreach (Activity activity6 in Helpers.GetAllEnabledActivities((CompositeActivity)activity5))
                        {
                            queue.Enqueue(activity6);
                        }
                    }
                }
                if (transactionOptions.TimeoutDuration.Ticks < 0L)
                {
                    ValidationError error3 = new ValidationError(SR.GetString("Error_NegativeValue", new object[] { transactionOptions.TimeoutDuration.ToString(), "TimeoutDuration" }), 0x531)
                    {
                        PropertyName = "TimeoutDuration"
                    };
                    errors.Add(error3);
                }
            }
            return(errors);
        }
        private ValidationErrorCollection ValidateDependencyProperty(DependencyObject dependencyObject, DependencyProperty dependencyProperty, ValidationManager manager)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            Attribute[]      attributes    = dependencyProperty.DefaultMetadata.GetAttributes(typeof(ValidationOptionAttribute));
            ValidationOption option        = (attributes.Length > 0) ? ((ValidationOptionAttribute)attributes[0]).ValidationOption : ValidationOption.Optional;
            Activity         propertyOwner = manager.Context[typeof(Activity)] as Activity;

            if (propertyOwner == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).FullName }));
            }
            PropertyValidationContext context = new PropertyValidationContext(propertyOwner, dependencyProperty);

            manager.Context.Push(context);
            try
            {
                if (dependencyProperty.DefaultMetadata.DefaultValue != null)
                {
                    if (!dependencyProperty.PropertyType.IsValueType && (dependencyProperty.PropertyType != typeof(string)))
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_PropertyDefaultIsReference", new object[] { dependencyProperty.Name }), 0x1a8));
                    }
                    else if (!dependencyProperty.PropertyType.IsAssignableFrom(dependencyProperty.DefaultMetadata.DefaultValue.GetType()))
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_PropertyDefaultTypeMismatch", new object[] { dependencyProperty.Name, dependencyProperty.PropertyType.FullName, dependencyProperty.DefaultMetadata.DefaultValue.GetType().FullName }), 0x1a9));
                    }
                }
                object propValue = null;
                if (dependencyObject.IsBindingSet(dependencyProperty))
                {
                    propValue = dependencyObject.GetBinding(dependencyProperty);
                }
                else if (!dependencyProperty.IsEvent)
                {
                    propValue = dependencyObject.GetValue(dependencyProperty);
                }
                if ((propValue == null) || (propValue == dependencyProperty.DefaultMetadata.DefaultValue))
                {
                    if (dependencyProperty.IsEvent)
                    {
                        propValue = dependencyObject.GetHandler(dependencyProperty);
                        if (propValue == null)
                        {
                            propValue = WorkflowMarkupSerializationHelpers.GetEventHandlerName(dependencyObject, dependencyProperty.Name);
                        }
                        if ((propValue is string) && !string.IsNullOrEmpty((string)propValue))
                        {
                            errors.AddRange(this.ValidateEvent(propertyOwner, dependencyProperty, propValue, manager));
                        }
                    }
                    else
                    {
                        propValue = dependencyObject.GetValue(dependencyProperty);
                    }
                }
                bool flag = (propertyOwner.Parent != null) || ((propertyOwner is CompositeActivity) && (((CompositeActivity)propertyOwner).EnabledActivities.Count != 0));
                if (((option == ValidationOption.Required) && ((propValue == null) || ((propValue is string) && string.IsNullOrEmpty((string)propValue)))) && (dependencyProperty.DefaultMetadata.IsMetaProperty && flag))
                {
                    errors.Add(ValidationError.GetNotSetValidationError(base.GetFullPropertyName(manager)));
                    return(errors);
                }
                if (propValue == null)
                {
                    return(errors);
                }
                if (propValue is IList)
                {
                    PropertyValidationContext context2 = new PropertyValidationContext(propValue, null, string.Empty);
                    manager.Context.Push(context2);
                    try
                    {
                        foreach (object obj3 in (IList)propValue)
                        {
                            errors.AddRange(ValidationHelpers.ValidateObject(manager, obj3));
                        }
                        return(errors);
                    }
                    finally
                    {
                        manager.Context.Pop();
                    }
                }
                if (dependencyProperty.ValidatorType != null)
                {
                    Validator validator = null;
                    try
                    {
                        validator = Activator.CreateInstance(dependencyProperty.ValidatorType) as Validator;
                        if (validator == null)
                        {
                            errors.Add(new ValidationError(SR.GetString("Error_CreateValidator", new object[] { dependencyProperty.ValidatorType.FullName }), 0x106));
                            return(errors);
                        }
                        errors.AddRange(validator.Validate(manager, propValue));
                        return(errors);
                    }
                    catch
                    {
                        errors.Add(new ValidationError(SR.GetString("Error_CreateValidator", new object[] { dependencyProperty.ValidatorType.FullName }), 0x106));
                        return(errors);
                    }
                }
                errors.AddRange(ValidationHelpers.ValidateObject(manager, propValue));
            }
            finally
            {
                manager.Context.Pop();
            }
            return(errors);
        }
        private ValidationErrorCollection ValidateField(ValidationManager manager, Activity activity, FieldBind bind, BindValidationContext validationContext)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();
            string   name = bind.Name;
            Activity enclosingActivity = Helpers.GetEnclosingActivity(activity);

            if ((name.IndexOf('.') != -1) && (enclosingActivity != null))
            {
                enclosingActivity = Helpers.GetDataSourceActivity(activity, bind.Name, out name);
            }
            if (enclosingActivity == null)
            {
                ValidationError error = new ValidationError(SR.GetString("Error_NoEnclosingContext", new object[] { activity.Name }), 0x130)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(error);
                return(errors);
            }
            ValidationError item            = null;
            Type            dataSourceClass = Helpers.GetDataSourceClass(enclosingActivity, manager);

            if (dataSourceClass == null)
            {
                item = new ValidationError(SR.GetString("Error_TypeNotResolvedInFieldName", new object[] { "Name" }), 0x11f)
                {
                    PropertyName = base.GetFullPropertyName(manager)
                };
            }
            else
            {
                FieldInfo field = dataSourceClass.GetField(name, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (field == null)
                {
                    item = new ValidationError(SR.GetString("Error_FieldNotExists", new object[] { base.GetFullPropertyName(manager), name }), 0x120)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else if (field.FieldType == null)
                {
                    item = new ValidationError(SR.GetString("Error_FieldTypeNotResolved", new object[] { base.GetFullPropertyName(manager), name }), 290)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                }
                else
                {
                    MemberInfo memberInfo = field;
                    if (((bind.Path == null) || (bind.Path.Length == 0)) && ((validationContext.TargetType != null) && !ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, field.FieldType, validationContext.Access)))
                    {
                        item = new ValidationError(SR.GetString("Error_FieldTypeMismatch", new object[] { base.GetFullPropertyName(manager), field.FieldType.FullName, validationContext.TargetType.FullName }), 0x13f)
                        {
                            PropertyName = base.GetFullPropertyName(manager)
                        };
                    }
                    else if (!string.IsNullOrEmpty(bind.Path))
                    {
                        memberInfo = MemberBind.GetMemberInfo(field.FieldType, bind.Path);
                        if (memberInfo == null)
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { name, bind.Path }), 300)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else
                        {
                            using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                            {
                                if (WorkflowCompilationContext.Current.CheckTypes)
                                {
                                    item = MemberBind.ValidateTypesInPath(field.FieldType, bind.Path);
                                    if (item != null)
                                    {
                                        item.PropertyName = base.GetFullPropertyName(manager) + ".Path";
                                    }
                                }
                            }
                            if (item == null)
                            {
                                Type memberType = (memberInfo is FieldInfo) ? (memberInfo as FieldInfo).FieldType : (memberInfo as PropertyInfo).PropertyType;
                                if (!ActivityBindValidator.DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeDataSourcePathMismatch", new object[] { validationContext.TargetType.FullName }), 0x141)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                    }
                    if (item == null)
                    {
                        if (memberInfo is PropertyInfo)
                        {
                            PropertyInfo info3 = memberInfo as PropertyInfo;
                            if (!info3.CanRead && ((validationContext.Access & AccessTypes.Read) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_PropertyNoGetter", new object[] { info3.Name, bind.Path }), 0x142)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                            else if (!info3.CanWrite && ((validationContext.Access & AccessTypes.Write) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_PropertyNoSetter", new object[] { info3.Name, bind.Path }), 0x143)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                        else if (memberInfo is FieldInfo)
                        {
                            FieldInfo info4 = memberInfo as FieldInfo;
                            if (((info4.Attributes & (FieldAttributes.Literal | FieldAttributes.InitOnly)) != FieldAttributes.PrivateScope) && ((validationContext.Access & AccessTypes.Write) != 0))
                            {
                                item = new ValidationError(SR.GetString("Error_ReadOnlyField", new object[] { info4.Name }), 0x145)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }
예제 #22
0
        private ValidationErrorCollection ValidateDependencyProperty(DependencyObject dependencyObject, DependencyProperty dependencyProperty, ValidationManager manager)
        {
            ValidationErrorCollection errors = new ValidationErrorCollection();

            Attribute[]      validationVisibilityAtrributes = dependencyProperty.DefaultMetadata.GetAttributes(typeof(ValidationOptionAttribute));
            ValidationOption validationVisibility           = (validationVisibilityAtrributes.Length > 0) ? ((ValidationOptionAttribute)validationVisibilityAtrributes[0]).ValidationOption : ValidationOption.Optional;

            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(Activity).FullName));
            }

            PropertyValidationContext propertyValidationContext = new PropertyValidationContext(activity, dependencyProperty);

            manager.Context.Push(propertyValidationContext);

            try
            {
                if (dependencyProperty.DefaultMetadata.DefaultValue != null)
                {
                    if (!dependencyProperty.PropertyType.IsValueType &&
                        dependencyProperty.PropertyType != typeof(string))
                    {
                        errors.Add(new ValidationError(SR.GetString(SR.Error_PropertyDefaultIsReference, dependencyProperty.Name), ErrorNumbers.Error_PropertyDefaultIsReference));
                    }
                    else if (!dependencyProperty.PropertyType.IsAssignableFrom(dependencyProperty.DefaultMetadata.DefaultValue.GetType()))
                    {
                        errors.Add(new ValidationError(SR.GetString(SR.Error_PropertyDefaultTypeMismatch, dependencyProperty.Name, dependencyProperty.PropertyType.FullName, dependencyProperty.DefaultMetadata.DefaultValue.GetType().FullName), ErrorNumbers.Error_PropertyDefaultTypeMismatch));
                    }
                }

                // If an event is of type Bind, GetBinding will return the Bind object.
                object propValue = null;
                if (dependencyObject.IsBindingSet(dependencyProperty))
                {
                    propValue = dependencyObject.GetBinding(dependencyProperty);
                }
                else if (!dependencyProperty.IsEvent)
                {
                    propValue = dependencyObject.GetValue(dependencyProperty);
                }

                if (propValue == null || propValue == dependencyProperty.DefaultMetadata.DefaultValue)
                {
                    if (dependencyProperty.IsEvent)
                    {
                        // Is this added through "+=" in InitializeComponent?  If so, the value should be in the instance properties hashtable
                        // If none of these, its value is stored in UserData at design time.
                        propValue = dependencyObject.GetHandler(dependencyProperty);
                        if (propValue == null)
                        {
                            propValue = WorkflowMarkupSerializationHelpers.GetEventHandlerName(dependencyObject, dependencyProperty.Name);
                        }

                        if (propValue is string && !string.IsNullOrEmpty((string)propValue))
                        {
                            errors.AddRange(ValidateEvent(activity, dependencyProperty, propValue, manager));
                        }
                    }
                    else
                    {
                        // Maybe this is an instance property.
                        propValue = dependencyObject.GetValue(dependencyProperty);
                    }
                }

                // Be careful before changing this. This is the (P || C) validation validation
                // i.e. validate properties being set only if Parent is set or
                // a child exists.
                bool checkNotSet = (activity.Parent != null) || ((activity is CompositeActivity) && (((CompositeActivity)activity).EnabledActivities.Count != 0));

                if (validationVisibility == ValidationOption.Required &&
                    (propValue == null || (propValue is string && string.IsNullOrEmpty((string)propValue))) &&
                    (dependencyProperty.DefaultMetadata.IsMetaProperty) &&
                    checkNotSet)
                {
                    errors.Add(ValidationError.GetNotSetValidationError(GetFullPropertyName(manager)));
                }
                else if (propValue != null)
                {
                    if (propValue is IList)
                    {
                        PropertyValidationContext childContext = new PropertyValidationContext(propValue, null, String.Empty);
                        manager.Context.Push(childContext);

                        try
                        {
                            foreach (object child in (IList)propValue)
                            {
                                errors.AddRange(ValidationHelpers.ValidateObject(manager, child));
                            }
                        }
                        finally
                        {
                            System.Diagnostics.Debug.Assert(manager.Context.Current == childContext, "Unwinding contextStack: the item that is about to be popped is not the one we pushed.");
                            manager.Context.Pop();
                        }
                    }
                    else if (dependencyProperty.ValidatorType != null)
                    {
                        Validator validator = null;
                        try
                        {
                            validator = Activator.CreateInstance(dependencyProperty.ValidatorType) as Validator;
                            if (validator == null)
                            {
                                errors.Add(new ValidationError(SR.GetString(SR.Error_CreateValidator, dependencyProperty.ValidatorType.FullName), ErrorNumbers.Error_CreateValidator));
                            }
                            else
                            {
                                errors.AddRange(validator.Validate(manager, propValue));
                            }
                        }
                        catch
                        {
                            errors.Add(new ValidationError(SR.GetString(SR.Error_CreateValidator, dependencyProperty.ValidatorType.FullName), ErrorNumbers.Error_CreateValidator));
                        }
                    }
                    else
                    {
                        errors.AddRange(ValidationHelpers.ValidateObject(manager, propValue));
                    }
                }
            }
            finally
            {
                System.Diagnostics.Debug.Assert(manager.Context.Current == propertyValidationContext, "Unwinding contextStack: the item that is about to be popped is not the one we pushed.");
                manager.Context.Pop();
            }

            return(errors);
        }
예제 #23
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors = base.Validate(manager, obj);
            ActivityBind bind = obj as ActivityBind;

            if (bind == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityBind).FullName }), "obj");
            }
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
            }
            PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;

            if (validationContext == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(BindValidationContext).Name }));
            }
            ValidationError item = null;

            if (string.IsNullOrEmpty(bind.Name))
            {
                item = new ValidationError(SR.GetString("Error_IDNotSetForActivitySource"), 0x613)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Name"
                };
                errors.Add(item);
                return(errors);
            }
            Activity refActivity = Helpers.ParseActivityForBind(activity, bind.Name);

            if (refActivity == null)
            {
                if (bind.Name.StartsWith("/"))
                {
                    item = new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128);
                }
                else
                {
                    item = new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129);
                }
                item.PropertyName = base.GetFullPropertyName(manager) + ".Name";
                errors.Add(item);
            }
            if (string.IsNullOrEmpty(bind.Path))
            {
                item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
                errors.Add(item);
            }
            if ((refActivity != null) && (errors.Count == 0))
            {
                string path       = bind.Path;
                string str2       = string.Empty;
                int    startIndex = path.IndexOfAny(new char[] { '.', '/', '[' });
                if (startIndex != -1)
                {
                    str2 = path.Substring(startIndex);
                    str2 = str2.StartsWith(".") ? str2.Substring(1) : str2;
                    path = path.Substring(0, startIndex);
                }
                Type       baseType   = BindHelpers.GetBaseType(manager, validationContext);
                MemberInfo memberInfo = null;
                Type       srcType    = null;
                if (!string.IsNullOrEmpty(path))
                {
                    srcType = BindValidatorHelper.GetActivityType(manager, refActivity);
                    if (srcType != null)
                    {
                        memberInfo = MemberBind.GetMemberInfo(srcType, path);
                        if ((memberInfo == null) && str2.StartsWith("[", StringComparison.Ordinal))
                        {
                            string str3  = bind.Path.Substring(startIndex);
                            int    index = str3.IndexOf(']');
                            if (index != -1)
                            {
                                string str4 = str3.Substring(0, index + 1);
                                str2 = ((index + 1) < str3.Length) ? str3.Substring(index + 1) : string.Empty;
                                str2 = str2.StartsWith(".") ? str2.Substring(1) : str2;
                                str3 = str4;
                            }
                            path       = path + str3;
                            memberInfo = MemberBind.GetMemberInfo(srcType, path);
                        }
                    }
                }
                Validator validator = null;
                object    obj2      = null;
                if (memberInfo != null)
                {
                    string str5 = !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : bind.Name;
                    if (memberInfo is FieldInfo)
                    {
                        obj2      = new FieldBind(str5 + "." + path, str2);
                        validator = new FieldBindValidator();
                    }
                    else if (memberInfo is MethodInfo)
                    {
                        if (typeof(Delegate).IsAssignableFrom(baseType))
                        {
                            obj2      = new MethodBind(str5 + "." + path);
                            validator = new MethodBindValidator();
                        }
                        else
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberType", new object[] { path, base.GetFullPropertyName(manager) }), 0x629)
                            {
                                PropertyName = base.GetFullPropertyName(manager)
                            };
                            errors.Add(item);
                        }
                    }
                    else if (memberInfo is PropertyInfo)
                    {
                        if (refActivity == activity)
                        {
                            obj2      = new PropertyBind(str5 + "." + path, str2);
                            validator = new PropertyBindValidator();
                        }
                        else
                        {
                            obj2      = bind;
                            validator = this;
                        }
                    }
                    else if (memberInfo is EventInfo)
                    {
                        obj2      = bind;
                        validator = this;
                    }
                }
                else if (((memberInfo == null) && (baseType != null)) && typeof(Delegate).IsAssignableFrom(baseType))
                {
                    obj2      = bind;
                    validator = this;
                }
                if ((validator != null) && (obj2 != null))
                {
                    if ((validator == this) && (obj2 is ActivityBind))
                    {
                        errors.AddRange(this.ValidateActivityBind(manager, obj2));
                        return(errors);
                    }
                    errors.AddRange(validator.Validate(manager, obj2));
                    return(errors);
                }
                if (item == null)
                {
                    item = new ValidationError(SR.GetString("Error_PathCouldNotBeResolvedToMember", new object[] { bind.Path, !string.IsNullOrEmpty(refActivity.QualifiedName) ? refActivity.QualifiedName : refActivity.GetType().Name }), 0x60d)
                    {
                        PropertyName = base.GetFullPropertyName(manager)
                    };
                    errors.Add(item);
                }
            }
            return(errors);
        }
예제 #24
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            Activity activity = obj as Activity;

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

            if (manager.Context == null)
            {
                throw new ArgumentException("manager", SR.GetString(SR.Error_MissingContextProperty));
            }

            manager.Context.Push(activity);

            ValidationErrorCollection errors = new ValidationErrorCollection();

            errors.AddRange(base.Validate(manager, obj));

            if (activity.Parent == null)
            {
                errors.AddRange(ValidationHelpers.ValidateUniqueIdentifiers(activity));

                if (activity.Enabled == false)
                {
                    ValidationError error = new ValidationError(SR.GetString(SR.Error_RootIsNotEnabled), ErrorNumbers.Error_RootIsNotEnabled);
                    error.PropertyName = "Enabled";
                    errors.Add(error);
                }
            }

            // validate ID property, only if it is not root activity
            Activity rootActivity = Helpers.GetRootActivity(activity);

            if (activity != rootActivity)
            {
                ValidationError identifierError = ValidationHelpers.ValidateNameProperty("Name", manager, activity.Name);
                if (identifierError != null)
                {
                    errors.Add(identifierError);
                }
            }

            try
            {
                errors.AddRange(ValidateProperties(manager, obj));
            }
            finally
            {
                System.Diagnostics.Debug.Assert(manager.Context.Current == activity, "Unwinding contextStack: the item that is about to be popped is not the one we pushed.");
                manager.Context.Pop();
            }

            return(errors);
        }
예제 #25
0
        private ValidationErrorCollection ValidateActivity(ValidationManager manager, ActivityBind bind, BindValidationContext validationContext)
        {
            ValidationError           item   = null;
            ValidationErrorCollection errors = new ValidationErrorCollection();
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(SR.GetString("Error_ContextStackItemMissing", new object[] { typeof(Activity).Name }));
            }
            Activity request = Helpers.ParseActivityForBind(activity, bind.Name);

            if (request == null)
            {
                item = bind.Name.StartsWith("/", StringComparison.Ordinal) ? new ValidationError(SR.GetString("Error_CannotResolveRelativeActivity", new object[] { bind.Name }), 0x128) : new ValidationError(SR.GetString("Error_CannotResolveActivity", new object[] { bind.Name }), 0x129);
                item.PropertyName = base.GetFullPropertyName(manager) + ".Name";
            }
            else if ((bind.Path == null) || (bind.Path.Length == 0))
            {
                item = new ValidationError(SR.GetString("Error_PathNotSetForActivitySource"), 0x12b)
                {
                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                };
            }
            else
            {
                if (!bind.Name.StartsWith("/", StringComparison.Ordinal) && !ValidationHelpers.IsActivitySourceInOrder(request, activity))
                {
                    item = new ValidationError(SR.GetString("Error_BindActivityReference", new object[] { request.QualifiedName, activity.QualifiedName }), 0x12a, true)
                    {
                        PropertyName = base.GetFullPropertyName(manager) + ".Name"
                    };
                }
                IDesignerHost          service = manager.GetService(typeof(IDesignerHost)) as IDesignerHost;
                WorkflowDesignerLoader loader  = manager.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                if ((service != null) && (loader != null))
                {
                    Type srcType = null;
                    if (service.RootComponent == request)
                    {
                        ITypeProvider provider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider;
                        if (provider == null)
                        {
                            throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
                        }
                        srcType = provider.GetType(service.RootComponentClassName);
                    }
                    else
                    {
                        request.GetType();
                    }
                    if (srcType != null)
                    {
                        MemberInfo memberInfo = MemberBind.GetMemberInfo(srcType, bind.Path);
                        if ((memberInfo == null) || ((memberInfo is PropertyInfo) && !(memberInfo as PropertyInfo).CanRead))
                        {
                            item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                        else
                        {
                            Type memberType = null;
                            if (memberInfo is FieldInfo)
                            {
                                memberType = ((FieldInfo)memberInfo).FieldType;
                            }
                            else if (memberInfo is PropertyInfo)
                            {
                                memberType = ((PropertyInfo)memberInfo).PropertyType;
                            }
                            else if (memberInfo is EventInfo)
                            {
                                memberType = ((EventInfo)memberInfo).EventHandlerType;
                            }
                            if (!DoesTargetTypeMatch(validationContext.TargetType, memberType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(memberInfo.DeclaringType))
                                {
                                    item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                                else
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { memberInfo.Name, memberType.FullName, validationContext.TargetType.FullName }), 0x12d)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                    }
                }
                else
                {
                    MemberInfo info2 = MemberBind.GetMemberInfo(request.GetType(), bind.Path);
                    if ((info2 == null) || ((info2 is PropertyInfo) && !(info2 as PropertyInfo).CanRead))
                    {
                        item = new ValidationError(SR.GetString("Error_InvalidMemberPath", new object[] { request.QualifiedName, bind.Path }), 300)
                        {
                            PropertyName = base.GetFullPropertyName(manager) + ".Path"
                        };
                    }
                    else
                    {
                        DependencyProperty dependencyProperty = DependencyProperty.FromName(info2.Name, info2.DeclaringType);
                        object             obj2 = BindHelpers.ResolveActivityPath(request, bind.Path);
                        if (obj2 == null)
                        {
                            Type fromType = null;
                            if (info2 is FieldInfo)
                            {
                                fromType = ((FieldInfo)info2).FieldType;
                            }
                            else if (info2 is PropertyInfo)
                            {
                                fromType = ((PropertyInfo)info2).PropertyType;
                            }
                            else if (info2 is EventInfo)
                            {
                                fromType = ((EventInfo)info2).EventHandlerType;
                            }
                            if (!TypeProvider.IsAssignable(typeof(ActivityBind), fromType) && !DoesTargetTypeMatch(validationContext.TargetType, fromType, validationContext.Access))
                            {
                                if (typeof(WorkflowParameterBinding).IsAssignableFrom(info2.DeclaringType))
                                {
                                    item = new ValidationError(SR.GetString("Warning_ParameterBinding", new object[] { bind.Path, request.QualifiedName, validationContext.TargetType.FullName }), 0x624, true)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                                else
                                {
                                    item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, fromType.FullName, validationContext.TargetType.FullName }), 0x12d)
                                    {
                                        PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                    };
                                }
                            }
                        }
                        else if ((obj2 is ActivityBind) && (request.Parent != null))
                        {
                            ActivityBind         bind2   = obj2 as ActivityBind;
                            bool                 flag    = false;
                            BindRecursionContext context = manager.Context[typeof(BindRecursionContext)] as BindRecursionContext;
                            if (context == null)
                            {
                                context = new BindRecursionContext();
                                manager.Context.Push(context);
                                flag = true;
                            }
                            if (context.Contains(activity, bind))
                            {
                                item = new ValidationError(SR.GetString("Bind_ActivityDataSourceRecursionDetected"), 0x12f)
                                {
                                    PropertyName = base.GetFullPropertyName(manager) + ".Path"
                                };
                            }
                            else
                            {
                                context.Add(activity, bind);
                                PropertyValidationContext propertyValidationContext = null;
                                if (dependencyProperty != null)
                                {
                                    propertyValidationContext = new PropertyValidationContext(request, dependencyProperty);
                                }
                                else
                                {
                                    propertyValidationContext = new PropertyValidationContext(request, info2 as PropertyInfo, info2.Name);
                                }
                                errors.AddRange(ValidationHelpers.ValidateProperty(manager, request, bind2, propertyValidationContext, validationContext));
                            }
                            if (flag)
                            {
                                manager.Context.Pop();
                            }
                        }
                        else if ((validationContext.TargetType != null) && !DoesTargetTypeMatch(validationContext.TargetType, obj2.GetType(), validationContext.Access))
                        {
                            item = new ValidationError(SR.GetString("Error_TargetTypeMismatch", new object[] { info2.Name, obj2.GetType().FullName, validationContext.TargetType.FullName }), 0x12d)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".Path"
                            };
                        }
                    }
                }
            }
            if (item != null)
            {
                errors.Add(item);
            }
            return(errors);
        }