internal bool InitializeRelationship(Activity parent, ActivityCollectionType collectionType, ref IList <ValidationError> validationErrors)
        {
            if (this.cacheId == parent.CacheId)
            {
                Activity owner = parent.MemberOf.Owner;
                if (owner == null)
                {
                    Activity activity2 = this.Handler;
                    if (activity2 == null)
                    {
                        ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferencedWithoutTargetNoHandler(parent.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    else
                    {
                        ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferencedWithoutTarget(activity2.DisplayName, parent.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    return(false);
                }
                if (owner.Delegates.Contains(this) || owner.ImportedDelegates.Contains(this))
                {
                    return(true);
                }
                Activity handler = this.Handler;
                if (handler == null)
                {
                    ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferencedNoHandler(parent.DisplayName, owner.DisplayName, this.owner.DisplayName), false, parent));
                }
                else
                {
                    ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ActivityDelegateCannotBeReferenced(handler.DisplayName, parent.DisplayName, owner.DisplayName, this.owner.DisplayName), false, parent));
                }
                return(false);
            }
            this.owner   = parent;
            this.cacheId = parent.CacheId;
            this.parentCollectionType = collectionType;
            this.InternalCacheMetadata();
            LocationReferenceEnvironment implementationEnvironment = null;

            if (collectionType == ActivityCollectionType.Implementation)
            {
                implementationEnvironment = parent.ImplementationEnvironment;
            }
            else
            {
                implementationEnvironment = parent.PublicEnvironment;
            }
            if (this.RuntimeDelegateArguments.Count > 0)
            {
                ActivityLocationReferenceEnvironment environment2 = new ActivityLocationReferenceEnvironment(implementationEnvironment);
                implementationEnvironment = environment2;
                for (int i = 0; i < this.RuntimeDelegateArguments.Count; i++)
                {
                    RuntimeDelegateArgument argument      = this.RuntimeDelegateArguments[i];
                    DelegateArgument        boundArgument = argument.BoundArgument;
                    if (boundArgument != null)
                    {
                        if (boundArgument.Direction != argument.Direction)
                        {
                            ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.RuntimeDelegateArgumentDirectionIncorrect, parent));
                        }
                        if (boundArgument.Type != argument.Type)
                        {
                            ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.RuntimeDelegateArgumentTypeIncorrect, parent));
                        }
                        environment2.Declare(boundArgument, this.owner, ref validationErrors);
                    }
                }
            }
            this.Environment = implementationEnvironment;
            if (this.Handler != null)
            {
                return(this.Handler.InitializeRelationship(this, collectionType, ref validationErrors));
            }
            return(true);
        }
Пример #2
0
 internal void Bind(RuntimeDelegateArgument runtimeArgument)
 {
     this.runtimeArgument = runtimeArgument;
 }
