Пример #1
0
 internal ValidationContext(ActivityUtilities.ChildActivity owner, ActivityUtilities.ActivityCallStack parentChain, ProcessActivityTreeOptions options, LocationReferenceEnvironment environment)
 {
     this.owner       = owner;
     this.parentChain = parentChain;
     this.options     = options;
     this.environment = environment;
 }
 internal ValidationContext(ActivityUtilities.ChildActivity owner, ActivityUtilities.ActivityCallStack parentChain, ProcessActivityTreeOptions options, LocationReferenceEnvironment environment)
 {
     this.owner = owner;
     this.parentChain = parentChain;
     this.options = options;
     this.environment = environment;
 }
        internal static string GenerateValidationErrorPrefix(Activity toValidate, ActivityUtilities.ActivityCallStack parentChain, out Activity source)
        {
            bool   flag = true;
            string str  = "";

            source = toValidate;
            for (int i = 0; i < parentChain.Count; i++)
            {
                ActivityUtilities.ChildActivity activity = parentChain[i];
                if (activity.Activity.MemberOf.Parent != null)
                {
                    flag = false;
                    break;
                }
            }
            while (source.MemberOf.Parent != null)
            {
                source = source.Parent;
            }
            if (toValidate.MemberOf.Parent != null)
            {
                return(System.Activities.SR.ValidationErrorPrefixForHiddenActivity(source));
            }
            if (!flag)
            {
                str = System.Activities.SR.ValidationErrorPrefixForPublicActivityWithHiddenParent(source.Parent, source);
            }
            return(str);
        }
Пример #4
0
        internal static List <Activity> GetChildren(ActivityUtilities.ChildActivity root, ActivityUtilities.ActivityCallStack parentChain, ProcessActivityTreeOptions options)
        {
            ActivityUtilities.FinishCachingSubtree(root, parentChain, options);

            List <Activity> listOfChildren = new List <Activity>();

            foreach (Activity activity in WorkflowInspectionServices.GetActivities(root.Activity))
            {
                listOfChildren.Add(activity);
            }

            int toProcessIndex = 0;

            while (toProcessIndex < listOfChildren.Count)
            {
                foreach (Activity activity in WorkflowInspectionServices.GetActivities(listOfChildren[toProcessIndex]))
                {
                    listOfChildren.Add(activity);
                }

                toProcessIndex++;
            }

            return(listOfChildren);
        }
Пример #5
0
            private void ValidateExpressionSubtree(ActivityUtilities.ChildActivity childActivity, ActivityUtilities.ActivityCallStack parentChain)
            {
                Fx.Assert(this.expressionRoot != null, "This callback should be called activities in the expression subtree only.");

                if (childActivity.Activity.InternalCanInduceIdle)
                {
                    Activity activity       = childActivity.Activity;
                    Activity expressionRoot = this.expressionRoot;

                    RuntimeArgument runtimeArgument = GetBoundRuntimeArgument(expressionRoot);
                    ValidationError error           = new ValidationError(SR.CanInduceIdleActivityInArgumentExpression(runtimeArgument.Name, expressionRoot.Parent.DisplayName, activity.DisplayName), true, runtimeArgument.Name, expressionRoot.Parent);
                    ActivityUtilities.Add(ref this.errors, error);
                }
            }
