public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj)); SetStateActivity setState = obj as SetStateActivity; if (setState == null) { throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(StateActivity).FullName }), "obj"); } if (SetStateContainment.Validate(setState, validationErrors)) { if (string.IsNullOrEmpty(setState.TargetStateName)) { validationErrors.Add(new ValidationError(SR.GetString("Error_PropertyNotSet", new object[] { "TargetStateName" }), 0x116, false, "TargetStateName")); return(validationErrors); } StateActivity state = StateMachineHelpers.FindStateByName(StateMachineHelpers.GetRootState(StateMachineHelpers.FindEnclosingState(setState)), setState.TargetStateName); if (state == null) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToAState(), 0x5f3, false, "TargetStateName")); return(validationErrors); } if (!StateMachineHelpers.IsLeafState(state)) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToALeafNodeState(), 0x5f4, false, "TargetStateName")); } } return(validationErrors); }
public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj)); SetStateActivity setState = obj as SetStateActivity; if (setState == null) { throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj"); } if (!SetStateContainment.Validate(setState, validationErrors)) { return(validationErrors); // could not find a valid parent } if (String.IsNullOrEmpty(setState.TargetStateName)) { validationErrors.Add(new ValidationError( SR.GetString(SR.Error_PropertyNotSet, SetStateActivity.TargetStateNamePropertyName), ErrorNumbers.Error_PropertyNotSet, false, SetStateActivity.TargetStateNamePropertyName)); } else { StateActivity enclosingState = StateMachineHelpers.FindEnclosingState(setState); Debug.Assert(enclosingState != null); // this should be caught by the SetStateContainment.Validate call above StateActivity rootState = StateMachineHelpers.GetRootState(enclosingState); StateActivity targetActivity = StateMachineHelpers.FindStateByName( rootState, setState.TargetStateName); StateActivity targetState = targetActivity as StateActivity; if (targetState == null) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToAState(), ErrorNumbers.Error_SetStateMustPointToAState, false, SetStateActivity.TargetStateNamePropertyName)); } else { if (!StateMachineHelpers.IsLeafState(targetState)) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToALeafNodeState(), ErrorNumbers.Error_SetStateMustPointToALeafNodeState, false, SetStateActivity.TargetStateNamePropertyName)); } } } return(validationErrors); }