Пример #3
0
        internal bool InitializeRelationship(Activity parent, ActivityCollectionType collectionType, ref IList <ValidationError> validationErrors)
        {
            if (this.cacheId == parent.CacheId)
            {
                Fx.Assert(this.owner != null, "We must have set the owner when we set the cache ID");

                // This means that we've already encountered a parent in the tree

                // Validate that it is visible.

                // In order to see the activity the new parent must be
                // in the implementation IdSpace of an activity which has
                // a public reference to it.
                Activity referenceTarget = parent.MemberOf.Owner;

                if (referenceTarget == null)
                {
                    Activity handler = this.Handler;

                    if (handler == null)
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferencedWithoutTargetNoHandler(parent.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    else
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferencedWithoutTarget(handler.DisplayName, parent.DisplayName, this.owner.DisplayName), false, parent));
                    }

                    return(false);
                }
                else if (!referenceTarget.Delegates.Contains(this) && !referenceTarget.ImportedDelegates.Contains(this))
                {
                    Activity handler = this.Handler;

                    if (handler == null)
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferencedNoHandler(parent.DisplayName, referenceTarget.DisplayName, this.owner.DisplayName), false, parent));
                    }
                    else
                    {
                        ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.ActivityDelegateCannotBeReferenced(handler.DisplayName, parent.DisplayName, referenceTarget.DisplayName, this.owner.DisplayName), false, parent));
                    }

                    return(false);
                }

                // This is a valid reference so we want to allow
                // normal processing to proceed.
                return(true);
            }

            this.owner   = parent;
            this.cacheId = parent.CacheId;
            this.parentCollectionType = collectionType;
            InternalCacheMetadata();

            // We need to setup the delegate environment so that it is
            // available when we process the Handler.
            LocationReferenceEnvironment delegateEnvironment = null;

            if (collectionType == ActivityCollectionType.Implementation)
            {
                delegateEnvironment = parent.ImplementationEnvironment;
            }
            else
            {
                delegateEnvironment = parent.PublicEnvironment;
            }

            if (this.RuntimeDelegateArguments.Count > 0)
            {
                ActivityLocationReferenceEnvironment newEnvironment = new ActivityLocationReferenceEnvironment(delegateEnvironment);
                delegateEnvironment = newEnvironment;

                for (int argumentIndex = 0; argumentIndex < this.RuntimeDelegateArguments.Count; argumentIndex++)
                {
                    RuntimeDelegateArgument runtimeDelegateArgument = this.RuntimeDelegateArguments[argumentIndex];
                    DelegateArgument        delegateArgument        = runtimeDelegateArgument.BoundArgument;

                    if (delegateArgument != null)
                    {
                        if (delegateArgument.Direction != runtimeDelegateArgument.Direction)
                        {
                            ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.RuntimeDelegateArgumentDirectionIncorrect, parent));
                        }

                        if (delegateArgument.Type != runtimeDelegateArgument.Type)
                        {
                            ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.RuntimeDelegateArgumentTypeIncorrect, parent));
                        }

                        // NOTE: We don't initialize this relationship here because
                        // at runtime we'll actually just place these variables in the
                        // environment of the Handler.  We'll initialize and set an
                        // ID when we process the Handler.
                        newEnvironment.Declare(delegateArgument, this.owner, ref validationErrors);
                    }
                }
            }

            this.Environment = delegateEnvironment;

            if (this.Handler != null)
            {
                return(this.Handler.InitializeRelationship(this, collectionType, ref validationErrors));
            }

            return(true);
        }
 internal void Bind(RuntimeDelegateArgument runtimeArgument)
 {
     this.runtimeArgument = runtimeArgument;
 }
        private static void ProcessActivity(ChildActivity childActivity, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining, ActivityCallStack parentChain, ref IList <ValidationError> validationErrors, ProcessActivityTreeOptions options, ProcessActivityCallback callback)
        {
            Activity                element            = childActivity.Activity;
            IList <Constraint>      runtimeConstraints = element.RuntimeConstraints;
            IList <ValidationError> list2 = null;

            if (!element.HasStartedCachingMetadata)
            {
                element.MemberOf.AddMember(element);
                element.InternalCacheMetadata(options.CreateEmptyBindings, ref list2);
                ActivityValidationServices.ValidateArguments(element, element.Parent == null, ref list2);
                ActivityLocationReferenceEnvironment environment  = null;
                ActivityLocationReferenceEnvironment environment2 = new ActivityLocationReferenceEnvironment(element.HostEnvironment)
                {
                    InternalRoot = element
                };
                int nextEnvironmentId = 0;
                ProcessChildren(element, element.Children, ActivityCollectionType.Public, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessChildren(element, element.ImportedChildren, ActivityCollectionType.Imports, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessChildren(element, element.ImplementationChildren, ActivityCollectionType.Implementation, !options.SkipPrivateChildren, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessArguments(element, element.RuntimeArguments, true, ref environment2, ref nextEnvironmentId, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessVariables(element, element.RuntimeVariables, ActivityCollectionType.Public, true, ref environment, ref nextEnvironmentId, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessVariables(element, element.ImplementationVariables, ActivityCollectionType.Implementation, !options.SkipPrivateChildren, ref environment2, ref nextEnvironmentId, ref nextActivity, ref activitiesRemaining, ref list2);
                if (element.HandlerOf != null)
                {
                    for (int i = 0; i < element.HandlerOf.RuntimeDelegateArguments.Count; i++)
                    {
                        RuntimeDelegateArgument argument      = element.HandlerOf.RuntimeDelegateArguments[i];
                        DelegateArgument        boundArgument = argument.BoundArgument;
                        if ((boundArgument != null) && boundArgument.InitializeRelationship(element, ref list2))
                        {
                            boundArgument.Id = nextEnvironmentId;
                            nextEnvironmentId++;
                        }
                    }
                }
                if (environment == null)
                {
                    element.PublicEnvironment = new ActivityLocationReferenceEnvironment(element.GetParentEnvironment());
                }
                else
                {
                    if (environment.Parent == null)
                    {
                        environment.InternalRoot = element;
                    }
                    element.PublicEnvironment = environment;
                }
                element.ImplementationEnvironment = environment2;
                ProcessDelegates(element, element.Delegates, ActivityCollectionType.Public, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessDelegates(element, element.ImportedDelegates, ActivityCollectionType.Imports, true, ref nextActivity, ref activitiesRemaining, ref list2);
                ProcessDelegates(element, element.ImplementationDelegates, ActivityCollectionType.Implementation, !options.SkipPrivateChildren, ref nextActivity, ref activitiesRemaining, ref list2);
                if (callback != null)
                {
                    callback(childActivity, parentChain);
                }
                if (list2 != null)
                {
                    Activity activity2;
                    if (validationErrors == null)
                    {
                        validationErrors = new List <ValidationError>();
                    }
                    string str = ActivityValidationServices.GenerateValidationErrorPrefix(childActivity.Activity, parentChain, out activity2);
                    for (int j = 0; j < list2.Count; j++)
                    {
                        ValidationError item = list2[j];
                        item.Source = activity2;
                        item.Id     = activity2.Id;
                        if (!string.IsNullOrEmpty(str))
                        {
                            item.Message = str + item.Message;
                        }
                        validationErrors.Add(item);
                    }
                    list2 = null;
                }
                if (options.StoreTempViolations && (validationErrors != null))
                {
                    childActivity.Activity.SetTempValidationErrorCollection(validationErrors);
                    validationErrors = null;
                }
            }
            else
            {
                SetupForProcessing(element.Children, true, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.ImportedChildren, false, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.RuntimeArguments, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.RuntimeVariables, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.Delegates, true, ref nextActivity, ref activitiesRemaining);
                SetupForProcessing(element.ImportedDelegates, false, ref nextActivity, ref activitiesRemaining);
                if (!options.SkipPrivateChildren)
                {
                    SetupForProcessing(element.ImplementationChildren, true, ref nextActivity, ref activitiesRemaining);
                    SetupForProcessing(element.ImplementationDelegates, true, ref nextActivity, ref activitiesRemaining);
                    SetupForProcessing(element.ImplementationVariables, ref nextActivity, ref activitiesRemaining);
                }
                if ((callback != null) && !options.OnlyCallCallbackForDeclarations)
                {
                    callback(childActivity, parentChain);
                }
                if (childActivity.Activity.HasTempViolations && !options.StoreTempViolations)
                {
                    childActivity.Activity.TransferTempValidationErrors(ref validationErrors);
                }
            }
            if ((!options.SkipConstraints && parentChain.WillExecute) && (childActivity.CanBeExecuted && (runtimeConstraints.Count > 0)))
            {
                ActivityValidationServices.RunConstraints(childActivity, parentChain, runtimeConstraints, options, false, ref validationErrors);
            }
        }
 protected virtual void VisitDelegateArgument(RuntimeDelegateArgument delegateArgument, out bool exit)
 {
     //
     // Nothing further to walk into here, this is just a stub for implementors to override
     exit = false;
 }
 void OnDelegateArgument(RuntimeDelegateArgument delegateArgument)
 {
     AddMember(delegateArgument.BoundArgument.Name, delegateArgument.BoundArgument.Type, this.compiledDataContexts.Peek());
 }
            protected override void VisitDelegateArgument(RuntimeDelegateArgument delegateArgument, out bool exit)
            {
                this.compiler.OnDelegateArgument(delegateArgument);

                base.VisitDelegateArgument(delegateArgument, out exit);
            }