Ejemplo n.º 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 ValidationResults InternalValidate()
 {
     this.options = ProcessActivityTreeOptions.GetValidationOptions(this.settings);
     if (this.settings.OnlyUseAdditionalConstraints)
     {
         IList <ValidationError> validationErrors = null;
         ActivityUtilities.CacheRootMetadata(this.rootToValidate, null, this.options, new ActivityUtilities.ProcessActivityCallback(this.ValidateElement), ref validationErrors);
     }
     else
     {
         ActivityUtilities.CacheRootMetadata(this.rootToValidate, null, this.options, new ActivityUtilities.ProcessActivityCallback(this.ValidateElement), ref this.errors);
     }
     return(new ValidationResults(this.errors));
 }
Ejemplo n.º 4
0
            internal ValidationResults InternalValidate()
            {
                this.options = ProcessActivityTreeOptions.GetValidationOptions(this.settings);

                if (this.settings.OnlyUseAdditionalConstraints)
                {
                    // We don't want the errors from CacheMetadata so we send those to a "dummy" list.
                    IList <ValidationError> suppressedErrors = null;
                    ActivityUtilities.CacheRootMetadata(this.rootToValidate, this.environment, this.options, new ActivityUtilities.ProcessActivityCallback(ValidateElement), ref suppressedErrors);
                }
                else
                {
                    // We want to add the CacheMetadata errors to our errors collection
                    ActivityUtilities.CacheRootMetadata(this.rootToValidate, this.environment, this.options, new ActivityUtilities.ProcessActivityCallback(ValidateElement), ref this.errors);
                }

                return(new ValidationResults(this.errors));
            }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 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);
                        }
                    }
                }
            }
Ejemplo n.º 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);
                    }
                }
            }
        }
Ejemplo n.º 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);
        }
 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);
        }