private void updateMoleculeAmountFromMoleculeStartValues(IModel model, IBuildConfiguration buildConfiguration)
        {
            foreach (var moleculeStartValue in buildConfiguration.AllPresentMoleculeValues())
            {
                //this can happen if the molecule start value contains entry for container that do not exist in the model
                var container = moleculeStartValue.ContainerPath.Resolve <IContainer>(model.Root);
                if (container == null || container.Mode != ContainerMode.Physical)
                {
                    continue;
                }

                var molecule = container.EntityAt <IMoleculeAmount>(moleculeStartValue.MoleculeName);
                if (molecule == null)
                {
                    throw new ArgumentException(Error.CouldNotFindMoleculeInContainer(moleculeStartValue.MoleculeName, moleculeStartValue.ContainerPath.PathAsString));
                }

                if (moleculeStartValue.Formula != null)
                {
                    //use a clone here because we want a different instance for each molecule
                    updateMoleculeAmountFormula(molecule, _cloneManagerForModel.Clone(moleculeStartValue.Formula));
                    _keywordReplacerTask.ReplaceIn(molecule, model.Root);
                }
                else if (startValueShouldBeSetAsConstantFormula(moleculeStartValue, molecule))
                {
                    updateMoleculeAmountFormula(molecule, createConstantFormula(moleculeStartValue));
                }

                molecule.ScaleDivisor          = moleculeStartValue.ScaleDivisor;
                molecule.NegativeValuesAllowed = moleculeStartValue.NegativeValuesAllowed;
            }
        }
示例#2
0
 private static IEnumerable <StartValueAndContainer> allPresentMoleculesInContainers(IContainer root, IBuildConfiguration buildConfiguration)
 {
     return(from moleculeStartValue in buildConfiguration.AllPresentMoleculeValues()
            let container = moleculeStartValue.ContainerPath.Resolve <IContainer>(root)
                            select new StartValueAndContainer
     {
         MoleculeStartValue = moleculeStartValue,
         Container = container
     });
 }