protected override void OnExecute(NativeActivityContext context, object objectToValidate, ValidationContext objectToValidateContext) { bool foundMultiple; ActivityWithResult boundExpression; LocationReference locationReference; ActivityWithResult activity = (ActivityWithResult)objectToValidate; foreach (RuntimeArgument runtimeArgument in activity.RuntimeArguments) { boundExpression = runtimeArgument.BoundArgument.Expression; if (boundExpression != null && boundExpression is ILocationReferenceWrapper) { locationReference = ((ILocationReferenceWrapper)boundExpression).LocationReference; if (locationReference != null) { foundMultiple = FindLocationReferencesFromEnvironment(objectToValidateContext.Environment, locationReference.Name); if (foundMultiple) { Constraint.AddValidationError(context, new ValidationError(SR.AmbiguousVBVariableReference(locationReference.Name))); } } } } }
internal static void RunConstraints(ActivityUtilities.ChildActivity childActivity, ActivityUtilities.ActivityCallStack parentChain, IList<Constraint> constraints, ProcessActivityTreeOptions options, bool suppressGetChildrenViolations, ref IList<ValidationError> validationErrors) { if (constraints != null) { Activity activity = childActivity.Activity; LocationReferenceEnvironment parentEnvironment = activity.GetParentEnvironment(); Dictionary<string, object> inputs = new Dictionary<string, object>(2); for (int i = 0; i < constraints.Count; i++) { Constraint workflow = constraints[i]; if (workflow != null) { object obj2; inputs["ToValidate"] = activity; ValidationContext context = new ValidationContext(childActivity, parentChain, options, parentEnvironment); inputs["ToValidateContext"] = context; IDictionary<string, object> dictionary2 = null; try { dictionary2 = WorkflowInvoker.Invoke(workflow, inputs); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } ValidationError data = new ValidationError(System.Activities.SR.InternalConstraintException(workflow.DisplayName, activity.GetType().FullName, activity.DisplayName, exception.ToString()), false) { Source = activity, Id = activity.Id }; ActivityUtilities.Add<ValidationError>(ref validationErrors, data); } if ((dictionary2 != null) && dictionary2.TryGetValue("ViolationList", out obj2)) { IList<ValidationError> list = (IList<ValidationError>) obj2; if (list.Count > 0) { Activity activity2; if (validationErrors == null) { validationErrors = new List<ValidationError>(); } string str = GenerateValidationErrorPrefix(childActivity.Activity, parentChain, out activity2); for (int j = 0; j < list.Count; j++) { ValidationError item = list[j]; item.Source = activity2; item.Id = activity2.Id; if (!string.IsNullOrEmpty(str)) { item.Message = str + item.Message; } validationErrors.Add(item); } } } if (!suppressGetChildrenViolations) { context.AddGetChildrenErrors(ref validationErrors); } } } } }
protected abstract void OnExecute(NativeActivityContext context, object objectToValidate, ValidationContext objectToValidateContext);