public SerializationContext Create(IEnumerable <DataRepository> dataRepositories = null, IEnumerable <IWithId> externalReferences = null) { var projectRetriever = _container.Resolve <IPKSimProjectRetriever>(); var project = projectRetriever.Current; //do not use the pksim repository since we need to register the deserialized object afterwards //this repository is only used to resolve the references var withIdRepository = new WithIdRepository(); externalReferences?.Each(withIdRepository.Register); var allRepositories = new List <DataRepository>(); if (project != null) { allRepositories.AddRange(project.All <IndividualSimulation>() .Where(s => s.HasResults) .Select(s => s.DataRepository) .Union(project.AllObservedData)); } if (dataRepositories != null) { allRepositories.AddRange(dataRepositories); } allRepositories.Each(withIdRepository.Register); return(SerializationTransaction.Create(_dimensionFactory, _objectBaseFactory, withIdRepository, _cloneManagerForModel, allRepositories)); }
public SerializationContext Create(SerializationContext parentSerializationContext = null) { var projectRetriever = _container.Resolve <IMoBiProjectRetriever>(); var project = projectRetriever.Current; var idRepository = new WithIdRepository(); var allRepositories = new List <DataRepository>(); if (parentSerializationContext != null) { allRepositories.AddRange(parentSerializationContext.Repositories); parentSerializationContext.IdRepository.All().Each(idRepository.Register); } //if project is defined, retrieved all available results from existing simulation. Required to ensure correct deserialization if (project != null) { var allSimulations = project.Simulations; var allSimulationResults = allSimulations.Where(s => s.HasResults).Select(s => s.Results); allRepositories.AddRange(allSimulationResults.Union(project.AllObservedData)); //Also register simulations to ensure that they are available as well for deserialization allSimulations.Each(idRepository.Register); } allRepositories.Each(idRepository.Register); return(new SerializationContext(_dimensionFactory, _objectBaseFactory, idRepository, allRepositories, _cloneManagerForModel, _container)); }
public override async Task <ModelSimulation> MapToModel(SnapshotSimulation snapshot, SimulationContext snapshotContext) { var project = snapshotContext.Project; _logger.AddInfo(PKSimConstants.Information.LoadingSimulation(snapshot.Name, snapshotContext.NumberOfSimulationsLoaded, snapshotContext.NumberOfSimulationsToLoad), project.Name); //Local cache of ids' that will be used to retrieve original building block parameters as the project is only registered //in global context once the whole snapshot mapping process is completed var withIdRepository = new WithIdRepository(); var registrationVisitor = new RegisterObjectVisitor(withIdRepository); var simulation = await createSimulationFrom(snapshot, snapshotContext); var contextWithSimulation = new SnapshotContextWithSimulation(simulation, snapshotContext); simulation.Solver = await _solverSettingsMapper.MapToModel(snapshot.Solver, snapshotContext); simulation.OutputSchema = await _outputSchemaMapper.MapToModel(snapshot.OutputSchema, snapshotContext); simulation.OutputSelections = await _outputSelectionsMapper.MapToModel(snapshot.OutputSelections, contextWithSimulation); registrationVisitor.Register(simulation); await updateParameters(simulation, snapshot.Parameters, withIdRepository, snapshotContext); await updateAdvancedParameters(simulation, snapshot.AdvancedParameters, snapshotContext); updateUsedObservedData(simulation, snapshot.ObservedData, project); updateAlteredBuildingBlock(simulation, snapshot.AlteredBuildingBlocks); if (snapshotContext.Run) { await runSimulation(snapshot, simulation); } simulation.AddAnalyses(await individualAnalysesFrom(simulation, snapshot.IndividualAnalyses, snapshotContext)); simulation.AddAnalyses(await populationAnalysesFrom(simulation, snapshot.PopulationAnalyses, snapshotContext)); _simulationParameterOriginIdUpdater.UpdateSimulationId(simulation); return(simulation); }
private async Task updateParameters(ModelSimulation simulation, LocalizedParameter[] snapshotParameters, WithIdRepository withIdRepository) { await _parameterMapper.MapLocalizedParameters(snapshotParameters, simulation.Model.Root); //The parameter mapper does not update the original building block in the simulation. We need to make sure we are keeping these values in sync so // that update and commit will work as expected (or building block difference ) var allParameters = _containerTask.CacheAllChildren <IParameter>(simulation.Model.Root); snapshotParameters?.Each(x => { var parameter = allParameters[x.Path]; //Somehow the localized parameter path was edited by hand or does not exist anymore. Warning was already shown during mapping. if (parameter == null) { return; } var buildingBlockParameter = withIdRepository.Get <IParameter>(parameter.Origin.ParameterId); if (buildingBlockParameter == null || !parameterDiffersFromTemplate(buildingBlockParameter, parameter)) { return; } buildingBlockParameter.Value = parameter.Value; buildingBlockParameter.IsDefault = false; }); }
protected override void Context() { sut = new WithIdRepository(); }