public override bool IsVisible(LocationReference locationReference) { if (locationReference == null) { throw FxTrace.Exception.ArgumentNull("locationReference"); } LocationReferenceEnvironment currentScope = this; while (currentScope != null) { ActivityLocationReferenceEnvironment activityEnvironment = currentScope as ActivityLocationReferenceEnvironment; if (activityEnvironment != null) { if (activityEnvironment.declarations != null) { foreach (LocationReference declaration in activityEnvironment.declarations.Values) { if (locationReference == declaration) { return(true); } } } if (activityEnvironment.unnamedDeclarations != null) { for (int i = 0; i < activityEnvironment.unnamedDeclarations.Count; i++) { if (locationReference == activityEnvironment.unnamedDeclarations[i]) { return(true); } } } } else { return(currentScope.IsVisible(locationReference)); } currentScope = currentScope.Parent; } return(false); }
public static void CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment) { if (rootActivity == null) { throw FxTrace.Exception.ArgumentNull("rootActivity"); } if (rootActivity.HasBeenAssociatedWithAnInstance) { throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.RootActivityAlreadyAssociatedWithInstance(rootActivity.DisplayName))); } IList<ValidationError> validationErrors = null; if (hostEnvironment == null) { hostEnvironment = new ActivityLocationReferenceEnvironment(); } ActivityUtilities.CacheRootMetadata(rootActivity, hostEnvironment, ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors); ActivityValidationServices.ThrowIfViolationsExist(validationErrors); }
public static void CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment) { if (rootActivity == null) { throw FxTrace.Exception.ArgumentNull("rootActivity"); } if (rootActivity.HasBeenAssociatedWithAnInstance) { throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.RootActivityAlreadyAssociatedWithInstance(rootActivity.DisplayName))); } IList <ValidationError> validationErrors = null; if (hostEnvironment == null) { hostEnvironment = new ActivityLocationReferenceEnvironment(); } ActivityUtilities.CacheRootMetadata(rootActivity, hostEnvironment, ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors); ActivityValidationServices.ThrowIfViolationsExist(validationErrors); }
public override bool TryGetLocationReference(string name, out LocationReference result) { if (name == null) { LocationReferenceEnvironment parent = base.Parent; while (parent is ActivityLocationReferenceEnvironment) { parent = parent.Parent; } if (parent != null) { return(parent.TryGetLocationReference(name, out result)); } } else { if ((this.declarations != null) && this.declarations.TryGetValue(name, out result)) { return(true); } bool flag = false; LocationReferenceEnvironment environment2 = base.Parent; while ((environment2 != null) && (environment2 is ActivityLocationReferenceEnvironment)) { ActivityLocationReferenceEnvironment environment3 = (ActivityLocationReferenceEnvironment)environment2; if ((environment3.declarations != null) && environment3.declarations.TryGetValue(name, out result)) { return(true); } environment2 = environment2.Parent; } if ((!flag && (environment2 != null)) && environment2.TryGetLocationReference(name, out result)) { return(true); } } result = null; return(false); }
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); } } } } }
private static void ProcessArguments(Activity parent, IList <RuntimeArgument> arguments, bool addChildren, ref ActivityLocationReferenceEnvironment environment, ref int nextEnvironmentId, ref ChildActivity nextActivity, ref Stack <ChildActivity> activitiesRemaining, ref IList <ValidationError> validationErrors) { if (arguments.Count > 0) { if (environment == null) { environment = new ActivityLocationReferenceEnvironment(parent.GetParentEnvironment()); } for (int i = 0; i < arguments.Count; i++) { RuntimeArgument locationReference = arguments[i]; if (locationReference.InitializeRelationship(parent, ref validationErrors)) { locationReference.Id = nextEnvironmentId; nextEnvironmentId++; environment.Declare(locationReference, locationReference.Owner, ref validationErrors); if (addChildren) { SetupForProcessing(locationReference, ref nextActivity, ref activitiesRemaining); } } } } }
public override bool IsVisible(LocationReference locationReference) { if (locationReference == null) { throw FxTrace.Exception.ArgumentNull("locationReference"); } for (LocationReferenceEnvironment environment = this; environment != null; environment = environment.Parent) { ActivityLocationReferenceEnvironment environment2 = environment as ActivityLocationReferenceEnvironment; if (environment2 == null) { return(environment.IsVisible(locationReference)); } if (environment2.declarations != null) { foreach (LocationReference reference in environment2.declarations.Values) { if (locationReference == reference) { return(true); } } } if (environment2.unnamedDeclarations != null) { for (int i = 0; i < environment2.unnamedDeclarations.Count; i++) { if (locationReference == environment2.unnamedDeclarations[i]) { return(true); } } } } return(false); }
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)); }
public override bool TryGetLocationReference(string name, out LocationReference result) { if (name == null) { // We don't allow null names in our LocationReferenceEnvironment but // a custom declared environment might. We need to walk up // to the root and see if it chains to a // non-ActivityLocationReferenceEnvironment implementation LocationReferenceEnvironment currentEnvironment = this.Parent; while (currentEnvironment is ActivityLocationReferenceEnvironment) { currentEnvironment = currentEnvironment.Parent; } if (currentEnvironment != null) { Fx.Assert(!(currentEnvironment is ActivityLocationReferenceEnvironment), "We must be at a non-ActivityLocationReferenceEnvironment implementation."); return(currentEnvironment.TryGetLocationReference(name, out result)); } } else { if (this.declarations != null && this.declarations.TryGetValue(name, out result)) { return(true); } bool found = false; LocationReferenceEnvironment currentEnvironment = this.Parent; LocationReferenceEnvironment rootEnvironment = this; // Loop through all of the ActivityLocationReferenceEnvironments we have chained together while (currentEnvironment != null && currentEnvironment is ActivityLocationReferenceEnvironment) { ActivityLocationReferenceEnvironment activityEnvironment = (ActivityLocationReferenceEnvironment)currentEnvironment; if (activityEnvironment.declarations != null && activityEnvironment.declarations.TryGetValue(name, out result)) { return(true); } rootEnvironment = currentEnvironment; currentEnvironment = currentEnvironment.Parent; } if (!found) { if (currentEnvironment != null) { // Looks like we have a non-ActivityLocationReferenceEnvironment at the root Fx.Assert(!(currentEnvironment is ActivityLocationReferenceEnvironment), "We should have some other host environment at this point."); if (currentEnvironment.TryGetLocationReference(name, out result)) { return(true); } } } } result = null; return(false); }
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); } }
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; }