Пример #1
0
        /// <summary>
        ///     Evaluates the expressions.
        /// </summary>
        /// <param name="contextEntity">The context entity.</param>
        /// <param name="expressions">The expressions.</param>
        /// <returns></returns>
        private Dictionary <string, EvaluateResult> EvaluateExpressionsInternal(IEntity contextEntity, IDictionary <string, CalcEngineExpression> expressions)
        {
            var results = new Dictionary <string, EvaluateResult>();

            var contextEntityTypeId = new EntityRef(contextEntity.TypeIds.FirstOrDefault());

            foreach (var item in expressions)
            {
                string key = item.Key;

                try
                {
                    CalcEngineExpression expression = item.Value;

                    IExpression compiledExpression = CompileExpression(contextEntityTypeId, expression);
                    string      value = RunExpression(compiledExpression, contextEntity);

                    results[key] = new EvaluateResult
                    {
                        Value = value,
                        CompiledExpression = compiledExpression
                    };
                }
                catch (Exception ex)
                {
                    results[key] = new EvaluateResult
                    {
                        Error = ex.ToString()
                    };
                }
            }

            return(results);
        }
Пример #2
0
        /// <summary>
        ///     Compiles the expression.
        /// </summary>
        /// <param name="contextEntityTypeId">The context entity type identifier.</param>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        private IExpression CompileExpression(EntityRef contextEntityTypeId, CalcEngineExpression expression)
        {
            var builderSettings = new BuilderSettings
            {
                RootContextType = ExprTypeHelper.EntityOfType(contextEntityTypeId),
                ScriptHost      = ScriptHostType.Any
            };

            return(Factory.ExpressionCompiler.Compile(expression.Expression, builderSettings));
        }