public CompiledExpressionInvoker(ITextExpression expression, bool isReference, CodeActivityMetadata metadata)
        {
            if (expression == null)
            {
                throw FxTrace.Exception.ArgumentNull("expression");
            }

            if (metadata == null)
            {
                throw FxTrace.Exception.ArgumentNull("metadata");
            }

            this.expressionId = -1;
            this.textExpression = expression;
            this.expressionActivity = expression as Activity;
            this.isReference = isReference;
            this.locationReferences = new List<LocationReference>();
            this.metadata = metadata;
            this.accessor = CodeActivityPublicEnvironmentAccessor.Create(this.metadata);

            if (this.expressionActivity == null)
            {
                throw FxTrace.Exception.Argument("expression", SR.ITextExpressionParameterMustBeActivity);
            }

            ActivityWithResult resultActivity = this.expressionActivity as ActivityWithResult;

            this.metadataRoot = metadata.Environment.Root;

            this.ProcessLocationReferences();
        }
Пример #2
0
        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
            CodeActivityPublicEnvironmentAccessor publicAccessor = CodeActivityPublicEnvironmentAccessor.Create(metadata);

            // We need to rewrite the tree.
            Expression newTree;

            if (ExpressionUtilities.TryRewriteLambdaExpression(_lambdaValue, out newTree, publicAccessor))
            {
                _rewrittenTree = (Expression <Func <ActivityContext, TResult> >)newTree;
            }
            else
            {
                _rewrittenTree = _lambdaValue;
            }
        }
Пример #3
0
        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
            expressionTree = null;
            invoker        = new CompiledExpressionInvoker(this, true, metadata);
            if (metadata.Environment.CompileExpressions)
            {
                return;
            }
            string validationError;
            // If ICER is not implemented that means we haven't been compiled
            var publicAccessor = CodeActivityPublicEnvironmentAccessor.Create(metadata);

            expressionTree = CompileLocationExpression(publicAccessor, out validationError);
            if (validationError != null)
            {
                metadata.AddValidationError(validationError);
            }
        }
Пример #4
0
        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
            expressionTree = null;
            invoker        = new CompiledExpressionInvoker(this, false, metadata);
            if (metadata.Environment.CompileExpressions)
            {
                return;
            }
            // If ICER is not implemented that means we haven't been compiled
            var publicAccessor = CodeActivityPublicEnvironmentAccessor.Create(metadata);

            try
            {
                expressionTree = VisualBasicHelper.Compile <TResult>(this.ExpressionText, publicAccessor, false);
            }
            catch (SourceExpressionException e)
            {
                metadata.AddValidationError(e.Message);
            }
        }
        public CompiledExpressionInvoker(ITextExpression expression, bool isReference, CodeActivityMetadata metadata)
        {
            this.expressionId       = -1;
            this.textExpression     = expression ?? throw FxTrace.Exception.ArgumentNull(nameof(expression));
            this.expressionActivity = expression as Activity;
            this.isReference        = isReference;
            this.locationReferences = new List <LocationReference>();
            this.metadata           = metadata;
            this.accessor           = CodeActivityPublicEnvironmentAccessor.Create(this.metadata);

            if (this.expressionActivity == null)
            {
                throw FxTrace.Exception.Argument(nameof(expression), SR.ITextExpressionParameterMustBeActivity);
            }

            ActivityWithResult resultActivity = this.expressionActivity as ActivityWithResult;

            this.metadataRoot = metadata.Environment.Root;

            this.ProcessLocationReferences();
        }
        public static Expression <Func <ActivityContext, T> > Compile <T>(string expressionText, CodeActivityPublicEnvironmentAccessor publicAccessor, bool isLocationExpression)
        {
            List <string>            localNamespaces;
            List <AssemblyReference> localAssemblies;

            GetAllImportReferences(publicAccessor.ActivityMetadata.CurrentActivity, false, out localNamespaces, out localAssemblies);
            var helper = new VisualBasicHelper(expressionText);
            HashSet <AssemblyName> localReferenceAssemblies = new HashSet <AssemblyName>();
            HashSet <string>       localImports             = new HashSet <string>(localNamespaces);

            foreach (AssemblyReference assemblyReference in localAssemblies)
            {
                if (assemblyReference.Assembly != null)
                {
                    // directly add the Assembly to the list
                    // so that we don't have to go through
                    // the assembly resolution process
                    if (helper.referencedAssemblies == null)
                    {
                        helper.referencedAssemblies = new HashSet <Assembly>();
                    }
                    helper.referencedAssemblies.Add(assemblyReference.Assembly);
                }
                else if (assemblyReference.AssemblyName != null)
                {
                    localReferenceAssemblies.Add(assemblyReference.AssemblyName);
                }
            }
            helper.Initialize(localReferenceAssemblies, localImports);
            return(helper.Compile <T>(publicAccessor, isLocationExpression));
        }
Пример #7
0
        private Expression <Func <ActivityContext, TResult> > CompileLocationExpression(CodeActivityPublicEnvironmentAccessor publicAccessor, out string validationError)
        {
            Expression <Func <ActivityContext, TResult> > expressionTreeToReturn = null;

            validationError = null;
            try
            {
                expressionTreeToReturn = VisualBasicHelper.Compile <TResult>(this.ExpressionText, publicAccessor, true);
                // inspect the expressionTree to see if it is a valid location expression(L-value)
                string extraErrorMessage = null;
                if (!publicAccessor.ActivityMetadata.HasViolations && (expressionTreeToReturn == null || !ExpressionUtilities.IsLocation(expressionTreeToReturn, typeof(TResult), out extraErrorMessage)))
                {
                    string errorMessage = SR.InvalidLValueExpression;

                    if (extraErrorMessage != null)
                    {
                        errorMessage += ":" + extraErrorMessage;
                    }
                    expressionTreeToReturn = null;
                    validationError        = SR.CompilerErrorSpecificExpression(this.ExpressionText, errorMessage);
                }
            }
            catch (SourceExpressionException e)
            {
                validationError = e.Message;
            }

            return(expressionTreeToReturn);
        }