public static Activity RecompileVisualBasicReference(ActivityWithResult visualBasicReference,
            out Type returnType,
            out SourceExpressionException compileError,
            out VisualBasicSettings vbSettings)
        {
            ITextExpression textExpression = visualBasicReference as ITextExpression;
            if (textExpression == null || textExpression.Language != VisualBasicHelper.Language)
            {
                // the argument must be of type VisualBasicReference<>
                throw FxTrace.Exception.AsError(new ArgumentException());
            }
            string expressionText = textExpression.ExpressionText;
            LocationReferenceEnvironment environment = visualBasicReference.GetParentEnvironment();

            IList<string> namespaces;
            IList<string> referencedAssemblies;
            GetAllImportReferences(visualBasicReference, out namespaces, out referencedAssemblies);

            return CreatePrecompiledVisualBasicReference(
                null,
                expressionText,
                namespaces,
                referencedAssemblies,
                environment,
                out returnType,
                out compileError,
                out vbSettings);
        }
        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));
        }
Beispiel #3
0
        public Activity RecompileReference(ActivityWithResult lValue, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
        {
            ITextExpression textExpression = lValue as ITextExpression;

            if (textExpression == null || textExpression.Language != Language)
            {
                throw FxTrace.Exception.AsError(new ArgumentException());
            }
            string expressionText = textExpression.ExpressionText;
            LocationReferenceEnvironment environment = lValue.GetParentEnvironment();

            List <string> namespaces;
            List <string> referencedAssemblies;

            GetAllImportReferences(lValue, out namespaces, out referencedAssemblies);

            return(CreatePrecompiledReference(
                       null,
                       expressionText,
                       namespaces,
                       referencedAssemblies,
                       environment,
                       out returnType,
                       out compileError,
                       out vbSettings));
        }
        void AddGeneratedArgument(Type argumentType, ArgumentDirection direction, ActivityWithResult expression)
        {
            Argument argument = ActivityUtilities.CreateArgument(argumentType, direction);

            argument.Expression = expression;
            RuntimeArgument runtimeArgument = this.metadata.CurrentActivity.AddTempAutoGeneratedArgument(argumentType, direction);

            Argument.TryBind(argument, runtimeArgument, this.metadata.CurrentActivity);
        }
        static void AssertIsCodeActivity(Activity activity)
        {
            Type codeActivityOfTType = null;
            ActivityWithResult activityWithResult = activity as ActivityWithResult;

            if (activityWithResult != null)
            {
                codeActivityOfTType = typeof(CodeActivity <>).MakeGenericType(activityWithResult.ResultType);
            }
            Fx.Assert(activity is CodeActivity || (codeActivityOfTType != null && codeActivityOfTType.IsAssignableFrom(activity.GetType())), "Expected CodeActivity or CodeActivity<T>");
        }
Beispiel #6
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;
                }
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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;
                }
            }
        }
        internal void CreateLocationArgument(LocationReference sourceReference, bool useLocationReferenceValue = false)
        {
            ActivityWithResult expression = ActivityUtilities.CreateLocationAccessExpression(sourceReference, true, useLocationReferenceValue);

            AddGeneratedArgument(expression.ResultType, ArgumentDirection.In, expression);
        }
Beispiel #10
0
 public ActivityWithResultWrapper(ActivityWithResult expression)
 {
     this.expression = expression;
 }
 void AddGeneratedArgument(Type argumentType, ArgumentDirection direction, ActivityWithResult expression)
 {
     Argument argument = ActivityUtilities.CreateArgument(argumentType, direction);
     argument.Expression = expression;
     RuntimeArgument runtimeArgument = this.metadata.CurrentActivity.AddTempAutoGeneratedArgument(argumentType, direction);
     Argument.TryBind(argument, runtimeArgument, this.metadata.CurrentActivity);
 }
 public static Activity RecompileVisualBasicValue(ActivityWithResult visualBasicValue, out Type returnType, out SourceExpressionException compileError, out VisualBasicSettings vbSettings)
 {
     IVisualBasicExpression expression = visualBasicValue as IVisualBasicExpression;
     if (expression == null)
     {
         throw FxTrace.Exception.AsError(new ArgumentException());
     }
     string expressionText = expression.ExpressionText;
     LocationReferenceEnvironment parentEnvironment = visualBasicValue.GetParentEnvironment();
     HashSet<VisualBasicImportReference> allImportReferences = VisualBasicHelper.GetAllImportReferences((parentEnvironment != null) ? parentEnvironment.Root : null);
     HashSet<string> namespaces = new HashSet<string>();
     HashSet<string> referencedAssemblies = new HashSet<string>();
     foreach (VisualBasicImportReference reference in allImportReferences)
     {
         namespaces.Add(reference.Import);
         referencedAssemblies.Add(reference.Assembly);
     }
     return CreatePrecompiledVisualBasicValue(null, expressionText, namespaces, referencedAssemblies, parentEnvironment, out returnType, out compileError, out vbSettings);
 }