protected override void Context()
 {
     base.Context();
     _concentrationFormula = A.Fake <IFormula>();
     _formulaCache         = new FormulaCache();
     A.CallTo(() => _formulaFactory.ConcentrationFormulaFor(_formulaCache)).Returns(_concentrationFormula);
 }
        public T CloneBuildingBlock <T>(T buildingBlock) where T : class, IBuildingBlock
        {
            var formulaCache = new FormulaCache();
            var clone        = Clone(buildingBlock, formulaCache);

            formulaCache.Each(clone.AddFormula);
            return(clone);
        }
        public T CloneBuidingBlock <T>(T toClone) where T : class, IBuildingBlock
        {
            var formulaCache = new FormulaCache();
            var copy         = _cloneManagerForBuildingBlock.Clone(toClone, formulaCache);

            formulaCache.Each(copy.AddFormula);
            return(copy);
        }
        public T CloneBuidingBlockInfo <T>(T toClone) where T : class, IBuildingBlockInfo, new()
        {
            var formulaCache = new FormulaCache();
            var copy         = new T {
                UntypedBuildingBlock = CloneBuidingBlock(toClone.UntypedBuildingBlock)
            };

            formulaCache.Each(copy.UntypedBuildingBlock.AddFormula);
            copy.TemplateBuildingBlockId = toClone.TemplateBuildingBlockId;
            copy.SimulationChanges       = toClone.SimulationChanges;
            return(copy);
        }
Exemple #5
0
        public virtual T Clone <T>(T objectToClone) where T : class, IObjectBase
        {
            var formulaCache = new FormulaCache();
            var clone        = _cloneManagerForBuildingBlock.Clone(objectToClone, formulaCache);

            var cloneBuildingBlock = clone as IBuildingBlock;

            if (cloneBuildingBlock != null)
            {
                updateFormulaCacheOfClone(objectToClone.DowncastTo <IBuildingBlock>(), cloneBuildingBlock, formulaCache);
            }

            return(clone);
        }
 public SerializationContext(IDimensionFactory dimensionFactory, IObjectBaseFactory objectFactory,
                             IWithIdRepository withIdRepository, IEnumerable <DataRepository> dataRepositories, ICloneManagerForModel cloneManagerForModel, IContainer container)
 {
     Container            = container;
     StringMap            = new Cache <string, int>();
     IdStringMap          = new Cache <int, string>();
     IdRepository         = withIdRepository;
     DimensionFactory     = dimensionFactory;
     ObjectFactory        = objectFactory;
     Formulas             = new FormulaCache();
     _modelReferenceCache = new ModelReferenceCache(withIdRepository, cloneManagerForModel);
     _dataReferenceCache  = new DataReferenceCache(withIdRepository);
     _dataRepositories    = new List <DataRepository>();
     dataRepositories?.Each(AddRepository);
 }
        protected override void Context()
        {
            base.Context();
            _dimParameter                 = DomainHelperForSpecs.AmountDimension;
            _dimEquivalent                = new Dimension(_dimParameter.BaseRepresentation, "Equivalent", _dimParameter.BaseUnit.Name);
            _anotherDimension             = DomainHelperForSpecs.TimeDimension;
            _parameter                    = A.Fake <IParameter>().WithDimension(_dimParameter);
            _parameter.Formula            = new ExplicitFormula("1+2").WithDimension(_dimParameter);
            _buidingBlockWithFormulaCache = A.Fake <IBuildingBlock>();
            _formulaCache                 = new FormulaCache();
            A.CallTo(() => _buidingBlockWithFormulaCache.FormulaCache).Returns(_formulaCache);
            _formulaCache.Add(new ExplicitFormula().WithId("B").WithName("B").WithDimension(_dimEquivalent));
            _formulaCache.Add(new ExplicitFormula().WithId("C").WithName("C").WithDimension(_anotherDimension));
            _formulaCache.Add(new ExplicitFormula().WithId("A").WithName("A").WithDimension(_dimParameter));

            sut.Init(_parameter, _buidingBlockWithFormulaCache, new UsingFormulaDecoder());
        }
        protected override void Context()
        {
            base.Context();
            _dimParameter         = DomainHelperForSpecs.AmountDimension;
            _rhsDim               = DomainHelperForSpecs.AmountPerTimeDimension;
            _parameter            = A.Fake <IParameter>().WithDimension(_dimParameter);
            _parameter.RHSFormula = new ExplicitFormula("1+2").WithDimension(_rhsDim);

            _buidingBlockWithFormulaCache = A.Fake <IBuildingBlock>();
            _formulaCache = new FormulaCache();
            A.CallTo(() => _buidingBlockWithFormulaCache.FormulaCache).Returns(_formulaCache);
            _formulaCache.Add(new ExplicitFormula().WithId("C").WithName("C").WithDimension(_rhsDim));
            _formulaCache.Add(new ExplicitFormula().WithId("A").WithName("A").WithDimension(_dimParameter));

            sut.IsRHS = true;
            sut.Init(_parameter, _buidingBlockWithFormulaCache);
        }
        public void TestSerialization()
        {
            IFormula           f1  = CreateObject <ConstantFormula>().WithName("F.Constantin").WithDimension(DimensionLength).WithValue(2.1);
            IFormula           f2  = CreateObject <ExplicitFormula>().WithName("F.Erika").WithDimension(DimensionLength).WithFormulaString("A * 2");
            IFormulaUsablePath fup = new FormulaUsablePath(new[] { "aa", "bb" }).WithAlias("b").WithDimension(DimensionLength);

            f2.AddObjectPath(fup);

            FormulaCache x1 = new FormulaCache();

            x1.Add(f1);
            x1.Add(f2);

            IFormulaCache x2 = SerializeAndDeserialize(x1);

            AssertForSpecs.AreEqualFormulaCache(x2, x1);
        }
