Beispiel #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;
        }
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && (psmAssociation.Lower != psmAssociationO.Lower || psmAssociation.Upper != psmAssociationO.Upper));
        }
Beispiel #3
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMContentModel psmContentModel  = (PSMContentModel)candidate;
            PSMContentModel psmContentModelO = (PSMContentModel)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && psmContentModel.Type != psmContentModelO.Type);
        }
Beispiel #4
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && psmAttribute.AttributeType != psmAttributeO.AttributeType);
        }
Beispiel #5
0
        //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
        }
Beispiel #6
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && (psmAttribute.Lower != psmAttributeO.Lower || psmAttribute.Upper != psmAttributeO.Upper));
        }
Beispiel #7
0
 public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
 {
     return(new ClassRenamedInstance(candidate, oldVersion, newVersion)
     {
         OldName = candidate.GetInVersion(oldVersion).Name, NewName = candidate.Name
     });
 }
Beispiel #8
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMClass psmClass  = (PSMClass)candidate;
            PSMClass psmClassO = (PSMClass)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) && psmClassO.IsStructuralRepresentative && !psmClass.IsStructuralRepresentative);
        }
Beispiel #9
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMContentModel psmContentModel  = (PSMContentModel)candidate;
            PSMContentModel psmContentModelO = (PSMContentModel)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) &&
                   !AreLinked(psmContentModelO.ParentAssociation, psmContentModel.ParentAssociation));
        }
Beispiel #10
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMClass psmClass  = (PSMClass)candidate;
            PSMClass psmClassO = (PSMClass)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) &&
                   !AreLinked(psmClassO.ParentAssociation, psmClass.ParentAssociation));
        }
Beispiel #11
0
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) &&
                   !AreLinked(psmAttributeO.PSMClass, psmAttribute.PSMClass));
        }
        public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(ExistingTest(candidate, oldVersion, newVersion) &&
                   !AreLinked(psmAssociationO.Parent, psmAssociation.Parent));
        }
Beispiel #13
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute = ((PSMAttribute)candidate);

            return(new AttributeAddedInstance(candidate, oldVersion, newVersion)
            {
                Parent = psmAttribute.PSMClass, Index = psmAttribute.Index
            });
        }
Beispiel #14
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMClass psmClass = ((PSMClass)candidate);

            return(new ClassAddedInstance(candidate, oldVersion, newVersion)
            {
                ParentAssociation = psmClass.ParentAssociation
            });
        }
Beispiel #15
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMClass psmClassO = (PSMClass)candidate.GetInVersion(oldVersion);

            return(new SRRemovedInstance(candidate, oldVersion, newVersion)
            {
                OldRepresentedPSMClass = psmClassO.RepresentedClass
            });
        }
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation = ((PSMAssociation)candidate);

            return(new AssociationAddedInstance(candidate, oldVersion, newVersion)
            {
                Parent = psmAssociation.Parent, Index = psmAssociation.Index
            });
        }
Beispiel #17
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMContentModel psmContentModel = ((PSMContentModel)candidate);

            return(new ContentModelAddedInstance(candidate, oldVersion, newVersion)
            {
                ParentAssociation = psmContentModel.ParentAssociation
            });
        }
Beispiel #18
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMClass psmClass = (PSMClass)candidate;

            return(new SRIntroducedInstance(candidate, oldVersion, newVersion)
            {
                RepresentedPSMClass = psmClass.RepresentedClass
            });
        }
Beispiel #19
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMClass psmClass  = (PSMClass)candidate;
            PSMClass psmClassO = (PSMClass)candidate.GetInVersion(oldVersion);

            return(new ClassMovedInstance(candidate, oldVersion, newVersion)
            {
                NewParentAssociation = psmClass.ParentAssociation,
                OldParentAssociation = psmClassO.ParentAssociation
            });
        }
Beispiel #20
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(new AttributeXFormChangedInstance(candidate, oldVersion, newVersion)
            {
                OldXFormElement = psmAttributeO.Element,
                NewXFormElement = psmAttribute.Element
            });
        }
Beispiel #21
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(new AttributeTypeChangedInstance(candidate, oldVersion, newVersion)
            {
                OldType = psmAttributeO.AttributeType,
                NewType = psmAttribute.AttributeType
            });
        }
Beispiel #22
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMContentModel psmContentModel  = (PSMContentModel)candidate;
            PSMContentModel psmContentModelO = (PSMContentModel)candidate.GetInVersion(oldVersion);

            return(new ContentModelMovedInstance(candidate, oldVersion, newVersion)
            {
                NewParentAssociation = psmContentModel.ParentAssociation,
                OldParentAssociation = psmContentModelO.ParentAssociation
            });
        }
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(new AssociationIndexChangedInstance(candidate, oldVersion, newVersion)
            {
                OldIndex = psmAssociationO.Index,
                NewIndex = psmAssociation.Index
            });
        }
