private static void ValidateCustomStateActivity(StateActivity state, ValidationErrorCollection validationErrors) { if (state.Activities.Count > 0) { validationErrors.Add(new ValidationError(SR.GetError_BlackBoxCustomStateNotSupported(), ErrorNumbers.Error_BlackBoxCustomStateNotSupported)); } }
public void MinLengthViolationTest() { MinimumLengthAttribute attribute = new MinimumLengthAttribute(8); ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(minLengthNode, valueInfo1, errors); Assert.AreEqual(1, errors.Count); }
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; Walker walker = new Walker(true); walker.FoundProperty += delegate (Walker w, WalkerEventArgs args) { if ((args.CurrentProperty != null) && (DependencyProperty.FromName(args.CurrentProperty.Name, args.CurrentProperty.DeclaringType) == null)) { object[] customAttributes = args.CurrentProperty.GetCustomAttributes(typeof(ValidationOptionAttribute), true); if (((customAttributes.Length > 0) ? ((ValidationOptionAttribute) customAttributes[0]).ValidationOption : ValidationOption.Optional) != ValidationOption.None) { errors.AddRange(this.ValidateProperty(args.CurrentProperty, args.CurrentPropertyOwner, args.CurrentValue, manager)); args.Action = WalkerAction.Skip; } } }; walker.WalkProperties(activity, obj); return errors; }
private static void FillCorrelationAliasAttrs(MemberInfo memberInfo, Hashtable correlationAliasAttrs, ValidationErrorCollection validationErrors) { foreach (object obj2 in memberInfo.GetCustomAttributes(typeof(CorrelationAliasAttribute), false)) { CorrelationAliasAttribute attributeFromObject = Helpers.GetAttributeFromObject<CorrelationAliasAttribute>(obj2); if (string.IsNullOrEmpty(attributeFromObject.Name) || (attributeFromObject.Name.Trim().Length == 0)) { ValidationError item = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationAttributeInvalid", new object[] { typeof(CorrelationAliasAttribute).Name, "Name", memberInfo.Name }), 0x150); item.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name); validationErrors.Add(item); } else if (string.IsNullOrEmpty(attributeFromObject.Path) || (attributeFromObject.Path.Trim().Length == 0)) { ValidationError error2 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_CorrelationAttributeInvalid", new object[] { typeof(CorrelationAliasAttribute).Name, "Path", memberInfo.Name }), 0x150); error2.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name); validationErrors.Add(error2); } else if (correlationAliasAttrs.Contains(attributeFromObject.Name)) { ValidationError error3 = new ValidationError(SR.GetString(CultureInfo.CurrentCulture, "Error_DuplicateCorrelationAttribute", new object[] { typeof(CorrelationAliasAttribute).Name, attributeFromObject.Name, memberInfo.Name }), 0x151); error3.UserData.Add(typeof(CorrelationAliasAttribute), memberInfo.Name); validationErrors.Add(error3); } else { correlationAliasAttrs.Add(attributeFromObject.Name, attributeFromObject); } } }
public RuleValidation(Activity activity, ITypeProvider typeProvider, bool checkStaticType) { this.errors = new ValidationErrorCollection(); this.typesUsed = new Dictionary<string, Type>(0x10); this.activeParentNodes = new Stack<CodeExpression>(); this.expressionInfoMap = new Dictionary<CodeExpression, RuleExpressionInfo>(); this.typeRefMap = new Dictionary<CodeTypeReference, Type>(); if (activity == null) { throw new ArgumentNullException("activity"); } if (typeProvider == null) { throw new ArgumentNullException("typeProvider"); } this.thisType = ConditionHelper.GetContextType(typeProvider, activity); this.typeProvider = typeProvider; this.checkStaticType = checkStaticType; if (checkStaticType) { this.authorizedTypes = WorkflowCompilationContext.Current.GetAuthorizedTypes(); this.typesUsedAuthorized = new Dictionary<string, Type>(); this.typesUsedAuthorized.Add(voidTypeName, voidType); } }
/// <summary> /// Inherited from <see cref="IValidationManager"/>. /// <para> /// This manager assumes all objects within <paramref name="validationResult"/> are of type <see cref="ValidationResult"/>. /// </para> /// <para> /// This manager assumes all <see cref="ValidationResult"/> objects within <paramref name="validationResult"/> that /// have an empty <see cref="P:ValidationResult.MemberNames"/> collection are top level or class level issues. /// </para> /// </summary> /// <param name="errorCollection">A <see cref="ValidationErrorCollection"/> that houses the validation results.</param> /// <param name="validationResult">A <see cref="IEnumerable{T}"/> that represents the collection of validation issues that need to be applied to <paramref name="errorCollection"/>.</param> public virtual void SetErrors(ValidationErrorCollection errorCollection, IEnumerable<object> validationResult) { lock (_syncObject) { IEnumerable<ValidationResult> vResults = validationResult.Cast<ValidationResult>(); var results = (from g in (from tuple in (from r in vResults from name in r.MemberNames select new Tuple<string, ValidationResult>(name, r)) group tuple by tuple.Item1) select new Tuple<string, IEnumerable<ValidationResult>>(g.Key, g.Select(a => a.Item2))).ToArray(); if (vResults.Any(a => a.MemberNames.Count() == 0)) { Tuple<string, IEnumerable<ValidationResult>> newTuple = new Tuple<string, IEnumerable<ValidationResult>>(string.Empty, from vr in vResults where vr.MemberNames.Count() == 0 select vr); results = results.Concat(new Tuple<string, IEnumerable<ValidationResult>>[] { newTuple }).ToArray(); } errorCollection.Clear(); foreach (Tuple<string, IEnumerable<ValidationResult>> item in results) errorCollection.SetErrors(item.Item1, item.Item2.Cast<object>()); } }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = new ValidationErrorCollection(base.Validate(manager, obj)); ListenActivity activity = obj as ListenActivity; if (activity == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ListenActivity).FullName }), "obj"); } if (activity.EnabledActivities.Count < 2) { errors.Add(new ValidationError(SR.GetString("Error_ListenLessThanTwoChildren"), 0x513)); } bool flag = false; foreach (Activity activity2 in activity.EnabledActivities) { if (!(activity2 is EventDrivenActivity)) { flag = true; } } if (flag) { errors.Add(new ValidationError(SR.GetString("Error_ListenNotAllEventDriven"), 0x514)); } return errors; }
internal void SetValidationErrors(ValidationErrorCollection errors) { foreach(ValidationError error in errors) { validationErrorsBox.Items.Add(error); } }
public void RequiredNotThereTest() { RequiredAttribute attribute = new RequiredAttribute(); ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(requiredNode, valueInfo1, errors); Assert.AreEqual(1, errors.Count); }
public void InvalidTypeProducesAnError() { TypeValidationAttribute attribute = new TypeValidationAttribute(); typeNode.TypeName = "MyTest"; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(typeNode, valueInfo1, errors); Assert.AreEqual(1, errors.Count); }
public void MaxLengthViolationTest() { MaximumLengthAttribute attribute = new MaximumLengthAttribute(3); maxLengthNode.Value1 = "aaaa"; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(maxLengthNode, valueInfo1, errors); Assert.AreEqual(1, errors.Count); }
public void ValidTypeProducesNoErrors() { TypeValidationAttribute attribute = new TypeValidationAttribute(); ValidationErrorCollection errors = new ValidationErrorCollection(); typeNode.TypeName = GetType().AssemblyQualifiedName; attribute.Validate(typeNode, valueInfo1, errors); Assert.AreEqual(0, errors.Count); }
public void CharOutOfRangeTest() { AssertRangeAttribute assertRange = new AssertRangeAttribute('a', RangeBoundaryType.Inclusive, 'd', RangeBoundaryType.Exclusive); rangeClass.CharValue = 'd'; ValidationErrorCollection errors = new ValidationErrorCollection(); assertRange.Validate(rangeClass, charInfo, errors); Assert.AreEqual(1, errors.Count); }
protected RuleSetValidationException(SerializationInfo serializeInfo, StreamingContext context) : base(serializeInfo, context) { if (serializeInfo == null) { throw new ArgumentNullException("serializeInfo"); } this.m_errors = (ValidationErrorCollection) serializeInfo.GetValue("errors", typeof(ValidationErrorCollection)); }
public void DoubleOutOfRangeTest() { AssertRangeAttribute assertRange = new AssertRangeAttribute(3D, RangeBoundaryType.Inclusive, 43D, RangeBoundaryType.Exclusive); rangeClass.DoubleValue = 2; ValidationErrorCollection errors = new ValidationErrorCollection(); assertRange.Validate(rangeClass, doubleInfo, errors); Assert.AreEqual(1, errors.Count); }
public void RegexViolationTest() { RegexAttribute attribute = new RegexAttribute(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); regexNode.Email = "joeblow"; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(regexNode, emailInfo, errors); Assert.AreEqual(1, errors.Count); }
public void MinLengthTest() { MinimumLengthAttribute attribute = new MinimumLengthAttribute(8); minLengthNode.Value2 = "MyTestPassword"; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(minLengthNode, valueInfo2, errors); Assert.AreEqual(0, errors.Count); }
public void FloatInRangeTest() { AssertRangeAttribute assertRange = new AssertRangeAttribute(3f, RangeBoundaryType.Inclusive, 43f, RangeBoundaryType.Exclusive); rangeClass.FloatValue = 25; ValidationErrorCollection errors = new ValidationErrorCollection(); assertRange.Validate(rangeClass, floatInfo, errors); Assert.AreEqual(0, errors.Count); }
public WorkflowValidationFailedException(string message, ValidationErrorCollection errors) : base(message) { if (errors == null) { throw new ArgumentNullException("errors"); } this.errors = XomlCompilerHelper.MorphIntoFriendlyValidationErrors(errors); }
public void RequiredValueTest() { RequiredAttribute attribute = new RequiredAttribute(); requiredNode.Value2 = "MyTest"; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(requiredNode, valueInfo2, errors); Assert.AreEqual(0, ValidationErrorsCount); }
// This function will create a new root activity definition tree by deserializing the xoml and the rules file. protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader) { if (workflowDefinitionReader == null) { throw new ArgumentNullException("workflowDefinitionReader"); } Activity root = null; ValidationErrorCollection errors = new ValidationErrorCollection(); ServiceContainer serviceContainer = new ServiceContainer(); ITypeProvider typeProvider = this.Runtime.GetService <ITypeProvider>(); if (typeProvider != null) { serviceContainer.AddService(typeof(ITypeProvider), typeProvider); } DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer); try { using (manager.CreateSession()) { WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager); root = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, workflowDefinitionReader) as Activity; if (root != null && rulesReader != null) { object rules = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, rulesReader); root.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, rules); } foreach (object error in manager.Errors) { if (error is WorkflowMarkupSerializationException) { errors.Add(new ValidationError(((WorkflowMarkupSerializationException)error).Message, ErrorNumbers.Error_SerializationError)); } else { errors.Add(new ValidationError(error.ToString(), ErrorNumbers.Error_SerializationError)); } } } } catch (Exception e) { errors.Add(new ValidationError(e.Message, ErrorNumbers.Error_SerializationError)); } if (errors.HasErrors) { throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); } return(root); }
public void RegexTest() { RegexAttribute attribute = new RegexAttribute(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); regexNode.Email = "*****@*****.**"; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(regexNode, emailInfo, errors); Assert.AreEqual(0, errors.Count); }
public void FloatOutOfRangeTest() { AssertRangeAttribute assertRange = new AssertRangeAttribute(3f, RangeBoundaryType.Inclusive, 43f, RangeBoundaryType.Exclusive); rangeClass.FloatValue = 2; ValidationErrorCollection errors = new ValidationErrorCollection(); assertRange.Validate(rangeClass, floatInfo, errors); Assert.AreEqual(1, errors.Count); }
public ApiException(string message, int statusCode = 500, ValidationErrorCollection errors = null, string detail = null) : base(message) { StatusCode = statusCode; Errors = errors; Detail = detail; }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); if (!(obj is ConditionedActivityGroup)) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(ConditionedActivityGroup).FullName }), "obj"); } return(errors); }
/// <summary> /// Adds an existing set of Validation Errors to the DisplayErrors /// </summary> /// <param name="validationErrors"></param> public void AddMessages(ValidationErrorCollection validationErrors, string fieldPrefix = null) { fieldPrefix = fieldPrefix ?? string.Empty; foreach (ValidationError error in validationErrors) { DisplayErrors.Add(error.Message, fieldPrefix + error.ControlID); } visible = true; }
private static void ValidateParameterSerializabiltiy(ValidationErrorCollection validationErrors, Type type) { object[] customAttributes = type.GetCustomAttributes(typeof(SerializableAttribute), false); Type type2 = type.GetInterface(typeof(ISerializable).FullName); if ((customAttributes.Length == 0) && (type2 == null)) { validationErrors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_EventArgumentValidationException"), new object[] { type.FullName }), 0x120, false, "EventName")); } }
public void MaxLengthTest() { MaximumLengthAttribute attribute = new MaximumLengthAttribute(8); maxLengthNode.Value2 = "aaaa"; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(maxLengthNode, valueInfo2, errors); Assert.AreEqual(0, errors.Count); }
public void StringInRangeTest() { AssertRangeAttribute assertRange = new AssertRangeAttribute("Anna", RangeBoundaryType.Inclusive, "Grace", RangeBoundaryType.Exclusive); rangeClass.StringValue = "Dee"; ValidationErrorCollection errors = new ValidationErrorCollection(); assertRange.Validate(rangeClass, stringInfo, errors); Assert.AreEqual(0, errors.Count); }
public void DoubleInRangeTest() { AssertRangeAttribute assertRange = new AssertRangeAttribute(3D, RangeBoundaryType.Inclusive, 43D, RangeBoundaryType.Exclusive); rangeClass.DoubleValue = 25; ValidationErrorCollection errors = new ValidationErrorCollection(); assertRange.Validate(rangeClass, doubleInfo, errors); Assert.AreEqual(0, errors.Count); }
public void CharInRangeTest() { AssertRangeAttribute assertRange = new AssertRangeAttribute('a', RangeBoundaryType.Inclusive, 'd', RangeBoundaryType.Exclusive); rangeClass.CharValue = 'c'; ValidationErrorCollection errors = new ValidationErrorCollection(); assertRange.Validate(rangeClass, charInfo, errors); Assert.AreEqual(0, errors.Count); }
public void EmptyTypeNameProducesAnError() { TypeValidationAttribute attribute = new TypeValidationAttribute(); typeNode.TypeName = string.Empty; ValidationErrorCollection errors = new ValidationErrorCollection(); attribute.Validate(typeNode, valueInfo1, errors); Assert.AreEqual(1, errors.Count); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = base.Validate(manager, obj); FaultHandlersActivity activity = obj as FaultHandlersActivity; if (activity == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(FaultHandlersActivity).FullName }), "obj"); } Hashtable hashtable = new Hashtable(); ArrayList list = new ArrayList(); bool flag = false; foreach (Activity activity2 in activity.EnabledActivities) { if (!(activity2 is FaultHandlerActivity)) { if (!flag) { errors.Add(new ValidationError(SR.GetString("Error_FaultHandlersActivityDeclNotAllFaultHandlerActivityDecl"), 0x51e)); flag = true; } } else { FaultHandlerActivity activity3 = (FaultHandlerActivity)activity2; Type faultType = activity3.FaultType; if (faultType != null) { if (hashtable[faultType] == null) { hashtable[faultType] = 1; list.Add(faultType); } else if (((int)hashtable[faultType]) == 1) { errors.Add(new ValidationError(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ScopeDuplicateFaultHandlerActivityFor"), new object[] { Helpers.GetEnclosingActivity(activity).GetType().Name, faultType.FullName }), 0x520)); hashtable[faultType] = 2; } foreach (Type type2 in list) { if ((type2 != faultType) && type2.IsAssignableFrom(faultType)) { errors.Add(new ValidationError(SR.GetString("Error_FaultHandlerActivityWrongOrder", new object[] { faultType.Name, type2.Name }), 0x521)); } } } } } if (activity.AlternateFlowActivities.Count > 0) { errors.Add(new ValidationError(SR.GetString("Error_ModelingConstructsCanNotContainModelingConstructs"), 0x61f)); } return(errors); }
/// <summary> /// add prefix to error name /// </summary> /// <param name="errors"></param> /// <param name="prefix"></param> /// <returns></returns> public static ValidationErrorCollection AddPrefix(this ValidationErrorCollection errors, String prefix) { var ret = new ValidationErrorCollection(); foreach (var item in errors) { ret.Add(prefix + item.Key, new ValidationError(prefix + item.Value.PropertyName, item.Value.ErrorMessage, item.Value.SourceObject)); } return ret; }
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(SR.Error_SerializationInsufficientState)); }
protected internal override ValidationErrorCollection ValidateChanges(Activity contextActivity) { ValidationErrorCollection errors = base.ValidateChanges(contextActivity); Activity removedActivityInContext = contextActivity.TraverseDottedPathFromRoot(this.originalRemovedActivity.DottedPath); if (WorkflowChanges.IsActivityExecutable(removedActivityInContext) && removedActivityInContext.ExecutionStatus == ActivityExecutionStatus.Executing) { errors.Add(new ValidationError(SR.GetString(SR.Error_RemoveExecutingActivity, this.originalRemovedActivity.QualifiedName), ErrorNumbers.Error_RemoveExecutingActivity)); } return(errors); }
// Token: 0x0600596C RID: 22892 RVA: 0x0018AEC8 File Offset: 0x001890C8 private static void OnErrorsInternalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ValidationErrorCollection validationErrorCollection = e.NewValue as ValidationErrorCollection; if (validationErrorCollection != null) { d.SetValue(Validation.ErrorsPropertyKey, new ReadOnlyObservableCollection <ValidationError>(validationErrorCollection)); return; } d.ClearValue(Validation.ErrorsPropertyKey); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj)); StateActivity state = obj as StateActivity; if (state == null) { throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj"); } // First we validate contaiment if (state.Parent != null) { if (StateMachineHelpers.IsStateMachine(state)) { validationErrors.Add(new ValidationError(SR.GetError_StateMachineWorkflowMustBeARootActivity(), ErrorNumbers.Error_StateMachineWorkflowMustBeARootActivity)); return(validationErrors); } else { // Make sure that a State is always contained in // another State or StateMachineWorkflow. State machine // within a sequential workflow is not supported if (!(state.Parent is StateActivity)) { validationErrors.Add(new ValidationError(SR.GetError_InvalidStateActivityParent(), ErrorNumbers.Error_InvalidStateActivityParent)); return(validationErrors); } } } if (state.Parent == null && !StateMachineHelpers.IsStateMachine(state)) { ValidateCustomStateActivity(state, validationErrors); } if (StateMachineHelpers.IsLeafState(state)) { ValidateLeafState(state, validationErrors); } else if (StateMachineHelpers.IsRootState(state)) { ValidateRootState(state, validationErrors); } else { ValidateState(state, validationErrors); } ValidateEventDrivenActivities(state, validationErrors); return(validationErrors); }
protected virtual void Validate(T obj) { ValidationErrorCollection errorCollection = new ValidationErrorCollection(); errorCollection.Add(obj.Validate()); OnValidating(obj, errorCollection); if (errorCollection.Count > 0) { throw new ValidationException(errorCollection); } }
protected internal override ValidationErrorCollection ValidateChanges(Activity contextActivity) { ValidationErrorCollection errors = base.ValidateChanges(contextActivity); Activity activity = contextActivity.TraverseDottedPathFromRoot(this.originalRemovedActivity.DottedPath); if (WorkflowChanges.IsActivityExecutable(activity) && (activity.ExecutionStatus == ActivityExecutionStatus.Executing)) { errors.Add(new ValidationError(SR.GetString("Error_RemoveExecutingActivity", new object[] { this.originalRemovedActivity.QualifiedName }), 0x11d)); } return(errors); }
public static bool Validate(SetStateActivity setState, ValidationErrorCollection validationErrors) { SetStateValidator.SetStateContainment containment = new SetStateValidator.SetStateContainment(); ValidateContainment(containment, setState); if (containment.validParentFound && containment.validParentStateFound) { return(true); } validationErrors.Add(new ValidationError(SR.GetError_SetStateOnlyWorksOnStateMachineWorkflow(), 0x5f2)); return(false); }
private static void ValidateInitialState(StateActivity state, ValidationErrorCollection validationErrors) { string initialStateName = StateMachineHelpers.GetInitialStateName(state); if (String.IsNullOrEmpty(initialStateName)) { if (state.Activities.Count > 0) { // we only require an initial state if the state machine is // not empty validationErrors.Add(new ValidationError( SR.GetString(SR.Error_PropertyNotSet, StateMachineWorkflowActivity.InitialStateNamePropertyName), ErrorNumbers.Error_PropertyNotSet, false, StateMachineWorkflowActivity.InitialStateNamePropertyName)); } } else { StateActivity initialState = StateMachineHelpers.FindStateByName( state, initialStateName); if (initialState == null) { validationErrors.Add(new ValidationError( SR.GetError_InitialStateMustPointToAState(), ErrorNumbers.Error_InitialStateMustPointToAState, false, StateMachineWorkflowActivity.InitialStateNamePropertyName)); } else { if (!StateMachineHelpers.IsLeafState(initialState)) { validationErrors.Add(new ValidationError( SR.GetError_InitialStateMustPointToALeafNodeState(), ErrorNumbers.Error_InitialStateMustPointToALeafNodeState, false, StateMachineWorkflowActivity.InitialStateNamePropertyName)); } // InitialState cannot be the completed state string completedStateName = StateMachineHelpers.GetCompletedStateName(state); if (initialStateName == completedStateName) { validationErrors.Add(new ValidationError( SR.GetError_InitialStateMustBeDifferentThanCompletedState(), ErrorNumbers.Error_InitialStateMustBeDifferentThanCompletedState, false, StateMachineWorkflowActivity.InitialStateNamePropertyName)); } } } }
internal void Validate(RuleValidation validation) { int oldErrorCount = validation.Errors.Count; if (string.IsNullOrEmpty(name)) { validation.Errors.Add(new ValidationError(Messages.RuleNameMissing, ErrorNumbers.Error_InvalidConditionName)); } // check the condition if (condition == null) { validation.Errors.Add(new ValidationError(Messages.MissingRuleCondition, ErrorNumbers.Error_MissingRuleCondition)); } else { condition.Validate(validation); } // check the optional then actions if (thenActions != null) { ValidateRuleActions(thenActions, validation); } // check the optional else actions if (elseActions != null) { ValidateRuleActions(elseActions, validation); } // fix up the error messages by prepending the rule name ValidationErrorCollection errors = validation.Errors; if (errors.Count > oldErrorCount) { string prefix = string.Format(CultureInfo.CurrentCulture, Messages.RuleValidationError, name); int newErrorCount = errors.Count; for (int i = oldErrorCount; i < newErrorCount; ++i) { ValidationError oldError = errors[i]; ValidationError newError = new ValidationError(prefix + oldError.ErrorText, oldError.ErrorNumber, oldError.IsWarning); foreach (DictionaryEntry de in oldError.UserData) { newError.UserData[de.Key] = de.Value; } errors[i] = newError; } } }
public void AddValidationError(string ruleIdGuidString, string ruleName, ValidationErrorCollection errors) { if (_translatedRuleSet) { Guid ruleId = new Guid(ruleIdGuidString); _validationErrors.Add(ruleId, errors); } else { _nonTranslatedRulesValidationErrors.Add(ruleName, errors); } }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { if (!(obj is CallExternalMethodActivity)) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(CallExternalMethodActivity).FullName }), "obj"); } ValidationErrorCollection errors = base.Validate(manager, obj); errors.AddRange(CorrelationSetsValidator.Validate(manager, obj)); errors.AddRange(ParameterBindingValidator.Validate(manager, obj)); return(errors); }
protected override void EndExecute( AsyncCodeActivityContext context, IAsyncResult result) { ValidationErrorCollection errors = ((Func <T, String, String, ValidationErrorCollection>) context.UserState).EndInvoke(result); if (errors != null) { Errors.Set(context, errors); } }
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); }
// Update HasErrors and Invalidate the public ValidationErrors property whose GetOverride will return // the updated value of ValidationErrorsInternal, nicely wrapped into a ReadOnlyCollection<T> private static void OnErrorsInternalChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ValidationErrorCollection newErrors = e.NewValue as ValidationErrorCollection; if (newErrors != null) { d.SetValue(ErrorsPropertyKey, new ReadOnlyObservableCollection <ValidationError>(newErrors)); } else { d.ClearValue(ErrorsPropertyKey); } }
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); ConditionedActivityGroup conditionedActivityGroup = obj as ConditionedActivityGroup; if (conditionedActivityGroup == null) { throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(ConditionedActivityGroup).FullName), "obj"); } return(validationErrors); }
/// <summary> /// Overridden to validate the activity properties and populate the error collection. /// Only one child activity is allowed. If multiple acitivties need to be executed, /// place them in a sequence or other appropriate composite activities. /// </summary> /// <param name="manager"></param> /// <param name="obj"></param> /// <returns></returns> public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj)); ForEach foreachActivity = obj as ForEach; if (foreachActivity == null) throw new ArgumentException("Validate parameter 'obj' is not a ForEach activity."); if (foreachActivity.EnabledActivities.Count > 1) validationErrors.Add(new ValidationError("Only one child is allowed in the ForEach activity.", InvalidNumberOfChildren)); return validationErrors; }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj)); StateActivity state = obj as StateActivity; if (state == null) throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj"); // First we validate contaiment if (state.Parent != null) { if (StateMachineHelpers.IsStateMachine(state)) { validationErrors.Add(new ValidationError(SR.GetError_StateMachineWorkflowMustBeARootActivity(), ErrorNumbers.Error_StateMachineWorkflowMustBeARootActivity)); return validationErrors; } else { // Make sure that a State is always contained in // another State or StateMachineWorkflow. State machine // within a sequential workflow is not supported if (!(state.Parent is StateActivity)) { validationErrors.Add(new ValidationError(SR.GetError_InvalidStateActivityParent(), ErrorNumbers.Error_InvalidStateActivityParent)); return validationErrors; } } } if (state.Parent == null && !StateMachineHelpers.IsStateMachine(state)) { ValidateCustomStateActivity(state, validationErrors); } if (StateMachineHelpers.IsLeafState(state)) { ValidateLeafState(state, validationErrors); } else if (StateMachineHelpers.IsRootState(state)) { ValidateRootState(state, validationErrors); } else { ValidateState(state, validationErrors); } ValidateEventDrivenActivities(state, validationErrors); return validationErrors; }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection errors = new ValidationErrorCollection(base.Validate(manager, obj)); WhileActivity activity = obj as WhileActivity; if (activity == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(WhileActivity).FullName }), "obj"); } if (activity.EnabledActivities.Count != 1) { errors.Add(new ValidationError(SR.GetString("Error_WhileShouldHaveOneChild"), 0x60b)); } return errors; }
internal RuleValidation(object thisObject) { this.errors = new ValidationErrorCollection(); this.typesUsed = new Dictionary<string, Type>(0x10); this.activeParentNodes = new Stack<CodeExpression>(); this.expressionInfoMap = new Dictionary<CodeExpression, RuleExpressionInfo>(); this.typeRefMap = new Dictionary<CodeTypeReference, Type>(); if (thisObject == null) { throw new ArgumentNullException("thisObject"); } this.thisType = thisObject.GetType(); this.typeProvider = new SimpleRunTimeTypeProvider(this.thisType.Assembly); }
public RuleValidation(Type thisType, ITypeProvider typeProvider) { this.errors = new ValidationErrorCollection(); this.typesUsed = new Dictionary<string, Type>(0x10); this.activeParentNodes = new Stack<CodeExpression>(); this.expressionInfoMap = new Dictionary<CodeExpression, RuleExpressionInfo>(); this.typeRefMap = new Dictionary<CodeTypeReference, Type>(); if (thisType == null) { throw new ArgumentNullException("thisType"); } this.thisType = thisType; this.typeProvider = (typeProvider != null) ? typeProvider : new SimpleRunTimeTypeProvider(this.thisType.Assembly); }
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; }
protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader) { if (workflowDefinitionReader == null) { throw new ArgumentNullException("workflowDefinitionReader"); } Activity activity = null; ValidationErrorCollection errors = new ValidationErrorCollection(); ServiceContainer container = new ServiceContainer(); ITypeProvider service = base.Runtime.GetService<ITypeProvider>(); if (service != null) { container.AddService(typeof(ITypeProvider), service); } DesignerSerializationManager manager = new DesignerSerializationManager(container); try { using (manager.CreateSession()) { WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager); activity = new WorkflowMarkupSerializer().Deserialize(serializationManager, workflowDefinitionReader) as Activity; if ((activity != null) && (rulesReader != null)) { object obj2 = new WorkflowMarkupSerializer().Deserialize(serializationManager, rulesReader); activity.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, obj2); } foreach (object obj3 in manager.Errors) { if (obj3 is WorkflowMarkupSerializationException) { errors.Add(new ValidationError(((WorkflowMarkupSerializationException) obj3).Message, 0x15b)); } else { errors.Add(new ValidationError(obj3.ToString(), 0x15b)); } } } } catch (Exception exception) { errors.Add(new ValidationError(exception.Message, 0x15b)); } if (errors.HasErrors) { throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); } return activity; }
public static ValidationErrorCollection GetErrors(object instance) { ValidationErrorCollection errors = new ValidationErrorCollection(); foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(instance).Cast<PropertyDescriptor>()) { foreach (ValidationAttribute attribute in prop.Attributes.OfType<ValidationAttribute>()) { if (!attribute.IsValid(prop.GetValue(instance))) { errors.Add(new ValidationError(prop.Name, attribute.FormatErrorMessage(string.Empty), instance)); } else if (attribute is DataTypeAttribute){ var dataAttr = (DataTypeAttribute)attribute; // validate datetime min, max if (dataAttr.DataType == DataType.Date || dataAttr.DataType == DataType.DateTime){ if (prop.PropertyType == typeof(DateTime) || (prop.PropertyType == typeof(DateTime?) && prop.GetValue(instance) != null)){ // validate min date DateTime value; if (prop.PropertyType == typeof(DateTime)) { value = (DateTime)prop.GetValue(instance); } else { value = ((DateTime?)prop.GetValue(instance)).Value; } if (value < System.Data.SqlTypes.SqlDateTime.MinValue.Value || value > System.Data.SqlTypes.SqlDateTime.MaxValue.Value) { errors.Add(new ValidationError(prop.Name, "Invalid datetime input", instance)); } } } else if (dataAttr.DataType == DataType.EmailAddress) { var value = prop.GetValue(instance) as String; if (value.Length > 0 && !Regex.Match(value, "^[\\w\\.=-]+@[\\w\\.-]+\\.[\\w]{2,}$").Success) { errors.Add(new ValidationError(prop.Name, "Please enter a valid email address", instance)); } } } } } return errors; }