Exemplo n.º 1
0
 public void Declare(LocationReference locationReference, Activity owner, ref IList <ValidationError> validationErrors)
 {
     if (locationReference.Name == null)
     {
         if (this.unnamedDeclarations == null)
         {
             this.unnamedDeclarations = new List <LocationReference>();
         }
         this.unnamedDeclarations.Add(locationReference);
     }
     else if (this.Declarations.ContainsKey(locationReference.Name))
     {
         string id = null;
         if (owner != null)
         {
             id = owner.Id;
         }
         ValidationError data = new ValidationError(System.Activities.SR.SymbolNamesMustBeUnique(locationReference.Name))
         {
             Source = owner,
             Id     = id
         };
         ActivityUtilities.Add <ValidationError>(ref validationErrors, data);
     }
     else
     {
         this.Declarations.Add(locationReference.Name, locationReference);
     }
 }
 internal bool InitializeRelationship(Activity parent, ref IList <ValidationError> validationErrors)
 {
     if (this.cacheId == parent.CacheId)
     {
         if (this.Owner == parent)
         {
             ActivityUtilities.Add <ValidationError>(ref validationErrors, this.ProcessViolation(parent, System.Activities.SR.ArgumentIsAddedMoreThanOnce(base.Name, this.Owner.DisplayName)));
             return(false);
         }
         ActivityUtilities.Add <ValidationError>(ref validationErrors, this.ProcessViolation(parent, System.Activities.SR.ArgumentAlreadyInUse(base.Name, this.Owner.DisplayName, parent.DisplayName)));
         return(false);
     }
     if ((this.boundArgument != null) && (this.boundArgument.RuntimeArgument != this))
     {
         ActivityUtilities.Add <ValidationError>(ref validationErrors, this.ProcessViolation(parent, System.Activities.SR.RuntimeArgumentBindingInvalid(base.Name, this.boundArgument.RuntimeArgument.Name)));
         return(false);
     }
     this.Owner   = parent;
     this.cacheId = parent.CacheId;
     if (this.boundArgument != null)
     {
         this.boundArgument.Validate(parent, ref validationErrors);
         if (!this.BoundArgument.IsEmpty)
         {
             return(this.BoundArgument.Expression.InitializeRelationship(this, ref validationErrors));
         }
     }
     return(true);
 }
        internal bool InitializeRelationship(Activity parent, bool isPublic, ref IList <ValidationError> validationErrors)
        {
            if ((this.cacheId == parent.CacheId) && (this.Owner != null))
            {
                ValidationError data = new ValidationError(System.Activities.SR.VariableAlreadyInUseOnActivity(this.Name, parent.DisplayName, this.Owner.DisplayName), false, this.Name, parent);
                ActivityUtilities.Add <ValidationError>(ref validationErrors, data);
                return(false);
            }
            this.Owner    = parent;
            this.cacheId  = parent.CacheId;
            this.IsPublic = isPublic;
            if (this.Default == null)
            {
                return(true);
            }
            ActivityWithResult innerExpression = this.Default;

            if (innerExpression is Argument.IExpressionWrapper)
            {
                innerExpression = ((Argument.IExpressionWrapper)innerExpression).InnerExpression;
            }
            if (innerExpression.ResultType != base.Type)
            {
                ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.VariableExpressionTypeMismatch(this.Name, base.Type, innerExpression.ResultType), false, this.Name, parent));
            }
            return(this.Default.InitializeRelationship(this, isPublic, ref validationErrors));
        }
