Exemplo n.º 1
0
 private void CreateResultFormula(string formula)
 {
     if (string.IsNullOrEmpty(formula)) return;
     MathFormula = formula;
     var engine = new CalculationEngine(CultureInfo.InvariantCulture);
     var formulaBuilder = engine.Formula(mathFormula).Result(Jace.DataType.FloatingPoint);
     var variable = 'a';
     for (var i = 0; i < criteria.Count; i++)
         formulaBuilder.Parameter("" + variable++, Jace.DataType.FloatingPoint);
     resultFormula = formulaBuilder.Build();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Converts the formula to a standard form, i.e. 
 ///     {4}*{5} => a*b
 /// Where
 ///     a is inputParameters[0],
 ///     b is inputParameters[1], etc.
 /// </summary>
 private object MathFormula(IReadOnlyList<SqlInputParameter> sqlInputParameters)
 {
     if (currentMathFormula != null) return currentMathFormula;
     inputParameters.Clear();
     var parameter = 'a';
     var formula = DesiredResultFormula;
     var index = 0;
     while (formula.Contains("{") && index < sqlInputParameters.Count)
     {
         var lookFor = string.Format("{{{0}}}", index++); // {0}, {1} etc.
         if (!formula.Contains(lookFor)) continue;
         formula = formula.Replace(lookFor, "" + parameter++);
         inputParameters.Add(sqlInputParameters[index-1]);
     }
     var engine = new CalculationEngine(CultureInfo.InvariantCulture);
     var formulaBuilder = engine.Formula(formula).Result(DataType.FloatingPoint);
     parameter = 'a';
     for (var i = 0; i < inputParameters.Count; i++)
         formulaBuilder.Parameter("" + parameter++, DataType.FloatingPoint);
     return currentMathFormula = formulaBuilder.Build();
 }