コード例 #1
0
        private PropertyDescriptorCollection CreateProperties()
        {
            // The name in child Activity will shadow the name in parent.
            Dictionary <string, object> names = new Dictionary <string, object>();

            List <PropertyDescriptorImpl> propertyList = new List <PropertyDescriptorImpl>();

            LocationReferenceEnvironment environment = this.activityInstance.Activity.PublicEnvironment;
            bool isLocalEnvironment = true;

            while (environment != null)
            {
                foreach (LocationReference locRef in environment.GetLocationReferences())
                {
                    if (this.IncludesLocalVariables || !isLocalEnvironment || !(locRef is Variable))
                    {
                        AddProperty(locRef, names, propertyList);
                    }
                }

                environment        = environment.Parent;
                isLocalEnvironment = false;
            }

            return(new PropertyDescriptorCollection(propertyList.ToArray(), true));
        }
コード例 #2
0
        public ActivityLocationReferenceEnvironment(LocationReferenceEnvironment parent)
        {
            this.Parent = parent;

            if (this.Parent != null)
            {
                this.InternalRoot = parent.Root;
            }
        }
コード例 #3
0
        public override bool IsVisible(LocationReference locationReference)
        {
            if (locationReference == null)
            {
                throw CoreWf.Internals.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);
        }
コード例 #4
0
        public static void CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment)
        {
            if (rootActivity == null)
            {
                throw CoreWf.Internals.FxTrace.Exception.ArgumentNull("rootActivity");
            }

            if (rootActivity.HasBeenAssociatedWithAnInstance)
            {
                throw CoreWf.Internals.FxTrace.Exception.AsError(new InvalidOperationException(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);
        }
コード例 #5
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);
        }
コード例 #6
0
 internal CodeActivityMetadata(Activity activity, LocationReferenceEnvironment environment, bool createEmptyBindings)
 {
     _activity            = activity;
     _environment         = environment;
     _createEmptyBindings = createEmptyBindings;
 }
コード例 #7
0
        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 (_declarations != null && _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);
        }
コード例 #8
0
 internal ActivityMetadata(Activity activity, LocationReferenceEnvironment environment, bool createEmptyBindings)
 {
     this.activity            = activity;
     this.environment         = environment;
     this.createEmptyBindings = createEmptyBindings;
 }