Beispiel #1
0
        public void Handle(EntitySelectedEvent eventToHandle)
        {
            var formula = eventToHandle.ObjectBase as IFormula;

            if (formula == null)
            {
                return;
            }
            if (_cache.Contains(formula))
            {
                Select(formula);
                _view.Select(dtoFor(formula));
            }
        }
Beispiel #2
0
        public IFormula RateFor(RateKey rateKey, IFormulaCache formulaCache)
        {
            if (rateKey == null)
            {
                return(null);
            }

            //no formula cache defined. Formula should be unique by id
            if (formulaCache == null)
            {
                return(createFormula(rateKey).WithId(_idGenerator.NewId()));
            }

            if (!formulaCache.Contains(rateKey))
            {
                var formula = createFormula(rateKey);
                if (formula.IsConstant())
                {
                    return(formula);
                }

                formulaCache.Add(formula);
            }

            return(formulaCache[rateKey]);
        }
Beispiel #3
0
 /// <summary>
 ///    add the given formula to the cache only if
 ///    1- the formula is not constant (constant formula are not registered in cache)
 ///    2- the formula was not registered already.
 /// </summary>
 /// <param name="formula">formula to add</param>
 /// <param name="formulaCache">formula cache</param>
 private void addFormulaToCacheIfNecessary(IFormula formula, IFormulaCache formulaCache)
 {
     if (formula.IsConstant())
     {
         return;
     }
     if (formulaCache.Contains(formula.Id))
     {
         return;
     }
     formulaCache.Add(formula);
 }
Beispiel #4
0
        public IFormula ConcentrationFormulaFor(IFormulaCache formulaCache)
        {
            if (formulaCache.Contains(CoreConstants.Formula.Concentration))
            {
                return(formulaCache[CoreConstants.Formula.Concentration]);
            }

            var formula = _objectBaseFactory.Create <ExplicitFormula>()
                          .WithId(CoreConstants.Formula.Concentration)
                          .WithName(CoreConstants.Formula.Concentration)
                          .WithFormulaString("V>0 ? M/V : 0");

            formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER).WithAlias("M").WithDimension(_dimensionRepository.Amount));
            formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, CoreConstants.Parameter.VOLUME).WithAlias("V").WithDimension(_dimensionRepository.Volume));

            formulaCache.Add(formula);
            formula.Dimension = _dimensionRepository.MolarConcentration;
            return(formula);
        }
        protected override IFormula CreateFormulaCloneFor(IFormula srcFormula)
        {
            // constant formulas are always cloned
            if (srcFormula.IsConstant())
            {
                return(CloneFormula(srcFormula));
            }

            // Check if target formula cache already contains the formula
            // to be cloned. This can happen if we are cloning
            // any substructure within the same building block
            // In this case, all formulas are already present in the
            // formula cache of this building block
            if (_formulaCache.Contains(srcFormula.Id))
            {
                return(srcFormula);
            }

            // Check if the formula was already cloned. Return the cloned
            // formula if so.
            if (_clonedFormulasByOriginalFormulaId.Contains(srcFormula.Id))
            {
                return(_clonedFormulasByOriginalFormulaId[srcFormula.Id]);
            }

            // Formula is neither present in the passed formula cahce nor
            // was already cloned. So create a new clone and insert it
            // in both target formula cache and the cache of all cloned formulas
            var clonedFormula = CloneFormula(srcFormula);

            _formulaCache.Add(clonedFormula);

            _clonedFormulasByOriginalFormulaId.Add(srcFormula.Id, clonedFormula);

            return(clonedFormula);
        }
Beispiel #6
0
 public void should_have_added_the_reaction_formula_to_the_formula_cache()
 {
     _formulaCache.Contains(_reaction.Formula).ShouldBeTrue();
 }
Beispiel #7
0
 public void should_create_a_new_concentration_formula_and_add_it_to_the_formula_cache()
 {
     _formulaCache.Contains(_concentrationFormula).ShouldBeTrue();
 }