Exemplo n.º 4
0
        internal bool InitializeRelationship(Activity parent, ref IList <ValidationError> validationErrors)
        {
            if (this.cacheId == parent.CacheId)
            {
                // We're part of the same tree walk
                if (this.Owner == parent)
                {
                    ActivityUtilities.Add(ref validationErrors, this.ProcessViolation(parent, SR.ArgumentIsAddedMoreThanOnce(this.Name, this.Owner.DisplayName)));

                    // Get out early since we've already initialized this argument.
                    return(false);
                }

                Fx.Assert(this.Owner != null, "We must have already assigned an owner.");

                ActivityUtilities.Add(
                    ref validationErrors,
                    this.ProcessViolation(
                        parent,
                        SR.ArgumentAlreadyInUse(
                            this.Name,
                            this.Owner?.DisplayName,
                            parent.DisplayName)));

                // Get out early since we've already initialized this argument.
                return(false);
            }

            if (this.BoundArgument != null && this.BoundArgument.RuntimeArgument != this)
            {
                ActivityUtilities.Add(
                    ref validationErrors,
                    this.ProcessViolation(
                        parent,
                        SR.RuntimeArgumentBindingInvalid(
                            this.Name,
                            this.BoundArgument.RuntimeArgument?.Name)));

                return(false);
            }

            this.Owner   = parent;
            this.cacheId = parent.CacheId;

            if (this.BoundArgument != null)
            {
                this.BoundArgument.Validate(parent, ref validationErrors);

                if (!(this.BoundArgument?.IsEmpty ?? true))
                {
                    return(this.BoundArgument?.Expression?.InitializeRelationship(this, ref validationErrors) ?? false);
                }
            }

            return(true);
        }
 internal bool InitializeRelationship(Activity parent, ref IList <ValidationError> validationErrors)
 {
     if (this.cacheId == parent.CacheId)
     {
         ValidationError data = new ValidationError(System.Activities.SR.DelegateArgumentAlreadyInUseOnActivity(this.Name, parent.DisplayName, this.Owner.DisplayName), this.Owner);
         ActivityUtilities.Add <ValidationError>(ref validationErrors, data);
         return(false);
     }
     this.Owner   = parent;
     this.cacheId = parent.CacheId;
     return(true);
 }
Exemplo n.º 6
0
        internal bool InitializeRelationship(Activity parent, ref IList <ValidationError> validationErrors)
        {
            if (this.cacheId == parent.CacheId)
            {
                Fx.Assert(this.Owner != null, "must have an owner here");
                var validationError = new ValidationError(SR.DelegateArgumentAlreadyInUseOnActivity(this.Name, parent.DisplayName, this.Owner.DisplayName), this.Owner);
                ActivityUtilities.Add(ref validationErrors, validationError);

                // Get out early since we've already initialized this argument.
                return(false);
            }

            this.Owner   = parent;
            this.cacheId = parent.CacheId;

            return(true);
        }
Exemplo n.º 7
0
        internal void Validate(Activity owner, ref IList <ValidationError> validationErrors)
        {
            if (this.Expression != null)
            {
                if (this.Expression.Result != null && !this.Expression.Result.IsEmpty)
                {
                    ValidationError validationError = new ValidationError(SR.ResultCannotBeSetOnArgumentExpressions, false, this.RuntimeArgument.Name, owner);
                    ActivityUtilities.Add(ref validationErrors, validationError);
                }

                ActivityWithResult actualExpression = this.Expression;

                if (actualExpression is IExpressionWrapper)
                {
                    actualExpression = ((IExpressionWrapper)actualExpression).InnerExpression;
                }

                switch (this.Direction)
                {
                case ArgumentDirection.In:
                    if (actualExpression.ResultType != this.ArgumentType)
                    {
                        ActivityUtilities.Add(
                            ref validationErrors,
                            new ValidationError(SR.ArgumentValueExpressionTypeMismatch(this.ArgumentType, actualExpression.ResultType), false, this.RuntimeArgument.Name, owner));
                    }
                    break;

                case ArgumentDirection.InOut:
                case ArgumentDirection.Out:
                    Type locationType;
                    if (!ActivityUtilities.IsLocationGenericType(actualExpression.ResultType, out locationType) ||
                        locationType != this.ArgumentType)
                    {
                        Type expectedType = ActivityUtilities.CreateActivityWithResult(ActivityUtilities.CreateLocation(this.ArgumentType));
                        ActivityUtilities.Add(
                            ref validationErrors,
                            new ValidationError(SR.ArgumentLocationExpressionTypeMismatch(expectedType.FullName, actualExpression.GetType().FullName), false, this.RuntimeArgument.Name, owner));
                    }
                    break;
                }
            }
        }
