public void SetValidationErrorsCollection(Collection <ValidationError> validationErrors)
 {
     this.ThrowIfDisposed();
     ActivityUtilities.RemoveNulls(validationErrors);
     this.activity.SetTempValidationErrorCollection(validationErrors);
 }
 public void SetImportedDelegatesCollection(Collection <ActivityDelegate> importedDelegates)
 {
     this.ThrowIfDisposed();
     ActivityUtilities.RemoveNulls(importedDelegates);
     this.activity.SetImportedDelegatesCollection(importedDelegates);
 }
 public void SetVariablesCollection(Collection <Variable> variables)
 {
     this.ThrowIfDisposed();
     ActivityUtilities.RemoveNulls(variables);
     this.activity.SetVariablesCollection(variables);
 }
 public void SetArgumentsCollection(Collection <RuntimeArgument> arguments)
 {
     this.ThrowIfDisposed();
     ActivityUtilities.RemoveNulls(arguments);
     this.activity.SetArgumentsCollection(arguments, this.createEmptyBindings);
 }
 public void SetImportedChildrenCollection(Collection <Activity> importedChildren)
 {
     this.ThrowIfDisposed();
     ActivityUtilities.RemoveNulls(importedChildren);
     this.activity.SetImportedChildrenCollection(importedChildren);
 }
 public Variable()
 {
     base.IsHandle = ActivityUtilities.IsHandle(typeof(T));
 }
Пример #7
0
        internal void SetupBinding(Activity owningElement, bool createEmptyBinding)
        {
            if (this.bindingProperty != null)
            {
                Argument argument = (Argument)this.bindingProperty.GetValue(this.bindingPropertyOwner);

                if (argument == null)
                {
                    Fx.Assert(this.bindingProperty.PropertyType.IsGenericType, "We only support arguments that are generic types in our reflection walk.");

                    argument = (Argument)Activator.CreateInstance(this.bindingProperty.PropertyType);
                    argument.WasDesignTimeNull = true;

                    if (createEmptyBinding && !this.bindingProperty.IsReadOnly)
                    {
                        this.bindingProperty.SetValue(this.bindingPropertyOwner, argument);
                    }
                }

                Argument.Bind(argument, this);
            }
            else if (!this.IsBound)
            {
                PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(owningElement);

                PropertyDescriptor targetProperty = null;

                for (int i = 0; i < properties.Count; i++)
                {
                    PropertyDescriptor property = properties[i];

                    // We only support auto-setting the property
                    // for generic types.  Otherwise we have no
                    // guarantee that the argument returned by the
                    // property still matches the runtime argument's
                    // type.
                    if (property.Name == this.Name && property.PropertyType.IsGenericType)
                    {
                        if (ActivityUtilities.TryGetArgumentDirectionAndType(property.PropertyType, out ArgumentDirection direction, out Type argumentType))
                        {
                            if (this.Type == argumentType && this.Direction == direction)
                            {
                                targetProperty = property;
                                break;
                            }
                        }
                    }
                }

                Argument argument = null;

                if (targetProperty != null)
                {
                    argument = (Argument)targetProperty.GetValue(owningElement);
                }

                if (argument == null)
                {
                    if (targetProperty != null)
                    {
                        if (targetProperty.PropertyType.IsGenericType)
                        {
                            argument = (Argument)Activator.CreateInstance(targetProperty.PropertyType);
                        }
                        else
                        {
                            argument = ActivityUtilities.CreateArgument(this.Type, this.Direction);
                        }
                    }
                    else
                    {
                        argument = ActivityUtilities.CreateArgument(this.Type, this.Direction);
                    }

                    argument.WasDesignTimeNull = true;

                    if (targetProperty != null && createEmptyBinding && !targetProperty.IsReadOnly)
                    {
                        targetProperty.SetValue(owningElement, argument);
                    }
                }

                Argument.Bind(argument, this);
            }

            Fx.Assert(this.IsBound, "We should always be bound when exiting this method.");
        }
Пример #8
0
 public static Argument Create(Type type, ArgumentDirection direction)
 {
     return(ActivityUtilities.CreateArgument(type, direction));
 }