Пример #6
0
            private void ValidateElement(ActivityUtilities.ChildActivity childActivity, ActivityUtilities.ActivityCallStack parentChain)
            {
                Activity toValidate = childActivity.Activity;

                if (!this.settings.SingleLevel || object.ReferenceEquals(toValidate, this.rootToValidate))
                {
                    // 0. Open time violations are captured by the CacheMetadata walk.

                    // 1. Argument validations are done by the CacheMetadata walk.

                    // 2. Build constraints are done by the CacheMetadata walk.

                    // 3. Then do policy constraints
                    if (this.settings.HasAdditionalConstraints && childActivity.CanBeExecuted && parentChain.WillExecute)
                    {
                        bool suppressGetChildrenViolations = this.settings.OnlyUseAdditionalConstraints || this.settings.SingleLevel;

                        Type currentType = toValidate.GetType();

                        while (currentType != null)
                        {
                            if (this.settings.AdditionalConstraints.TryGetValue(currentType, out IList <Constraint> policyConstraints))
                            {
                                RunConstraints(childActivity, parentChain, policyConstraints, this.options, suppressGetChildrenViolations, ref this.errors);
                            }

                            if (currentType.IsGenericType)
                            {
                                Type genericDefinitionType = currentType.GetGenericTypeDefinition();
                                if (genericDefinitionType != null)
                                {
                                    if (this.settings.AdditionalConstraints.TryGetValue(genericDefinitionType, out IList <Constraint> genericTypePolicyConstraints))
                                    {
                                        RunConstraints(childActivity, parentChain, genericTypePolicyConstraints, this.options, suppressGetChildrenViolations, ref this.errors);
                                    }
                                }
                            }
                            currentType = currentType.BaseType;
                        }
                    }

                    //4. Validate if the argument expression subtree contains an activity that can induce idle.
                    if (childActivity.Activity.IsExpressionRoot)
                    {
                        if (childActivity.Activity.HasNonEmptySubtree)
                        {
                            this.expressionRoot = childActivity.Activity;
                            // Back-compat: In Dev10 we always used ProcessActivityTreeOptions.FullCachingOptions here, and ignored this.options.
                            // So we need to continue to do that, unless the new Dev11 flag SkipRootConfigurationValidation is passed.
                            ProcessActivityTreeOptions options = this.options.SkipRootConfigurationValidation ? this.options : ProcessActivityTreeOptions.FullCachingOptions;
                            ActivityUtilities.FinishCachingSubtree(childActivity, parentChain, options, ValidateExpressionSubtree);
                            this.expressionRoot = null;
                        }
                        else if (childActivity.Activity.InternalCanInduceIdle)
                        {
                            Activity        activity        = childActivity.Activity;
                            RuntimeArgument runtimeArgument = GetBoundRuntimeArgument(activity);
                            ValidationError error           = new ValidationError(SR.CanInduceIdleActivityInArgumentExpression(runtimeArgument.Name, activity.Parent.DisplayName, activity.DisplayName), true, runtimeArgument.Name, activity.Parent);
                            ActivityUtilities.Add(ref this.errors, error);
                        }
                    }
                }
            }
Пример #7
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);
                    }
                }
            }
        }
Пример #8
0
        static internal string GenerateValidationErrorPrefix(Activity toValidate, ActivityUtilities.ActivityCallStack parentChain, ProcessActivityTreeOptions options, out Activity source)
        {
            bool   parentVisible = true;
            string prefix        = "";

            source = toValidate;

            // Processing for implementation of activity
            // during build time
            if (options.SkipRootConfigurationValidation)
            {
                // Check if the activity is a implementation child
                if (toValidate.MemberOf.Parent != null)
                {
                    // Check if activity is an immediate implementation child
                    // of x:class activity. This means that the activity is
                    // being designed and hence we do not want to add the
                    // prefix at build time
                    if (toValidate.MemberOf.Parent.Parent == null)
                    {
                        prefix = "";
                        source = toValidate;
                    }
                    else
                    {
                        // This means the activity is a child of immediate implementation child
                        // of x:class activity which means the activity is not visible.
                        // The source points to the first visible parent activity in the
                        // parent chain.
                        while (source.MemberOf.Parent.Parent != null)
                        {
                            source = source.Parent;
                        }
                        prefix = SR.ValidationErrorPrefixForHiddenActivity(source);
                    }
                    return(prefix);
                }
            }

            // Find out if any of the parents of the activity are not publicly visible
            for (int i = 0; i < parentChain.Count; i++)
            {
                if (parentChain[i].Activity.MemberOf.Parent != null)
                {
                    parentVisible = false;
                    break;
                }
            }

            // Figure out the source of validation error:
            //    - For hidden activity - source will be closest visible public parent
            //    - For visible activity - source will be the activity itself
            // In current design an activity is visible only if it is in the root id space.
            // In future, if we provide a knob for the user to specify the
            // id spaces that are visible, then this check needs to be changed
            // to iterate over the parentChain and find the closest parent activity that
            // is in the visible id spaces.
            while (source.MemberOf.Parent != null)
            {
                source = source.Parent;
            }

            if (toValidate.MemberOf.Parent != null)
            {
                // Activity itself is hidden
                prefix = SR.ValidationErrorPrefixForHiddenActivity(source);
            }
            else
            {
                if (!parentVisible)
                {
                    // Activity itself is public but has a private parent
                    prefix = SR.ValidationErrorPrefixForPublicActivityWithHiddenParent(source.Parent, source);
                }
            }
            return(prefix);
        }
 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);
     }
 }
            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);
                        }
                    }
                }
            }
 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);
                 }
             }
         }
     }
 }
        internal static List <Activity> GetChildren(ActivityUtilities.ChildActivity root, ActivityUtilities.ActivityCallStack parentChain, ProcessActivityTreeOptions options)
        {
            ActivityUtilities.FinishCachingSubtree(root, parentChain, options);
            List <Activity> list = new List <Activity>();

            foreach (Activity activity in WorkflowInspectionServices.GetActivities(root.Activity))
            {
                list.Add(activity);
            }
            for (int i = 0; i < list.Count; i++)
            {
                foreach (Activity activity2 in WorkflowInspectionServices.GetActivities(list[i]))
                {
                    list.Add(activity2);
                }
            }
            return(list);
        }