示例#1
0
        public override async Task <ModelProject> MapToModel(SnapshotProject snapshot, ProjectContext projectContext)
        {
            _logger.AddDebug($"Loading project '{snapshot.Name}' from snapshot...", snapshot.Name);

            var project = new ModelProject
            {
                Name        = snapshot.Name,
                Description = snapshot.Description,
                Creation    = _creationMetaDataFactory.Create()
            };

            //The entry point of our context structure.
            var snapshotContext = new SnapshotContext(project, snapshot.Version);

            project.Creation.InternalVersion = snapshot.Version;
            project.Creation.Version         = ProjectVersions.FindBy(snapshot.Version)?.VersionDisplay;

            await allBuildingBlocksFrom(snapshot, snapshotContext);

            var observedData = await observedDataFrom(snapshot.ObservedData, snapshotContext);

            observedData?.Each(repository => addObservedDataToProject(project, repository));

            var allSimulations = await allSimulationsFrom(project, projectContext, snapshot.Simulations, snapshotContext);

            allSimulations?.Each(simulation => addSimulationToProject(project, simulation));

            var allSimulationComparisons = await allSimulationComparisonsFrom(snapshot.SimulationComparisons, snapshotContext);

            allSimulationComparisons?.Each(comparison => addComparisonToProject(project, comparison));

            var allParameterIdentifications = await allParameterIdentificationsFrom(snapshot.ParameterIdentifications, snapshotContext);

            allParameterIdentifications?.Each(parameterIdentification => addParameterIdentificationToProject(project, parameterIdentification));

            var allQualificationPlans = await allQualificationPlansFrom(snapshot.QualificationPlans, snapshotContext);

            allQualificationPlans?.Each(qualificationPlan => addQualificationPlanToProject(project, qualificationPlan));

            //Map all classifications once project is loaded
            await updateProjectClassifications(snapshot, snapshotContext);

            return(project);
        }
示例#2
0
        public override async Task <ModelProject> MapToModel(SnapshotProject snapshot)
        {
            var project = new ModelProject
            {
                Description = snapshot.Description,
                Creation    = _creationMetaDataFactory.Create()
            };

            project.Creation.InternalVersion = snapshot.Version;
            project.Creation.Version         = ProjectVersions.FindBy(snapshot.Version)?.VersionDisplay;

            var buildingBlocks = await allBuidingBlocksFrom(snapshot);

            buildingBlocks?.Each(project.AddBuildingBlock);

            var observedData = await observedDataFrom(snapshot.ObservedData);

            observedData?.Each(repository => addObservedDataToProject(project, repository));

            var allSimulations = await allSmulationsFrom(snapshot.Simulations, project);

            allSimulations?.Each(simulation => addSimulationToProject(project, simulation));

            var allSimulationComparisons = await allSimulationComparisonsFrom(snapshot.SimulationComparisons, project);

            allSimulationComparisons?.Each(comparison => addComparisonToProject(project, comparison));

            var allParameterIdentifications = await allParameterIdentificationsFrom(snapshot.ParameterIdentifications, project);

            allParameterIdentifications?.Each(parameterIdentification => addParameterIdentificationToProject(project, parameterIdentification));

            var allQualificationPlans = await allQualificationPlansFrom(snapshot.QualificationPlans, project);

            allQualificationPlans?.Each(qualificationPlan => addQualificationPlanToProject(project, qualificationPlan));

            //Map all classifications once project is loaded
            await updateProjectClassifications(snapshot, project);

            return(project);
        }
示例#3
0
        private object deserialize(XElement element, IMoBiProject project, int version, Type type = null, SerializationContext parentSerializationContext = null)
        {
            object deserializedObject;
            bool   conversionHappened = false;

            using (var serializationContext = _serializationContextFactory.Create(parentSerializationContext))
            {
                conversionHappened = convertXml(element, version, project);

                IXmlSerializer <SerializationContext> serializer;
                Type deserializeType;

                if (type == null)
                {
                    serializer      = _repository.SerializerFor(element);
                    deserializeType = serializer.ObjectType;
                }
                else
                {
                    serializer      = serializeFor(type);
                    deserializeType = type;
                }

                var formulaCacheElement = getFormulaCacheElementFor(element, deserializeType);
                conversionHappened = convertXml(formulaCacheElement, version, project) || conversionHappened;
                deserializeFormula(formulaCacheElement, version, project, serializationContext);

                deserializedObject = serializer.Deserialize(element, serializationContext);
            }

            //Performs the conversion to the latest project version
            conversionHappened = convert(deserializedObject, version, project) || conversionHappened;

            //Once the project was converted, update all formula references
            _deserializedReferenceResolver.ResolveFormulaAndTemplateReferences(deserializedObject, project);

            if (conversionHappened)
            {
                _eventPublisher.PublishEvent(new ObjectConvertedEvent(deserializedObject, ProjectVersions.FindBy(version)));
            }

            return(deserializedObject);
        }
        private void updatePropertiesFor <TObject>(TObject deserializedObject, int version)
        {
            //convert object if required
            var conversionHappened = convert(deserializedObject, version);

            var simulation = deserializedObject as Simulation;

            if (simulation != null)
            {
                _simulationUpdater.UpdateSimulation(simulation);
            }

            var individual = deserializedObject as Individual;

            if (individual != null)
            {
                _referenceResolver.ResolveReferencesIn(individual);
            }

            var population = deserializedObject as Population;

            if (population != null)
            {
                _referenceResolver.ResolveReferencesIn(population.FirstIndividual);
            }

            var lazyLoadable = deserializedObject as ILazyLoadable;

            if (lazyLoadable != null)
            {
                lazyLoadable.IsLoaded = true;
            }

            if (conversionHappened && deserializedObject.IsAnImplementationOf <IObjectBase>())
            {
                _eventPublisher.PublishEvent(new ObjectBaseConvertedEvent(deserializedObject.DowncastTo <IObjectBase>(), ProjectVersions.FindBy(version)));
            }
        }