//private static void CheckPsmClassParent(PSMDiagram diagram) //{ // foreach (PSMClass psmClass in diagram.DiagramElements.Keys.OfType<PSMClass>()) // { // if (psmClass.ParentAssociation != null) // { // if (psmClass.ParentAssociation.ChildEnd != psmClass) // { // throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass)); // } // if (psmClass.ParentUnion != null) // { // throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass)); // } // } // else if (psmClass.ParentUnion != null) // { // if (!psmClass.ParentUnion.Components.Contains(psmClass)) // { // throw new ModelConsistencyException(string.Format("Bad class parent union component {0}", psmClass)); // } // if (psmClass.ParentAssociation != null) // { // throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass)); // } // } // else // { // if (!diagram.Roots.Contains(psmClass) && psmClass.Generalizations.Count == 0) // { // throw new ModelConsistencyException(string.Format("Bad class {0}", psmClass)); // } // } // } //} //public static void CheckPsmParentsAndRoots(PSMDiagram diagram) //{ // foreach (Element element in diagram.DiagramElements.Keys) // { // PSMSubordinateComponent subordinateComponent = (element as PSMSubordinateComponent); // if (subordinateComponent != null) // { // if (subordinateComponent.ParentEnd == null && !diagram.Roots.Contains((PSMClass)subordinateComponent)) // { // throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent)); // } // if (subordinateComponent.ParentEnd != null) // { // if (!subordinateComponent.ParentEnd.Components.Contains(subordinateComponent)) // { // throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent)); // } // } // } // PSMSuperordinateComponent superordinateComponent = element as PSMSuperordinateComponent; // if (superordinateComponent != null) // { // foreach (PSMSubordinateComponent component in superordinateComponent.Components) // { // if (component.ParentEnd != superordinateComponent) // { // throw new ModelConsistencyException(string.Format("Bad superordinateComponent component {0}", superordinateComponent)); // } // } // } // } //} //public static void CheckPsmElementsDiagram(PSMDiagram diagram) //{ // foreach (Element element in diagram.DiagramElements.Keys) // { // PSMElement psmElement = element as PSMElement; // if (psmElement != null) // { // if (psmElement.Diagram != diagram) // { // throw new ModelConsistencyException(string.Format("Element {0} has wrong diagram.", psmElement)); // } // } // } //} //public static void CheckViewHelpersDiagram(Diagram diagram) //{ // foreach (KeyValuePair<Element, ViewHelper> kvp in diagram.DiagramElements) // { // if (kvp.Value.Diagram != diagram) // { // throw new ModelConsistencyException(string.Format("ViewHelper {0} for element {1} has wrong diagram.", kvp.Key, // kvp.Value)); // } // } //} //public static void CheckElementSchema(IEnumerable<Element> elements, Schema schema, List<Element> checkedAlready) //{ // if (checkedAlready == null) // checkedAlready = new List<Element>(); // foreach (Element element in elements) // { // CheckElementSchema(element, schema, checkedAlready); // } //} //public static void CheckElementSchema(Element element, Schema schema, List<Element> checkedAlready) //{ // if (element == null) // { // return; // } // if (checkedAlready != null) // { // if (checkedAlready.Contains(element)) // return; // else // checkedAlready.Add(element); // } // if (element.Schema != schema) // { // throw new ModelConsistencyException(string.Format("Schema of element {0} differs.", element)); // } // // reiterate through properties // Type type = element.GetType(); // Type elementInterfaceType = typeof(Element); // Type elementCollectionType = typeof(IEnumerable); // foreach (PropertyInfo propertyInfo in type.GetProperties()) // { // if (elementInterfaceType.IsAssignableFrom(propertyInfo.PropertyType)) // { // //System.Diagnostics.Debug.WriteLine(String.Format("Checking property {0}.{1}.", type.Name, propertyInfo.Name)); // Element value = propertyInfo.GetValue(element, null) as Element; // if (value != null) // { // CheckElementSchema(value, schema, checkedAlready); // } // } // if (elementCollectionType.IsAssignableFrom(propertyInfo.PropertyType)) // { // IEnumerable theCollection = propertyInfo.GetValue(element, null) as IEnumerable; // if (theCollection != null) // { // foreach (object item in theCollection) // { // if (item is Element) // { // CheckElementSchema(element, schema, checkedAlready); // } // } // } // } // } //} #endregion #region Versioning private static void CheckVersioningConsistency(Project project) { VersionManager versionManager = project.VersionManager; Assert.AreEqual(versionManager.Versions.Count, project.ProjectVersions.Count); foreach (ProjectVersion projectVersion in project.ProjectVersions) { Assert.AreEqual(projectVersion, project.GetProjectVersion(projectVersion.Version)); } foreach (ProjectVersion projectVersion in project.ProjectVersions) { foreach (ExolutioObject o in ModelIterator.GetAllModelItems(projectVersion)) { IVersionedItem versionedItem = (o as IVersionedItem); if (versionedItem != null) { Assert.AreEqual(versionedItem.Version, projectVersion.Version); Assert.IsTrue(projectVersion.Version.Items.Contains(versionedItem)); } } } foreach (Exolutio.Model.Versioning.Version version in project.VersionManager.Versions) { Exolutio.Model.Versioning.Version _v = version; Assert.IsTrue(version.Items.All(i => i.Version == _v)); } #if DEBUG versionManager.VerifyConsistency(); #endif }
/// <summary> /// Creates new verion of the project from the existing version <param name="branchedVersion" />. /// The created version is fully integrated into versioning system /// (dictionaries <see cref="Exolutio.Model.Project" />.<see cref="Exolutio.Model.Project.ProjectVersions" /> and version links /// among <see cref="IVersionedItem"/>s). /// </summary> /// <param name="branchedVersion">Existing version in the project</param> /// <param name="newVersion">New version marker. Created, but "emtpy", must not be member of Project.Versions collection</param> public ProjectVersion BranchProject(ProjectVersion branchedVersion, Version newVersion) { branching = true; newVersion.BranchedFrom = branchedVersion.Version; Versions.Add(newVersion); ProjectVersion newProjectVersion = new ProjectVersion(Project); newProjectVersion.Version = newVersion; ElementCopiesMap elementCopiesMap = new ElementCopiesMap(Project, Project); IEnumerable <ExolutioObject> allModelItems = ModelIterator.GetAllModelItems(branchedVersion); List <ExolutioObject> exolutioObjects = allModelItems.ToList(); elementCopiesMap.PrepareGuids(exolutioObjects); elementCopiesMap.PrepareGuid(branchedVersion); branchedVersion.FillCopy(newProjectVersion, newProjectVersion, elementCopiesMap); Project.ProjectVersions.Add(newProjectVersion); foreach (KeyValuePair <IVersionedItem, IVersionedItem> keyValuePair in elementCopiesMap) { RegisterVersionLink(branchedVersion.Version, newVersion, keyValuePair.Key, keyValuePair.Value); } branching = false; return(newProjectVersion); }
/// <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; }
public Project SeparateVersion(ProjectVersion projectVersion, bool keepGuids) { Project separatedProject = new Project(); separatedProject.InitNewEmptyProject(false); ElementCopiesMap elementCopiesMap = new ElementCopiesMap(Project, separatedProject); elementCopiesMap.KeepGuids = keepGuids; IEnumerable <ExolutioObject> allModelItems = ModelIterator.GetAllModelItems(projectVersion); List <ExolutioObject> exolutioObjects = allModelItems.ToList(); elementCopiesMap.PrepareGuids(exolutioObjects); elementCopiesMap.PrepareGuid(projectVersion); projectVersion.FillCopy(separatedProject.SingleVersion, separatedProject.SingleVersion, elementCopiesMap); return(separatedProject); }
public void EmbedVersion(ProjectVersion embededVersion, Version newVersion, Version branchedFrom, bool keepGuids, bool createVersionLinks) { newVersion.BranchedFrom = branchedFrom; Versions.Add(newVersion); ProjectVersion newProjectVersion = new ProjectVersion(Project); newProjectVersion.Version = newVersion; ElementCopiesMap elementCopiesMap = new ElementCopiesMap(embededVersion.Project, Project); elementCopiesMap.KeepGuids = keepGuids; IEnumerable <ExolutioObject> allModelItems = ModelIterator.GetAllModelItems(embededVersion); List <ExolutioObject> exolutioObjects = allModelItems.ToList(); elementCopiesMap.PrepareGuids(exolutioObjects); elementCopiesMap.PrepareGuid(embededVersion); Project.ProjectVersions.Add(newProjectVersion); embededVersion.FillCopy(newProjectVersion, newProjectVersion, elementCopiesMap); if (createVersionLinks) { foreach (KeyValuePair <IVersionedItem, IVersionedItem> kvp in elementCopiesMap) { IVersionedItem fromEmbedded = kvp.Key; IVersionedItem newlyCreated = kvp.Value; ExolutioObject previousObject; if (Project.TryTranslateObject(fromEmbedded.ID, out previousObject) && previousObject is IVersionedItem) { if (Project.mappingDictionary.ContainsKey(previousObject.ID) && Project.mappingDictionary.ContainsKey(newlyCreated.ID)) { RegisterVersionLink(((IVersionedItem)previousObject).Version, newVersion, (IVersionedItem)previousObject, newlyCreated); } } } } }