Esempio n. 1
0
 internal IEnumerable <Activity> GetChildren()
 {
     if (!this.owner.Equals(ActivityUtilities.ChildActivity.Empty))
     {
         return(ActivityValidationServices.GetChildren(this.owner, this.parentChain, this.options));
     }
     return(ActivityValidationServices.EmptyChildren);
 }
 private void ValidateExpressionSubtree(ActivityUtilities.ChildActivity childActivity, ActivityUtilities.ActivityCallStack parentChain)
 {
     if (childActivity.Activity.InternalCanInduceIdle)
     {
         Activity        activity             = childActivity.Activity;
         Activity        expressionRoot       = this.expressionRoot;
         RuntimeArgument boundRuntimeArgument = ActivityValidationServices.GetBoundRuntimeArgument(expressionRoot);
         ValidationError data = new ValidationError(System.Activities.SR.CanInduceIdleActivityInArgumentExpression(boundRuntimeArgument.Name, expressionRoot.Parent.DisplayName, activity.DisplayName), true, boundRuntimeArgument.Name, expressionRoot.Parent);
         ActivityUtilities.Add <ValidationError>(ref this.errors, data);
     }
 }
Esempio n. 3
0
        internal IEnumerable <Activity> GetWorkflowTree()
        {
            Activity parent = this.owner.Activity;

            if (parent == null)
            {
                return(ActivityValidationServices.EmptyChildren);
            }
            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }
            List <Activity> list = ActivityValidationServices.GetChildren(new ActivityUtilities.ChildActivity(parent, true), new ActivityUtilities.ActivityCallStack(), this.options);

            list.Add(parent);
            return(list);
        }
            private void ValidateElement(ActivityUtilities.ChildActivity childActivity, ActivityUtilities.ActivityCallStack parentChain)
            {
                Activity objA = childActivity.Activity;

                if (!this.settings.SingleLevel || object.ReferenceEquals(objA, this.rootToValidate))
                {
                    if (this.settings.HasAdditionalConstraints)
                    {
                        bool suppressGetChildrenViolations = this.settings.OnlyUseAdditionalConstraints || this.settings.SingleLevel;
                        for (Type type = objA.GetType(); type != null; type = type.BaseType)
                        {
                            IList <Constraint> list;
                            if (this.settings.AdditionalConstraints.TryGetValue(type, out list))
                            {
                                ActivityValidationServices.RunConstraints(childActivity, parentChain, list, this.options, suppressGetChildrenViolations, ref this.errors);
                            }
                            if (type.IsGenericType)
                            {
                                IList <Constraint> list2;
                                Type genericTypeDefinition = type.GetGenericTypeDefinition();
                                if ((genericTypeDefinition != null) && this.settings.AdditionalConstraints.TryGetValue(genericTypeDefinition, out list2))
                                {
                                    ActivityValidationServices.RunConstraints(childActivity, parentChain, list2, this.options, suppressGetChildrenViolations, ref this.errors);
                                }
                            }
                        }
                    }
                    if (childActivity.Activity.IsExpressionRoot)
                    {
                        if (childActivity.Activity.HasNonEmptySubtree)
                        {
                            this.expressionRoot = childActivity.Activity;
                            ActivityUtilities.FinishCachingSubtree(childActivity, parentChain, ProcessActivityTreeOptions.FullCachingOptions, new ActivityUtilities.ProcessActivityCallback(this.ValidateExpressionSubtree));
                            this.expressionRoot = null;
                        }
                        else if (childActivity.Activity.InternalCanInduceIdle)
                        {
                            Activity        activity             = childActivity.Activity;
                            RuntimeArgument boundRuntimeArgument = ActivityValidationServices.GetBoundRuntimeArgument(activity);
                            ValidationError data = new ValidationError(System.Activities.SR.CanInduceIdleActivityInArgumentExpression(boundRuntimeArgument.Name, activity.Parent.DisplayName, activity.DisplayName), true, boundRuntimeArgument.Name, activity.Parent);
                            ActivityUtilities.Add <ValidationError>(ref this.errors, data);
                        }
                    }
                }
            }
Esempio n. 5
0
        internal IEnumerable <Activity> GetWorkflowTree()
        {
            // It is okay to just walk the declared parent chain here
            var currentNode = this.owner.Activity;

            if (currentNode != null)
            {
                while (currentNode.Parent != null)
                {
                    currentNode = currentNode.Parent;
                }
                var nodes = ActivityValidationServices.GetChildren(new ActivityUtilities.ChildActivity(currentNode, true), new ActivityUtilities.ActivityCallStack(), this.options);
                nodes.Add(currentNode);
                return(nodes);
            }
            else
            {
                return(ActivityValidationServices.EmptyChildren);
            }
        }
Esempio n. 6
0
        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 toValidate = childActivity.Activity;

                LocationReferenceEnvironment environment = toValidate.GetParentEnvironment();

                Dictionary <string, object> inputDictionary = new Dictionary <string, object>(2);

                for (int constraintIndex = 0; constraintIndex < constraints.Count; constraintIndex++)
                {
                    Constraint constraint = constraints[constraintIndex];

                    // there may be null entries here
                    if (constraint == null)
                    {
                        continue;
                    }

                    inputDictionary[Constraint.ToValidateArgumentName] = toValidate;
                    ValidationContext validationContext = new ValidationContext(childActivity, parentChain, options, environment);
                    inputDictionary[Constraint.ToValidateContextArgumentName] = validationContext;
                    IDictionary <string, object> results = null;

                    try
                    {
                        results = WorkflowInvoker.Invoke(constraint, inputDictionary);
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        ValidationError constraintExceptionValidationError = new ValidationError(SR.InternalConstraintException(constraint.DisplayName, toValidate.GetType().FullName, toValidate.DisplayName, e.ToString()), false)
                        {
                            Source = toValidate,
                            Id     = toValidate.Id
                        };

                        ActivityUtilities.Add(ref validationErrors, constraintExceptionValidationError);
                    }

                    if (results != null)
                    {
                        if (results.TryGetValue(Constraint.ValidationErrorListArgumentName, out object resultValidationErrors))
                        {
                            IList <ValidationError> validationErrorList = (IList <ValidationError>)resultValidationErrors;

                            if (validationErrorList.Count > 0)
                            {
                                if (validationErrors == null)
                                {
                                    validationErrors = new List <ValidationError>();
                                }

                                string prefix = ActivityValidationServices.GenerateValidationErrorPrefix(childActivity.Activity, parentChain, options, out Activity source);

                                for (int validationErrorIndex = 0; validationErrorIndex < validationErrorList.Count; validationErrorIndex++)
                                {
                                    ValidationError validationError = validationErrorList[validationErrorIndex];

                                    validationError.Source = source;
                                    validationError.Id     = source.Id;
                                    if (!string.IsNullOrEmpty(prefix))
                                    {
                                        validationError.Message = prefix + validationError.Message;
                                    }
                                    validationErrors.Add(validationError);
                                }
                            }
                        }
                    }

                    if (!suppressGetChildrenViolations)
                    {
                        validationContext.AddGetChildrenErrors(ref validationErrors);
                    }
                }
            }
        }