Пример #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 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;
                }
            }
        }
        public static IEnumerable <Activity> GetActivities(Activity activity)
        {
            if (activity == null)
            {
                throw FxTrace.Exception.ArgumentNull("activity");
            }

            if (!activity.IsMetadataCached)
            {
                IList <ValidationError> validationErrors = null;

                ActivityUtilities.CacheRootMetadata(activity, new ActivityLocationReferenceEnvironment(), ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors);

                ActivityValidationServices.ThrowIfViolationsExist(validationErrors);
            }

            int i = 0;

            for (; i < activity.RuntimeArguments.Count; i++)
            {
                RuntimeArgument argument = activity.RuntimeArguments[i];

                if (argument.BoundArgument != null && argument.BoundArgument.Expression != null)
                {
                    yield return(argument.BoundArgument.Expression);
                }
            }

            for (i = 0; i < activity.RuntimeVariables.Count; i++)
            {
                Variable variable = activity.RuntimeVariables[i];

                if (variable.Default != null)
                {
                    yield return(variable.Default);
                }
            }

            for (i = 0; i < activity.ImplementationVariables.Count; i++)
            {
                Variable variable = activity.ImplementationVariables[i];

                if (variable.Default != null)
                {
                    yield return(variable.Default);
                }
            }

            for (i = 0; i < activity.Children.Count; i++)
            {
                yield return(activity.Children[i]);
            }

            for (i = 0; i < activity.ImportedChildren.Count; i++)
            {
                yield return(activity.ImportedChildren[i]);
            }

            for (i = 0; i < activity.ImplementationChildren.Count; i++)
            {
                yield return(activity.ImplementationChildren[i]);
            }

            for (i = 0; i < activity.Delegates.Count; i++)
            {
                ActivityDelegate activityDelegate = activity.Delegates[i];

                if (activityDelegate.Handler != null)
                {
                    yield return(activityDelegate.Handler);
                }
            }

            for (i = 0; i < activity.ImportedDelegates.Count; i++)
            {
                ActivityDelegate activityDelegate = activity.ImportedDelegates[i];

                if (activityDelegate.Handler != null)
                {
                    yield return(activityDelegate.Handler);
                }
            }

            for (i = 0; i < activity.ImplementationDelegates.Count; i++)
            {
                ActivityDelegate activityDelegate = activity.ImplementationDelegates[i];

                if (activityDelegate.Handler != null)
                {
                    yield return(activityDelegate.Handler);
                }
            }
        }
Пример #11
0
 public override void TraceStarting()
 {
     if (TD.StartBookmarkWorkItemIsEnabled())
     {
         TD.StartBookmarkWorkItem(this.ActivityInstance.Activity.GetType().ToString(), this.ActivityInstance.Activity.DisplayName, this.ActivityInstance.Id, ActivityUtilities.GetTraceString(Bookmark.AsyncOperationCompletionBookmark), ActivityUtilities.GetTraceString(Bookmark.AsyncOperationCompletionBookmark.Scope));
     }
 }
 internal void SetupBinding(Activity owningElement, bool createEmptyBinding)
 {
     if (this.bindingProperty != null)
     {
         Argument argument = (Argument)this.bindingProperty.GetValue(this.bindingPropertyOwner);
         if (argument == null)
         {
             argument = (Argument)Activator.CreateInstance(this.bindingProperty.PropertyType);
             argument.WasDesignTimeNull = true;
             if (createEmptyBinding && !this.bindingProperty.IsReadOnly)
             {
                 this.bindingProperty.SetValue(this.bindingPropertyOwner, argument);
             }
         }
         Argument.Bind(argument, this);
     }
     else if (!this.IsBound)
     {
         PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(owningElement);
         PropertyDescriptor           descriptor = null;
         for (int i = 0; i < properties.Count; i++)
         {
             ArgumentDirection direction;
             Type type;
             PropertyDescriptor descriptor2 = properties[i];
             if ((((descriptor2.Name == base.Name) && descriptor2.PropertyType.IsGenericType) && (ActivityUtilities.TryGetArgumentDirectionAndType(descriptor2.PropertyType, out direction, out type) && (base.Type == type))) && (this.Direction == direction))
             {
                 descriptor = descriptor2;
                 break;
             }
         }
         Argument argument2 = null;
         if (descriptor != null)
         {
             argument2 = (Argument)descriptor.GetValue(owningElement);
         }
         if (argument2 == null)
         {
             if (descriptor != null)
             {
                 if (descriptor.PropertyType.IsGenericType)
                 {
                     argument2 = (Argument)Activator.CreateInstance(descriptor.PropertyType);
                 }
                 else
                 {
                     argument2 = ActivityUtilities.CreateArgument(base.Type, this.Direction);
                 }
             }
             else
             {
                 argument2 = ActivityUtilities.CreateArgument(base.Type, this.Direction);
             }
             argument2.WasDesignTimeNull = true;
             if (((descriptor != null) && createEmptyBinding) && !descriptor.IsReadOnly)
             {
                 descriptor.SetValue(owningElement, argument2);
             }
         }
         Argument.Bind(argument2, this);
     }
 }
 public static Variable Create(string name, Type type, VariableModifiers modifiers)
 {
     return(ActivityUtilities.CreateVariable(name, type, modifiers));
 }