Exemplo n.º 8
0
        internal bool InitializeRelationship(Activity parent, bool isPublic, ref IList <ValidationError> validationErrors)
        {
            if (this.cacheId == parent.CacheId)
            {
                if (this.Owner != null)
                {
                    ValidationError validationError = new ValidationError(SR.VariableAlreadyInUseOnActivity(this.Name, parent.DisplayName, this.Owner.DisplayName), false, this.Name, parent);
                    ActivityUtilities.Add(ref validationErrors, validationError);

                    // Get out early since we've already initialized this variable.
                    return(false);
                }
            }

            this.Owner    = parent;
            this.cacheId  = parent.CacheId;
            this.IsPublic = isPublic;

            if (this.Default != null)
            {
                ActivityWithResult expression = this.Default;

                if (expression is Argument.IExpressionWrapper)
                {
                    expression = ((Argument.IExpressionWrapper)expression).InnerExpression;
                }

                if (expression.ResultType != this.Type)
                {
                    ActivityUtilities.Add(
                        ref validationErrors,
                        new ValidationError(SR.VariableExpressionTypeMismatch(this.Name, this.Type, expression.ResultType), false, this.Name, parent));
                }

                return(this.Default.InitializeRelationship(this, isPublic, ref validationErrors));
            }

            return(true);
        }
Exemplo n.º 9
0
        internal void Validate(Activity owner, ref IList <ValidationError> validationErrors)
        {
            if (this.Expression != null)
            {
                if ((this.Expression.Result != null) && !this.Expression.Result.IsEmpty)
                {
                    ValidationError data = new ValidationError(System.Activities.SR.ResultCannotBeSetOnArgumentExpressions, false, this.RuntimeArgument.Name, owner);
                    ActivityUtilities.Add <ValidationError>(ref validationErrors, data);
                }
                ActivityWithResult expression = this.Expression;
                if (expression is IExpressionWrapper)
                {
                    expression = ((IExpressionWrapper)expression).InnerExpression;
                }
                switch (this.Direction)
                {
                case ArgumentDirection.In:
                    if (!(expression.ResultType != this.ArgumentType))
                    {
                        break;
                    }
                    ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ArgumentValueExpressionTypeMismatch(this.ArgumentType, expression.ResultType), false, this.RuntimeArgument.Name, owner));
                    return;

                case ArgumentDirection.Out:
                case ArgumentDirection.InOut:
                    Type type;
                    if (!ActivityUtilities.IsLocationGenericType(expression.ResultType, out type) || (type != this.ArgumentType))
                    {
                        Type type2 = ActivityUtilities.CreateActivityWithResult(ActivityUtilities.CreateLocation(this.ArgumentType));
                        ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.ArgumentLocationExpressionTypeMismatch(type2.FullName, expression.GetType().FullName), false, this.RuntimeArgument.Name, owner));
                    }
                    break;

                default:
                    return;
                }
            }
        }
Exemplo n.º 10
0
        public void Declare(LocationReference locationReference, Activity owner, ref IList <ValidationError> validationErrors)
        {
            Fx.Assert(locationReference != null, "Must not be null");

            if (locationReference.Name == null)
            {
                if (this.unnamedDeclarations == null)
                {
                    this.unnamedDeclarations = new List <LocationReference>();
                }

                this.unnamedDeclarations.Add(locationReference);
            }
            else
            {
                if (this.Declarations.ContainsKey(locationReference.Name))
                {
                    string id = null;

                    if (owner != null)
                    {
                        id = owner.Id;
                    }

                    ValidationError validationError = new ValidationError(SR.SymbolNamesMustBeUnique(locationReference.Name))
                    {
                        Source = owner,
                        Id     = id
                    };

                    ActivityUtilities.Add(ref validationErrors, validationError);
                }
                else
                {
                    this.Declarations.Add(locationReference.Name, locationReference);
                }
            }
        }
        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);
        }
Exemplo n.º 12
0
        /// <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));
        }