Ejemplo n.º 1
0
        /// <summary>
        /// Creates the version manager and delcares the existing content as the virst version of the project.
        /// </summary>
        public void StartVersioning(int firstVersionNumber = 1, string firstVersionLabel = "v1")
        {
            VersionManager = new VersionManager(this);

            Version firstVersion = new Version(this)
            {
                Label = firstVersionLabel, Number = firstVersionNumber
            };

            VersionManager.Versions.Add(firstVersion);
            ProjectVersion firstProjectVersion = this.SingleVersion;

            firstProjectVersion.Version = firstVersion;
            this.SingleVersion          = null;

            /* direct property base assignment is used to prevent
             * methods reacting to the change of "UsesVersioning"
             * property during an incoherent state */
            usesVersioning = true;
            ProjectVersions.Add(firstProjectVersion);

            foreach (IVersionedItem versionedItem in ModelIterator.GetAllModelItems(firstProjectVersion).OfType <IVersionedItem>())
            {
                firstVersion.Items.Add(versionedItem);
                VersionManager.AddVersionedItem(versionedItem);
            }

            /* Now listeners to the change of "UsesVersioning" can be notified */
            UsesVersioning = true;
        }
Ejemplo n.º 2
0
        private static ProjectVersions GetProjectVersions(XmlElement xmlProject)
        {
            var projectVersions = new ProjectVersions();

            foreach (XmlElement propertyGroup in xmlProject.Elements("PropertyGroup"))
            {
                var version = propertyGroup.Element("Version");
                if (version != null)
                {
                    projectVersions.Version = Version.Parse(version.InnerText);
                }

                var fileVersion = propertyGroup.Element("FileVersion");
                if (fileVersion != null)
                {
                    projectVersions.FileVersion = Version.Parse(fileVersion.InnerText);
                }

                var assemblyVersion = propertyGroup.Element("AssemblyVersion");
                if (assemblyVersion != null)
                {
                    projectVersions.AssemblyVersion = Version.Parse(assemblyVersion.InnerText);
                }
            }

            return(projectVersions);
        }
Ejemplo n.º 3
0
        private XElement getConvertedElementFrom(byte[] serializationBytes, out int version)
        {
            var element = ElementFrom(serializationBytes);

            version = versionFrom(element);
            if (!ProjectVersions.CanLoadVersion(version))
            {
                throw new InvalidProjectVersionException(version);
            }

            convertXml(element, version);
            return(element);
        }
Ejemplo n.º 4
0
        private (XElement element, int originalVersion, bool conversionHappened) getConvertedElementFrom(byte[] serializationBytes)
        {
            var element         = ElementFrom(serializationBytes);
            var originalVersion = versionFrom(element);

            if (!ProjectVersions.CanLoadVersion(originalVersion))
            {
                throw new InvalidProjectVersionException(originalVersion);
            }

            var conversionHappened = convertXml(element, originalVersion);

            return(element, originalVersion, conversionHappened);
        }
Ejemplo n.º 5
0
        public IPKSimProject Load(ISession session)
        {
            var projectFromDb = projectFromDatabase(session);

            if (projectFromDb == null)
            {
                throw new InvalidProjectFileException();
            }

            if (ProjectVersions.CanLoadVersion(projectFromDb.Version))
            {
                return(projectFrom(projectFromDb));
            }

            //Project was created with a newer version of the software
            throw new InvalidProjectVersionException(projectFromDb.Version);
        }
Ejemplo n.º 6
0
        //-------------------------------------------
        private static void CreateSLN(ProjectVersions version)
        {
            //-----------------------------------
            string slnFile = "ProjectFiles/ProjectBuilder" + version + ".sln";

            StreamReader _reader = null;

            string        lineOfText;
            StringBuilder sb = new StringBuilder();

            if (false == System.IO.File.Exists(slnFile))
            {
                throw new Exception("File " + slnFile + " does not exists");
            }
            using (Stream stream = System.IO.File.OpenRead(slnFile))
            {
                _reader = new StreamReader(stream);
                while (true)
                {
                    lineOfText = _reader.ReadLine();
                    if (lineOfText == null)
                    {
                        string _class = sb.ToString();
                        _class = _class.Replace("{0}", ProjectPort);
                        _class = _class.Replace("{1}", PhysicalPath);
//						_class=_class.Replace("{1}",Guid.NewGuid().ToString());
//						_class=_class.Replace("{2}",Guid.NewGuid().ToString());
                        //-----------------------------------
                        string path = Globals.BaseDirectory + ProjectName + version + ".sln";
                        // Create a file to write to.
                        using (StreamWriter sw = File.CreateText(path))
                        {
                            sw.WriteLine(_class);
                        }
                        return;
                        //-----------------------------------
                    }
                    else
                    {
                        sb.Append(lineOfText + Environment.NewLine);
                    }
                }
            }
            //-----------------------------------
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public IMoBiProject Load(IMoBiContext context)
        {
            var projectFromDb = projectFromDatabase();

            if (projectFromDb == null)
            {
                return(null);
            }

            if (!ProjectVersions.CanLoadVersion(projectFromDb.Version))
            {
                throw new InvalidProjectFileException(projectFromDb.Version);
            }

            var project = projectFrom(projectFromDb);

            _postSerializationStepsMaker.PerformPostDeserializationFor(project, projectFromDb.Version);

            context.LoadFrom(project);

            return(project);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public InvalidProjectFileException(int projectVersion)
     : base(AppConstants.ProjectVersionCannotBeLoaded(projectVersion, ProjectVersions.Current, ProjectVersions.ProjectIsTooOld(projectVersion), AppConstants.ProductSiteDownload))
 {
 }
Ejemplo n.º 12
0
 public InvalidProjectVersionException(int projectVersion) :
     base(PKSimConstants.Error.ProjectVersionCannotBeLoaded(projectVersion, ProjectVersions.Current,
                                                            ProjectVersions.ProjectIsTooOld(projectVersion), Constants.PRODUCT_SITE_DOWNLOAD))
 {
 }
Ejemplo n.º 13
0
        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)));
            }
        }