private IFormula checkFormula(IFormulaCache formulaCache, IFormula formula)
        {
            if (formula.IsExplicit())
            {
                return(checkFormulaByType(formulaCache, (ExplicitFormula)formula, AreEqualExplicitFormula));
            }

            if (formula.IsBlackBox())
            {
                return(checkFormulaByType(formulaCache, (BlackBoxFormula)formula, AreEqualBalckBoxFormula));
            }

            if (formula.IsTable())
            {
                return(checkFormulaByType(formulaCache, (TableFormula)formula, AreEqualTableFormula));
            }

            if (formula.IsTableWithOffSet())
            {
                return(checkFormulaByType(formulaCache, (TableFormulaWithOffset)formula, AreEqualTableFormulaWithOffset));
            }

            if (formula.IsDynamic())
            {
                return(checkFormulaByType(formulaCache, (SumFormula)formula, AreEqualSumFormula));
            }

            return(formula);
        }
 private void renameAbsolutePathIn(IFormula formula)
 {
     if (formula == null || !formula.IsExplicit())
     {
         return;
     }
     formula.ObjectPaths.Where(isAbsolutePath).Each(renameObjectPath);
 }
        private static string formulaStringFrom(IFormula formula)
        {
            if (formula != null && formula.IsExplicit())
            {
                return(formula.DowncastTo <ExplicitFormula>().FormulaString);
            }

            return(string.Empty);
        }
Esempio n. 4
0
 /// <summary>
 ///    Returns true if the formula can be added to a <see cref="FormulaCache" /> otherwise false
 /// </summary>
 public static bool IsCachable(this IFormula formula)
 {
     return(formula.IsExplicit() ||
            formula.IsBlackBox() ||
            formula.IsDynamic() ||
            formula.IsTable() ||
            formula.IsTableWithOffSet() ||
            formula.IsTableWithXArgument());
 }
Esempio n. 5
0
        private static void addFormualDescription(IFormula formula, StringBuilder description)
        {
            if (formula.IsConstant())
            {
                description.AppendLine($"{AppConstants.Captions.Value}: {((ConstantFormula) formula).Value.ToString(CultureInfo.InvariantCulture)}");
            }

            if (formula.IsExplicit())
            {
                description.AppendLine($"{AppConstants.Captions.Formula}:{((ExplicitFormula) formula).FormulaString}");
            }
        }
        private ExplicitFormula updateFormulaToAmountBase(IFormula originalFormula, IDimension amountDimension)
        {
            ExplicitFormula formulaInAmount;

            if (originalFormula.IsExplicit())
            {
                formulaInAmount = _cloneManagerForModel.Clone(originalFormula.DowncastTo <ExplicitFormula>());
            }
            else
            {
                formulaInAmount = _objectBaseFactory.Create <ExplicitFormula>()
                                  .WithFormulaString(originalFormula.Calculate(null).ToString(CultureInfo.InvariantCulture));
            }

            formulaInAmount.Dimension = amountDimension;

            var volumeAlias = _formulaTask.AddParentVolumeReferenceToFormula(formulaInAmount);

            formulaInAmount.FormulaString = $"({formulaInAmount.FormulaString})*{volumeAlias}";
            return(formulaInAmount);
        }
        public FormulaBuilderDTO MapFrom(IFormula formula)
        {
            if (formula == null)
            {
                return(FormulaBuilderDTO.NULL);
            }

            var dto = Map <FormulaBuilderDTO>(formula);

            if (formula.IsConstant())
            {
                dto.FormulaString = ((ConstantFormula)formula).Value.ConvertedTo <string>();
            }

            else if (formula.IsExplicit())
            {
                dto.FormulaString = ((ExplicitFormula)formula).FormulaString;
            }

            dto.FormulaType = _resolver.TypeFor(formula);
            dto.Dimension   = formula.Dimension;
            dto.ObjectPaths = _formulaUsablePathMapper.MapFrom(formula);
            return(dto);
        }
Esempio n. 8
0
        public bool FormulasAreTheSame(IFormula firstFormula, IFormula secondFormula)
        {
            if (firstFormula == null && secondFormula == null)
            {
                return(true);
            }

            if (firstFormula == null || secondFormula == null)
            {
                return(false);
            }

            var firstType  = firstFormula.GetType();
            var secondType = secondFormula.GetType();

            if (firstType != secondType)
            {
                return(false);
            }

            //nothing more to check for distributed formula or black box formula
            if (firstFormula.IsDistributed() || firstFormula.IsBlackBox() || firstFormula.IsDynamic())
            {
                return(true);
            }

            if (firstFormula.IsConstant())
            {
                var firstConstFormula  = firstFormula.DowncastTo <ConstantFormula>();
                var secondConstFormula = secondFormula.DowncastTo <ConstantFormula>();
                return(firstConstFormula.Value == secondConstFormula.Value);
            }

            if (firstFormula.IsExplicit())
            {
                var firstExplicit  = firstFormula.DowncastTo <ExplicitFormula>();
                var secondExplicit = secondFormula.DowncastTo <ExplicitFormula>();

                if (!string.Equals(firstExplicit.FormulaString, secondExplicit.FormulaString))
                {
                    return(false);
                }

                //check that formula have the same references using the same alias
                var firstObjectPathCache = new Cache <string, IFormulaUsablePath>(x => x.Alias);
                firstObjectPathCache.AddRange(firstExplicit.ObjectPaths);
                var secondObjectPathCache = new Cache <string, IFormulaUsablePath>(x => x.Alias);
                secondObjectPathCache.AddRange(secondExplicit.ObjectPaths);


                if (firstObjectPathCache.Count() != secondObjectPathCache.Count())
                {
                    return(false);
                }

                foreach (var keyValue in firstObjectPathCache.KeyValues)
                {
                    if (!secondObjectPathCache.Contains(keyValue.Key))
                    {
                        return(false);
                    }
                    var path = secondObjectPathCache[keyValue.Key];
                    if (!path.Equals(keyValue.Value))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }