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); }
public WorkflowValidationFailedException(string message, ValidationErrorCollection errors) : base(message) { if (errors == null) { throw new ArgumentNullException("errors"); } this.errors = XomlCompilerHelper.MorphIntoFriendlyValidationErrors(errors); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); if (!(obj is ActivityCondition)) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ActivityCondition).FullName }), "obj"); } errors.AddRange(this.ValidateProperties(manager, obj)); return(errors); }
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); }
private WorkflowValidationFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException("info"); } this.errors = (ValidationErrorCollection)info.GetValue("errors", typeof(ValidationErrorCollection)); if (this.errors == null) { throw new SerializationException(SR.GetString("Error_SerializationInsufficientState")); } }
internal static ValidationErrorCollection ValidateObject(ValidationManager manager, object obj) { ValidationErrorCollection errors = new ValidationErrorCollection(); if (obj == null) { return(errors); } Type objType = obj.GetType(); if (!objType.IsPrimitive && (objType != typeof(string))) { bool removeValidatedObjectCollection = false; Dictionary <int, object> validatedObjects = manager.Context[typeof(Dictionary <int, object>)] as Dictionary <int, object>; if (validatedObjects == null) { validatedObjects = new Dictionary <int, object>(); manager.Context.Push(validatedObjects); removeValidatedObjectCollection = true; } try { if (!validatedObjects.ContainsKey(obj.GetHashCode())) { validatedObjects.Add(obj.GetHashCode(), obj); try { Validator[] validators = manager.GetValidators(objType); foreach (Validator validator in validators) { errors.AddRange(validator.Validate(manager, obj)); } } finally { validatedObjects.Remove(obj.GetHashCode()); } } } finally { if (removeValidatedObjectCollection) { manager.Context.Pop(); } } } return(errors); }
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); }
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); }
internal static ValidationErrorCollection ValidateActivity(ValidationManager manager, Activity activity) { ValidationErrorCollection errors = ValidationHelpers.ValidateObject(manager, activity); foreach (ValidationError error in errors) { if (!error.UserData.Contains(typeof(Activity))) { error.UserData[typeof(Activity)] = activity; } } return(errors); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = base.Validate(manager, obj); ActivityCondition conditionDeclaration = obj as ActivityCondition; if (conditionDeclaration == null) { throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(ActivityCondition).FullName), "obj"); } validationErrors.AddRange(ValidateProperties(manager, obj)); return(validationErrors); }
internal static ValidationErrorCollection ValidateObject(ValidationManager manager, object obj) { ValidationErrorCollection errors = new ValidationErrorCollection(); if (obj != null) { Type type = obj.GetType(); if (type.IsPrimitive || !(type != typeof(string))) { return(errors); } bool flag = false; Dictionary <int, object> context = manager.Context[typeof(Dictionary <int, object>)] as Dictionary <int, object>; if (context == null) { context = new Dictionary <int, object>(); manager.Context.Push(context); flag = true; } try { if (context.ContainsKey(obj.GetHashCode())) { return(errors); } context.Add(obj.GetHashCode(), obj); try { foreach (Validator validator in manager.GetValidators(type)) { errors.AddRange(validator.Validate(manager, obj)); } } finally { context.Remove(obj.GetHashCode()); } } finally { if (flag) { manager.Context.Pop(); } } } return(errors); }
public virtual ValidationErrorCollection ValidateProperties(ValidationManager manager, object obj) { if (manager == null) { throw new ArgumentNullException("manager"); } if (obj == null) { throw new ArgumentNullException("obj"); } ValidationErrorCollection errors = new ValidationErrorCollection(); Activity activity = manager.Context[typeof(Activity)] as Activity; // Validate all members that support validations. Walker walker = new Walker(true); walker.FoundProperty += delegate(Walker w, WalkerEventArgs args) { //If we find dynamic property of the same name then we do not invoke the validator associated with the property //Attached dependency properties will not be found by FromName(). // args.CurrentProperty can be null if the property is of type IList. The walker would go into each item in the // list, but we don't need to validate these items. if (args.CurrentProperty != null) { DependencyProperty dependencyProperty = DependencyProperty.FromName(args.CurrentProperty.Name, args.CurrentProperty.DeclaringType); if (dependencyProperty == null) { object[] validationVisibilityAtrributes = args.CurrentProperty.GetCustomAttributes(typeof(ValidationOptionAttribute), true); ValidationOption validationVisibility = (validationVisibilityAtrributes.Length > 0) ? ((ValidationOptionAttribute)validationVisibilityAtrributes[0]).ValidationOption : ValidationOption.Optional; if (validationVisibility != ValidationOption.None) { errors.AddRange(ValidateProperty(args.CurrentProperty, args.CurrentPropertyOwner, args.CurrentValue, manager)); // don't probe into subproperties as validate object inside the ValidateProperties call does it for us args.Action = WalkerAction.Skip; } } } }; walker.WalkProperties(activity, obj); return(errors); }
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) { 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); }
internal protected ValidationErrorCollection ValidateProperty(PropertyInfo propertyInfo, object propertyOwner, object propertyValue, ValidationManager manager) { ValidationErrorCollection errors = new ValidationErrorCollection(); object[] validationVisibilityAtrributes = propertyInfo.GetCustomAttributes(typeof(ValidationOptionAttribute), true); ValidationOption validationVisibility = (validationVisibilityAtrributes.Length > 0) ? ((ValidationOptionAttribute)validationVisibilityAtrributes[0]).ValidationOption : ValidationOption.Optional; PropertyValidationContext propertyValidationContext = new PropertyValidationContext(propertyOwner, propertyInfo, propertyInfo.Name); manager.Context.Push(propertyValidationContext); try { if (propertyValue != null) { errors.AddRange(ValidationHelpers.ValidateObject(manager, propertyValue)); if (propertyValue is IList) { PropertyValidationContext childContext = new PropertyValidationContext(propertyValue, null, ""); manager.Context.Push(childContext); try { foreach (object child in (IList)propertyValue) { 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(); } } } } 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); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { if (manager == null) { throw new ArgumentNullException("manager"); } if (obj == null) { throw new ArgumentNullException("obj"); } ValidationErrorCollection errors = base.Validate(manager, obj); DependencyObject dependencyObject = obj as DependencyObject; if (dependencyObject == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(DependencyObject).FullName }), "obj"); } ArrayList list = new ArrayList(); foreach (DependencyProperty property in DependencyProperty.FromType(dependencyObject.GetType())) { if (!property.IsAttached) { list.Add(property); } } foreach (DependencyProperty property2 in dependencyObject.MetaDependencyProperties) { if (property2.IsAttached && (obj.GetType().GetProperty(property2.Name, BindingFlags.Public | BindingFlags.Instance) == null)) { list.Add(property2); } } foreach (DependencyProperty property3 in list) { object[] attributes = property3.DefaultMetadata.GetAttributes(typeof(ValidationOptionAttribute)); if (((attributes.Length > 0) ? ((ValidationOptionAttribute)attributes[0]).ValidationOption : ValidationOption.Optional) != ValidationOption.None) { errors.AddRange(this.ValidateDependencyProperty(dependencyObject, property3, manager)); } } return(errors); }
protected internal ValidationErrorCollection ValidateProperty(PropertyInfo propertyInfo, object propertyOwner, object propertyValue, ValidationManager manager) { ValidationErrorCollection errors = new ValidationErrorCollection(); object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(ValidationOptionAttribute), true); if (customAttributes.Length > 0) { ValidationOption validationOption = ((ValidationOptionAttribute) customAttributes[0]).ValidationOption; } PropertyValidationContext context = new PropertyValidationContext(propertyOwner, propertyInfo, propertyInfo.Name); manager.Context.Push(context); try { if (propertyValue == null) { return errors; } errors.AddRange(ValidationHelpers.ValidateObject(manager, propertyValue)); if (!(propertyValue is IList)) { return errors; } PropertyValidationContext context2 = new PropertyValidationContext(propertyValue, null, ""); manager.Context.Push(context2); try { foreach (object obj2 in (IList) propertyValue) { errors.AddRange(ValidationHelpers.ValidateObject(manager, obj2)); } return errors; } finally { manager.Context.Pop(); } } finally { manager.Context.Pop(); } return errors; }
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); }
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); }
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); }
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); }
internal static ValidationErrorCollection ValidateProperty(ValidationManager manager, Activity activity, object obj, PropertyValidationContext propertyValidationContext, object extendedPropertyContext) { if (manager == null) { throw new ArgumentNullException("manager"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (propertyValidationContext == null) { throw new ArgumentNullException("propertyValidationContext"); } ValidationErrorCollection errors = new ValidationErrorCollection(); manager.Context.Push(activity); manager.Context.Push(propertyValidationContext); if (extendedPropertyContext != null) { manager.Context.Push(extendedPropertyContext); } try { errors.AddRange(ValidationHelpers.ValidateObject(manager, obj)); } finally { manager.Context.Pop(); manager.Context.Pop(); if (extendedPropertyContext != null) { manager.Context.Pop(); } } 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); }
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); }
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); }
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); }
internal static CodeCompileUnit GenerateCodeFromFileBatch(string[] files, WorkflowCompilerParameters parameters, WorkflowCompilerResults results) { WorkflowCompilationContext current = WorkflowCompilationContext.Current; if (current == null) { throw new Exception(SR.GetString("Error_MissingCompilationContext")); } CodeCompileUnit unit = new CodeCompileUnit(); foreach (string str in files) { Activity rootActivity = null; try { DesignerSerializationManager manager = new DesignerSerializationManager(current.ServiceProvider); using (manager.CreateSession()) { WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager); xomlSerializationManager.WorkflowMarkupStack.Push(parameters); xomlSerializationManager.LocalAssembly = parameters.LocalAssembly; using (XmlReader reader = XmlReader.Create(str)) { rootActivity = WorkflowMarkupSerializationHelpers.LoadXomlDocument(xomlSerializationManager, reader, str); } if (parameters.LocalAssembly != null) { foreach (object obj2 in manager.Errors) { if (obj2 is WorkflowMarkupSerializationException) { results.Errors.Add(new WorkflowCompilerError(str, (WorkflowMarkupSerializationException)obj2)); } else { int num2 = 0x15b; results.Errors.Add(new WorkflowCompilerError(str, -1, -1, num2.ToString(CultureInfo.InvariantCulture), obj2.ToString())); } } } } } catch (WorkflowMarkupSerializationException exception) { results.Errors.Add(new WorkflowCompilerError(str, exception)); continue; } catch (Exception exception2) { int num3 = 0x15b; results.Errors.Add(new WorkflowCompilerError(str, -1, -1, num3.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_CompilationFailed", new object[] { exception2.Message }))); continue; } if (rootActivity == null) { int num4 = 0x15b; results.Errors.Add(new WorkflowCompilerError(str, 1, 1, num4.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_RootActivityTypeInvalid"))); } else if (string.IsNullOrEmpty(rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string)) { int num5 = 0x15b; results.Errors.Add(new WorkflowCompilerError(str, 1, 1, num5.ToString(CultureInfo.InvariantCulture), SR.GetString("Error_CannotCompile_No_XClass"))); } else { if (parameters.CompileWithNoCode && XomlCompilerHelper.HasCodeWithin(rootActivity)) { ValidationError error = new ValidationError(SR.GetString("Error_CodeWithinNotAllowed"), 0x16a); error.UserData[typeof(Activity)] = rootActivity; results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error, parameters)); } ValidationErrorCollection errors = new ValidationErrorCollection(); foreach (ValidationError error2 in ValidateIdentifiers(current.ServiceProvider, rootActivity)) { results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error2, parameters)); } if (!results.Errors.HasErrors) { unit.Namespaces.AddRange(WorkflowMarkupSerializationHelpers.GenerateCodeFromXomlDocument(rootActivity, str, current.RootNamespace, CompilerHelpers.GetSupportedLanguage(current.Language), current.ServiceProvider)); } } } WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(unit.Namespaces, current.RootNamespace, CompilerHelpers.GetSupportedLanguage(current.Language)); return(unit); }
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); }
internal static CodeCompileUnit GenerateCodeFromFileBatch(string[] files, WorkflowCompilerParameters parameters, WorkflowCompilerResults results) { WorkflowCompilationContext context = WorkflowCompilationContext.Current; if (context == null) { throw new Exception(SR.GetString(SR.Error_MissingCompilationContext)); } CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); foreach (string fileName in files) { Activity rootActivity = null; try { DesignerSerializationManager manager = new DesignerSerializationManager(context.ServiceProvider); using (manager.CreateSession()) { WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager); xomlSerializationManager.WorkflowMarkupStack.Push(parameters); xomlSerializationManager.LocalAssembly = parameters.LocalAssembly; using (XmlReader reader = XmlReader.Create(fileName)) rootActivity = WorkflowMarkupSerializationHelpers.LoadXomlDocument(xomlSerializationManager, reader, fileName); if (parameters.LocalAssembly != null) { foreach (object error in manager.Errors) { if (error is WorkflowMarkupSerializationException) { results.Errors.Add(new WorkflowCompilerError(fileName, (WorkflowMarkupSerializationException)error)); } else { results.Errors.Add(new WorkflowCompilerError(fileName, -1, -1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), error.ToString())); } } } } } catch (WorkflowMarkupSerializationException xomlSerializationException) { results.Errors.Add(new WorkflowCompilerError(fileName, xomlSerializationException)); continue; } catch (Exception e) { results.Errors.Add(new WorkflowCompilerError(fileName, -1, -1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_CompilationFailed, e.Message))); continue; } if (rootActivity == null) { results.Errors.Add(new WorkflowCompilerError(fileName, 1, 1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_RootActivityTypeInvalid))); continue; } bool createNewClass = (!string.IsNullOrEmpty(rootActivity.GetValue(WorkflowMarkupSerializer.XClassProperty) as string)); if (!createNewClass) { results.Errors.Add(new WorkflowCompilerError(fileName, 1, 1, ErrorNumbers.Error_SerializationError.ToString(CultureInfo.InvariantCulture), SR.GetString(SR.Error_CannotCompile_No_XClass))); continue; } //NOTE: CompileWithNoCode is meaningless now. It means no x:Code in a XOML file. It exists until the FP migration is done //Ideally FP should just use XOML files w/o X:Class and run them w/o ever compiling them if ((parameters.CompileWithNoCode) && XomlCompilerHelper.HasCodeWithin(rootActivity)) { ValidationError error = new ValidationError(SR.GetString(SR.Error_CodeWithinNotAllowed), ErrorNumbers.Error_CodeWithinNotAllowed); error.UserData[typeof(Activity)] = rootActivity; results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error, parameters)); } ValidationErrorCollection errors = new ValidationErrorCollection(); errors = ValidateIdentifiers(context.ServiceProvider, rootActivity); foreach (ValidationError error in errors) { results.Errors.Add(XomlCompilerHelper.CreateXomlCompilerError(error, parameters)); } if (results.Errors.HasErrors) { continue; } codeCompileUnit.Namespaces.AddRange(WorkflowMarkupSerializationHelpers.GenerateCodeFromXomlDocument(rootActivity, fileName, context.RootNamespace, CompilerHelpers.GetSupportedLanguage(context.Language), context.ServiceProvider)); } WorkflowMarkupSerializationHelpers.FixStandardNamespacesAndRootNamespace(codeCompileUnit.Namespaces, context.RootNamespace, CompilerHelpers.GetSupportedLanguage(context.Language)); return(codeCompileUnit); }