Exemple #10
0
        public void AddHelpParameter(IParameter parameter, DescriptorCriteria containerCriteria)
        {
            if (parameter == null)
            {
                throw new ArgumentException(Error.UndefinedHelpParameter(Name, Category));
            }

            if (parameter.Formula == null)
            {
                throw new ArgumentException(Error.UndefinedFormulaInHelpParameter(parameter.Name, Name, Category));
            }

            if (!FormulaCache.Contains(parameter.Formula))
            {
                FormulaCache.Add(parameter.Formula);
            }

            _helpParameters.Add(parameter, containerCriteria);
        }
Exemple #11
0
        protected override void Context()
        {
            base.Context();
            _process = new EnzymaticProcess().WithName("P1");
            _process.InternalName = "internalNAme";
            _drug         = new MoleculeBuilder().WithName("drug");
            _metabolite   = new MoleculeBuilder().WithName("metabolite");
            _enzymeName   = "P1";
            _formulaCache = new FormulaCache();
            _kinetic      = new ExplicitFormula().WithId("trala");
            _kinetic.AddObjectPath(new FormulaUsablePath(new[] { "Organism", CoreConstants.KeyWords.Molecule }));
            _kinetic.AddObjectPath(new FormulaUsablePath(new[] { "Organism", CoreConstants.KeyWords.Protein }));
            _parameterFormula = new ExplicitFormula();
            _parameterFormula.AddObjectPath(new FormulaUsablePath(new[] { "Liver", CoreConstants.KeyWords.Molecule }));

            var pkSimReaction = new PKSimReaction().WithName("template");

            A.CallTo(() => _simulationActiveProcessRepository.ProcessFor <PKSimReaction>(_process.InternalName)).Returns(pkSimReaction);
            pkSimReaction.Formula = _kinetic;
            A.CallTo(() => _cloneManager.Clone(pkSimReaction)).Returns(pkSimReaction);
        }
 protected override void Context()
 {
     _reactionDimensionRetriever        = A.Fake <IReactionDimensionRetriever>();
     _dimensionFactory                  = A.Fake <IDimensionFactory>();
     _amoutToConcentrationFormulaMapper = A.Fake <IAmoutToConcentrationFormulaMapper>();
     _objectBaseFactory                 = A.Fake <IObjectBaseFactory>();
     _formulaTask          = A.Fake <IFormulaTask>();
     _displayUnitRetriever = A.Fake <IDisplayUnitRetriever>();
     _formulaFactory       = A.Fake <IFormulaFactory>();
     _constantZeroFormula  = new ConstantFormula(0);
     _formulaCache         = new FormulaCache();
     _objectTypeResolver   = new ObjectTypeResolver();
     A.CallTo(() => _formulaTask.AddParentVolumeReferenceToFormula(A <IFormula> ._)).Returns(Constants.VOLUME_ALIAS);
     A.CallTo(() => _dimensionFactory.Dimension(Constants.Dimension.AMOUNT)).Returns(DomainHelperForSpecs.AmountDimension);
     A.CallTo(() => _dimensionFactory.Dimension(Constants.Dimension.AMOUNT_PER_TIME)).Returns(DomainHelperForSpecs.AmountPerTimeDimension);
     A.CallTo(() => _dimensionFactory.Dimension(Constants.Dimension.MOLAR_CONCENTRATION)).Returns(DomainHelperForSpecs.ConcentrationDimension);
     A.CallTo(() => _dimensionFactory.Dimension(Constants.Dimension.MOLAR_CONCENTRATION_PER_TIME)).Returns(DomainHelperForSpecs.ConcentrationPerTimeDimension);
     A.CallTo(() => _objectBaseFactory.Create <ExplicitFormula>()).Returns(new ExplicitFormula());
     A.CallTo(() => _formulaFactory.ConstantFormula(0, DomainHelperForSpecs.ConcentrationDimension)).Returns(_constantZeroFormula);
     sut = new AmountToConcentrationConverter(_reactionDimensionRetriever, _dimensionFactory, _amoutToConcentrationFormulaMapper,
                                              _objectBaseFactory, _formulaTask, _displayUnitRetriever, _objectTypeResolver, _formulaFactory);
 }
        public void TestSerializationObserverBuilderWithExplicitFormula()
        {
            ContainerObserverBuilder x1 = CreateObject <ContainerObserverBuilder>().WithName("Oberon.Builder");

            x1.ForAll = false;
            x1.AddMoleculeName("H2O");
            x1.AddMoleculeName("CO2");

            ExplicitFormula    f1  = CreateObject <ExplicitFormula>().WithName("Fortunato").WithDimension(DimensionLength);
            IFormulaUsablePath fup = new FormulaUsablePath(new string[] { "aa", "bb" }).WithAlias("b").WithDimension(DimensionLength);

            f1.AddObjectPath(fup);

            IFormulaCache formulaCache = new FormulaCache();

            formulaCache.Add(f1);

            x1.Formula = formulaCache[f1.Id];

            //SerializeAndDeserializeGeneral(formulaCache);
            IObserverBuilder x2 = SerializeAndDeserialize(x1);

            AssertForSpecs.AreEqualObserverBuilder(x2, x1);
        }
