Esempio n. 1
0
        public override async Task <ModelExpressionProfile> MapToModel(SnapshotExpressionProfile snapshot, SnapshotContext snapshotContext)
        {
            var expressionProfile = _expressionProfileFactory.Create(snapshot.Type, snapshot.Species, snapshot.Molecule);

            expressionProfile.Description = snapshot.Description;
            expressionProfile.Category    = snapshot.Category;

            var(molecule, individual) = expressionProfile;
            //Update molecule properties first
            updateMoleculePropertiesToMolecule(molecule, snapshot, individual, snapshotContext);

            //Then override all parameters that were set
            await _parameterMapper.MapLocalizedParameters(snapshot.Parameters, individual, snapshotContext, !snapshotContext.IsV9FormatOrEarlier);

            var snapshotWithSubjectContext = new SnapshotContextWithSubject(individual, snapshotContext);
            var ontogeny = await _ontogenyMapper.MapToModel(snapshot.Ontogeny, snapshotWithSubjectContext);

            _ontogenyTask.SetOntogenyForMolecule(molecule, ontogeny, individual);

            var context = new ExpressionContainerMapperContext(snapshotContext)
            {
                Molecule                     = molecule,
                ExpressionParameters         = individual.AllExpressionParametersFor(molecule),
                MoleculeExpressionContainers = individual.AllMoleculeContainersFor(molecule),
            };
            await _expressionContainerMapper.MapToModels(snapshot.Expression, context);

            //We need to normalize relative expressions when loading from old format
            if (snapshotContext.IsV9FormatOrEarlier)
            {
                //Make sure we load the default parameters from db just in case we were dealing with a standard molecule
                _moleculeParameterTask.SetDefaultMoleculeParameters(molecule);

                //Global parameters were saved directly under the snapshot parameter
                await updateGlobalMoleculeParameters(snapshot, molecule, snapshotContext);

                NormalizeRelativeExpressionCommand.NormalizeExpressions(individual, molecule);
            }

            return(expressionProfile);
        }
Esempio n. 2
0
        public override async Task <IndividualMolecule> MapToModel(Molecule snapshot, ModelIndividual individual)
        {
            var molecule = createMoleculeFrom(snapshot, individual);

            MapSnapshotPropertiesToModel(snapshot, molecule);

            //This call should happen before updating parameters from snapshot to ensure that default molecule
            //parameters that were updated by the user are taking precedence.
            _moleculeExpressionTask.SetDefaulMoleculeParameters(molecule);

            await UpdateParametersFromSnapshot(snapshot, molecule, snapshot.Type.ToString());

            updateMoleculePropertiesToMolecule(molecule, snapshot);

            var ontogeny = await _ontogenyMapper.MapToModel(snapshot.Ontogeny, individual);

            _ontogenyTask.SetOntogenyForMolecule(molecule, ontogeny, individual);

            await updateExpression(snapshot, new ExpressionContainerMapperContext { Molecule = molecule, SimulationSubject = individual });

            return(molecule);
        }