Пример #1
0
        // Just recalc Name.
        private void RecalcWorker2(string name)
        {
            if (_calcs.ContainsKey(name))
            {
                return; // already computed.
            }

            var fi = _parent.Formulas[name];

            // Now calculate this node. Will recalc any dependencies if needed.
            if (fi._binding != null)
            {
                var binding = fi._binding;

                (IntermediateNode irnode, ScopeSymbol ruleScopeSymbol) = IRTranslator.Translate(binding);

                var scope = this;
                var v     = new EvalVisitor(_cultureInfo);

                FormulaValue newValue = irnode.Accept(v, SymbolContext.New());

                var equal = fi._value != null &&  // null on initial run.
                            RuntimeHelpers.AreEqual(newValue, fi._value);

                if (!equal)
                {
                    _sendUpdates.Add(name);
                }

                fi._value = newValue;
            }

            _calcs[name] = fi._value;
        }
Пример #2
0
        /// <summary>
        /// Evaluate an expression as text and return the result.
        /// </summary>
        /// <param name="expressionText">textual representation of the formula</param>
        /// <param name="parameters">parameters for formula. The fields in the parameter record can
        /// be acecssed as top-level identifiers in the formula.</param>
        /// <returns>The formula's result</returns>
        public FormulaValue Eval(string expressionText, RecordValue parameters = null)
        {
            if (parameters == null)
            {
                parameters = RecordValue.Empty();
            }
            var check = Check(expressionText, parameters.IRContext.ResultType);

            check.ThrowOnErrors();

            var binding = check._binding;


            (IntermediateNode irnode, ScopeSymbol ruleScopeSymbol) = IRTranslator.Translate(binding);

            var          ev2      = new EvalVisitor(_cultureInfo);
            FormulaValue newValue = irnode.Accept(ev2, SymbolContext.New().WithGlobals(parameters));

            return(newValue);
        }