Exemple #14
0
        private void updateFormulaCacheOfClone(IBuildingBlock originBuildingBlock, IBuildingBlock cloneBuildingBlock, FormulaCache formulaCache)
        {
            //reset formula cache of cloneManager at that stage
            _cloneManagerForBuildingBlock.FormulaCache = new FormulaCache();

            //  add a clone of each formula that is not present in the clone by name
            originBuildingBlock.FormulaCache
            .Where(f => !formulaCache.ExistsByName(f.Name))
            .Each(f => formulaCache.Add(_cloneManagerForBuildingBlock.Clone(f)));

            // we nee to add the Formulas to the clones of BuildingBlockWithFormulaCaches Formula cache
            formulaCache.Each(cloneBuildingBlock.AddFormula);
        }
Exemple #15
0
 public override void AcceptVisitor(IVisitor visitor)
 {
     base.AcceptVisitor(visitor);
     FormulaCache.Each(formula => formula.AcceptVisitor(visitor));
 }
Exemple #16
0
 public void AddFormula(IFormula formula)
 {
     FormulaCache.Add(formula);
 }
 public IEnumerable <FormulaBuilderDTO> GetFormulas()
 {
     return(FormulaCache != null
     ? FormulaCache.MapAllUsing(_formulaMapper)
     : Enumerable.Empty <FormulaBuilderDTO>());
 }
 public IEnumerable <FormulaBuilderDTO> GetFormulas()
 {
     return(FormulaCache.MapAllUsing(_formulaToDTOFormulaMapper));
 }
Exemple #19
0
 public IEnumerable <FormulaBuilderDTO> GetFormulas()
 {
     return(FormulaCache.Select(formula => _formulaToDTOFormulaBuilderMapper.MapFrom(formula)));
 }
 protected override void Context()
 {
     sut = new FormulaCache();
 }