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); }
/// <summary> /// Initializes the relationship. /// </summary> /// <param name="parent">The parent.</param> /// <param name="collectionType">Type of the collection.</param> /// <param name="validationErrors">The validation errors.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> 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. var referenceTarget = parent.MemberOf.Owner; if (referenceTarget == null) { var 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)) { var 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; this.InternalCacheMetadata(); // We need to setup the delegate environment so that it is available when we process the Handler. var delegateEnvironment = collectionType == ActivityCollectionType.Implementation ? parent.ImplementationEnvironment : parent.PublicEnvironment; if (this.RuntimeDelegateArguments.Count > 0) { var newEnvironment = new ActivityLocationReferenceEnvironment(delegateEnvironment); delegateEnvironment = newEnvironment; for (var argumentIndex = 0; argumentIndex < this.RuntimeDelegateArguments.Count; argumentIndex++) { var runtimeDelegateArgument = this.RuntimeDelegateArguments[argumentIndex]; var 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; return(this.Handler == null ? true : this.Handler.InitializeRelationship(this, collectionType, ref validationErrors)); }
private static void ProcessDelegates(Activity parent, IList <ActivityDelegate> delegates, ActivityCollectionType collectionType, bool addChildren, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining, ref IList <ValidationError> validationErrors) { for (int i = 0; i < delegates.Count; i++) { ActivityDelegate activityDelegate = delegates[i]; if (activityDelegate.InitializeRelationship(parent, collectionType, ref validationErrors) && addChildren) { SetupForProcessing(activityDelegate, collectionType != ActivityCollectionType.Imports, ref nextActivity, ref activitiesRemaining); } } }
private static void ProcessVariables(Activity parent, IList <Variable> variables, ActivityCollectionType collectionType, bool addChildren, ref ActivityLocationReferenceEnvironment environment, ref int nextEnvironmentId, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining, ref IList <ValidationError> validationErrors) { if (variables.Count > 0) { if (environment == null) { environment = new ActivityLocationReferenceEnvironment(parent.GetParentEnvironment()); } for (int i = 0; i < variables.Count; i++) { Variable locationReference = variables[i]; if (locationReference.InitializeRelationship(parent, collectionType == ActivityCollectionType.Public, ref validationErrors)) { locationReference.Id = nextEnvironmentId; nextEnvironmentId++; environment.Declare(locationReference, locationReference.Owner, ref validationErrors); if (addChildren) { SetupForProcessing(locationReference, ref nextActivity, ref activitiesRemaining); } } } } }
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; }