Beispiel #24
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMContentModel psmContentModel  = (PSMContentModel)candidate;
            PSMContentModel psmContentModelO = (PSMContentModel)candidate.GetInVersion(oldVersion);

            return(new ContentModelTypeChangedInstance(candidate, oldVersion, newVersion)
            {
                OldType = psmContentModelO.Type,
                NewType = psmContentModel.Type
            });
        }
Beispiel #25
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(new AttributeMovedInstance(candidate, oldVersion, newVersion)
            {
                NewParent = psmAttribute.PSMClass,
                OldParent = psmAttributeO.PSMClass,
                NewIndex = psmAttribute.Index,
                OldIndex = psmAttributeO.Index
            });
        }
Beispiel #26
0
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAttribute psmAttribute  = (PSMAttribute)candidate;
            PSMAttribute psmAttributeO = (PSMAttribute)candidate.GetInVersion(oldVersion);

            return(new AttributeCardinalityChangedInstance(candidate, oldVersion, newVersion)
            {
                OldLower = psmAttributeO.Lower,
                OldUpper = psmAttributeO.Upper,
                NewLower = psmAttribute.Lower,
                NewUpper = psmAttribute.Upper
            });
        }
        public new static ChangeInstance CreateInstance(PSMComponent candidate, Version oldVersion, Version newVersion)
        {
            PSMAssociation psmAssociation  = (PSMAssociation)candidate;
            PSMAssociation psmAssociationO = (PSMAssociation)candidate.GetInVersion(oldVersion);

            return(new AssociationCardinalityChangedInstance(candidate, oldVersion, newVersion)
            {
                OldLower = psmAssociationO.Lower,
                OldUpper = psmAssociationO.Upper,
                NewLower = psmAssociation.Lower,
                NewUpper = psmAssociation.Upper
            });
        }
Beispiel #28
0
        void ResolveVersion(string versionName)
        {
            Schema         targetSchema   = this.Bridge.Schema;
            VersionManager versionManager = this.Bridge.Schema.Project.VersionManager;
            Version        sourceVersion  = versionManager.Versions.SingleOrDefault(v => v.Label == versionName);

            if (sourceVersion == null)
            {
                Errors.AddError(new ErrorItem(string.Format("Source version `{0}` not found in the project.", versionName)));
            }
            SourceVersion = sourceVersion;
            if (!targetSchema.ExistsInVersion(sourceVersion))
            {
                Errors.AddError(new ErrorItem(string.Format("Schema '{0}' does not exist in version `{1}`.", targetSchema, versionName)));
            }
            Schema sourceSchema = targetSchema.GetInVersion(sourceVersion);

            this.Bridge.TranslateSchema(sourceSchema, true);

            foreach (Component componentT in targetSchema.SchemaComponents)
            {
                if (componentT.ExistsInVersion(SourceVersion) && (componentT is PIMClass || componentT is PSMClass || componentT is PSMContentModel))
                {
                    Component componentS = componentT.GetInVersion(SourceVersion);
                    {
                        Classifier classifierT = Bridge.Find(componentT);
                        Classifier classifierS = Bridge.Find(componentS);

                        Operation prevOp = new Operation(@"prev", true, classifierS);
                        prevOp.Tag = new PrevOperationTag()
                        {
                            SourceVersionClassifier = classifierS, TargetVersionClassifier = classifierT
                        };
                        classifierT.Operations.Add(prevOp);

                        Operation nextOp = new Operation(@"next", true, classifierT);
                        nextOp.Tag = new NextOperationTag()
                        {
                            SourceVersionClassifier = classifierS, TargetVersionClassifier = classifierT
                        };
                        classifierS.Operations.Add(nextOp);
                    }
                }
            }
        }
Beispiel #29
0
 private static void testConstructs <TPSMComponent>(IEnumerable <TPSMComponent> components,
                                                    Version oldVersion, Version newVersion, DetectedChangeInstancesSet changeInstancesSet, EChangePredicateScope scope)
     where TPSMComponent : ExolutioObject
 {
     foreach (TPSMComponent component in components)
     {
         if (changePredicatesByScope.ContainsKey(scope))
         {
             foreach (Type type in changePredicatesByScope[scope])
             {
                 object[] testParams = new object[] { component, oldVersion, newVersion };
                 bool     result     = (bool)testMethods[type].Invoke(null, testParams);
                 if (result)
                 {
                     changeInstancesSet.CreateSubCollectionIfNeeded(type);
                     ChangeInstance instance = (ChangeInstance)createInstanceMethods[type].Invoke(null, testParams);
                     changeInstancesSet[type].Add(instance);
                 }
             }
         }
     }
 }
Beispiel #30
0
 public new static bool TestCandidate(PSMComponent candidate, Version oldVersion, Version newVersion)
 {
     return(RemovalTest(candidate, oldVersion, newVersion));
 }