Пример #14
0
        public static IEnumerable <Activity> GetActivities(Activity activity)
        {
            int iteratorVariable0;

            if (activity == null)
            {
                throw FxTrace.Exception.ArgumentNull("activity");
            }
            if (!activity.IsMetadataCached)
            {
                IList <ValidationError> validationErrors = null;
                ActivityUtilities.CacheRootMetadata(activity, new ActivityLocationReferenceEnvironment(), ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors);
                ActivityValidationServices.ThrowIfViolationsExist(validationErrors);
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.RuntimeArguments.Count; iteratorVariable0++)
            {
                RuntimeArgument iteratorVariable1 = activity.RuntimeArguments[iteratorVariable0];
                if ((iteratorVariable1.BoundArgument != null) && (iteratorVariable1.BoundArgument.Expression != null))
                {
                    yield return(iteratorVariable1.BoundArgument.Expression);
                }
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.RuntimeVariables.Count; iteratorVariable0++)
            {
                Variable iteratorVariable2 = activity.RuntimeVariables[iteratorVariable0];
                if (iteratorVariable2.Default != null)
                {
                    yield return(iteratorVariable2.Default);
                }
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.ImplementationVariables.Count; iteratorVariable0++)
            {
                Variable iteratorVariable3 = activity.ImplementationVariables[iteratorVariable0];
                if (iteratorVariable3.Default != null)
                {
                    yield return(iteratorVariable3.Default);
                }
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.Children.Count; iteratorVariable0++)
            {
                yield return(activity.Children[iteratorVariable0]);
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.ImportedChildren.Count; iteratorVariable0++)
            {
                yield return(activity.ImportedChildren[iteratorVariable0]);
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.ImplementationChildren.Count; iteratorVariable0++)
            {
                yield return(activity.ImplementationChildren[iteratorVariable0]);
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.Delegates.Count; iteratorVariable0++)
            {
                ActivityDelegate iteratorVariable4 = activity.Delegates[iteratorVariable0];
                if (iteratorVariable4.Handler != null)
                {
                    yield return(iteratorVariable4.Handler);
                }
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.ImportedDelegates.Count; iteratorVariable0++)
            {
                ActivityDelegate iteratorVariable5 = activity.ImportedDelegates[iteratorVariable0];
                if (iteratorVariable5.Handler != null)
                {
                    yield return(iteratorVariable5.Handler);
                }
            }
            for (iteratorVariable0 = 0; iteratorVariable0 < activity.ImplementationDelegates.Count; iteratorVariable0++)
            {
                ActivityDelegate iteratorVariable6 = activity.ImplementationDelegates[iteratorVariable0];
                if (iteratorVariable6.Handler != null)
                {
                    yield return(iteratorVariable6.Handler);
                }
            }
        }
        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);
        }
 public void SetImplementationVariablesCollection(Collection <Variable> implementationVariables)
 {
     this.ThrowIfDisposed();
     ActivityUtilities.RemoveNulls(implementationVariables);
     this.activity.SetImplementationVariablesCollection(implementationVariables);
 }