コード例 #1
0
        public XDocument GetRelaxNgSchema()
        {
            XElement rngSchema;

            RelaxNGXmlSyntaxWriter.CreateInitialDeclarations(out rngSchema);
            string comment = string.Format(" generated by eXolutio on {0} {1} from {2}/{3}. ", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), PSMSchema.Project.Name, PSMSchema.Caption);

            RelaxNGXmlSyntaxWriter.AddComment(rngSchema, comment);

            var orderedNodes = ModelIterator.OrderBFS(PSMSchema.PSMNodes.Cast <PSMComponent>().ToList());

            AddStartElements(rngSchema);

            foreach (PSMAssociationMember node in orderedNodes)
            {
                if (node is PSMClass)
                {
                    TranslateClass(rngSchema, (PSMClass)node);
                }
            }

            ReportUsedCustomSimpleTypes();

            XDocument doc = RelaxNGXmlSyntaxWriter.GetFinalResult();

            return(doc);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
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
        }
コード例 #4
0
ファイル: Project.cs プロジェクト: mff-uk/exolutio
        /// <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;
        }
コード例 #5
0
        public void TranslateSchema(Schema pimSchema, bool translateAsOldVersion = false)
        {
            List <PIMBridgeClass> classToProcess = new List <PIMBridgeClass>();
            //vytvoreni prazdnych trid
            //musi predchazet propertam a associacim, aby se neodkazovalo na neexistujici typy

            // JM: usporadani trid tak, aby predkove byli zalozeni pred potomky
            List <PIMClass> pimClassesHierarchy = ModelIterator.GetPIMClassesInheritanceBFS((PIMSchema)pimSchema).ToList();

            foreach (PIMClass pimClass in pimClassesHierarchy)
            {
                // JM: parent - predek v PIM modelu
                PIMBridgeClass parent       = pimClass.GeneralizationAsSpecific != null ? PIMClasses[pimClass.GeneralizationAsSpecific.General] : null;
                string         nameOverride = translateAsOldVersion ? pimClass.Name + @"_old" : null;
                PIMBridgeClass newClass     = new PIMBridgeClass(TypesTable, TypesTable.Library.RootNamespace, pimClass, parent, nameOverride);

                //  tt.Library.RootNamespace.NestedClassifier.Add(newClass);
                TypesTable.RegisterType(newClass);
                classToProcess.Add(newClass);
                //Hack
                newClass.Tag = pimClass;
                //Registred to find
                PIMClasses.Add(pimClass, newClass);
            }

            //Translates classes members
            classToProcess.ForEach(cl => cl.TranslateMembers());
        }
コード例 #6
0
        /// <summary>
        /// Build the properties.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual string BuildPropertiesForModel(ModelContext ctx, Model model)
        {
            IncrementIndent(2);
            StringBuilder buffer = new StringBuilder();

            // Build properties that belog directly to the model.
            BuildProperties(ctx, model, buffer);

            ModelIterator iterator = new ModelIterator();

            iterator.OnCompositeProcess += (mctx, m, composition) =>
            {
                BuildProperty(composition.ModelRef, new PropertyInfo()
                {
                    Name = composition.ModelRef.Name
                }, false, buffer);
                return(true);
            };
            iterator.OnIncludeProcess += (mctx, m, include) =>
            {
                BuildProperties(ctx, include.ModelRef, buffer);
                return(true);
            };
            iterator.Process(ctx, model.Name);
            DecrementIndent(2);
            string props = buffer.ToString();

            return(props);
        }
コード例 #7
0
ファイル: PSMPath.cs プロジェクト: mff-uk/exolutio
        public override string ToXPath()
        {
            if (Association.IsNamed)
            {
                if (IsUp)
                {
                    bool useFullParentStep = false;
                    if (From is PSMClass)
                    {
                        useFullParentStep = ((PSMClass)From).GetIncomingNonTreeAssociations().Count() > 0;
                    }
                    if (useFullParentStep)
                    {
                        //HACK : this works for tree-like schemas, could cause problems where non-tree features appear (inheritance, SR, non-tree associations)
                        IEnumerable <PSMAssociation> associations = ModelIterator.GetAncestorAssociations(To).Where(a => a.IsNamed);
                        if (associations.Count() > 0)
                        {
                            return(string.Format(@"/parent::{0}", associations.First().Name));
                        }
                    }

                    return(string.Format(@"/.."));
                }
                else
                {
                    return(string.Format(@"/{0}", Association.Name));
                }
            }
            else
            {
                return(string.Empty);
            }
        }
コード例 #8
0
        /// <summary>
        /// Process the model, by handling all it's properties, compositions, and includes and calling
        /// the delegate given  to handle the properties.
        /// </summary>
        /// <param name="propHandler"></param>
        public virtual void Process(Action <string, Model, PropertyInfo> propHandler)
        {
            ModelIterator iterator = new ModelIterator();

            // Now add the columns of the model itself.
            iterator.OnPropertyProcess += new Func <ModelContext, Model, PropertyInfo, bool>((ctx, model, prop) =>
            {
                string objProp = string.Empty;
                if (model.Name != _modelName)
                {
                    objProp = model.Name;
                }

                if (prop.Name != "Id")
                {
                    propHandler(objProp, model, prop);
                }
                return(true);
            });

            // Now add the columns of the composite model
            iterator.OnCompositeProcess += new Func <ModelContext, Model, Composition, bool>((ctx, model, composition) =>
            {
                iterator.ProcessModel(ctx, composition.ModelRef);
                return(true);
            });

            // Now add the columns of the composite model
            iterator.OnIncludeProcess += new Func <ModelContext, Model, Include, bool>((ctx, model, include) =>
            {
                iterator.ProcessModel(ctx, include.ModelRef);
                return(true);
            });
            iterator.Process(_ctx, _modelName);
        }
コード例 #9
0
        private void ClassifyNodes(DetectedChangeInstancesSet changeInstances, PSMSchema psmSchema)
        {
            FindRedNodes(changeInstances);

            #region blue and green nodes

            Queue <PSMAssociationMember> toDo = new Queue <PSMAssociationMember>();
            foreach (PSMAssociationMember m in ModelIterator.GetLeaves(psmSchema))
            {
                if (changeInstances.RedNodes.Contains(m))
                {
                    toDo.Enqueue(m);
                }
            }

            foreach (PSMAssociationMember redNode in changeInstances.RedNodes.OfType <PSMAssociationMember>())
            {
                toDo.Enqueue(redNode);
            }

            foreach (PSMAttribute psmAttribute in changeInstances.RedNodes.OfType <PSMAttribute>())
            {
                if (!changeInstances.RedNodes.Contains(psmAttribute.PSMClass))
                {
                    changeInstances.BlueNodes.AddIfNotContained(psmAttribute.PSMClass);
                    toDo.Enqueue(psmAttribute.PSMClass);
                }
            }

            while (!toDo.IsEmpty())
            {
                PSMAssociationMember m = toDo.Dequeue();
                if (m.ParentAssociation != null)
                {
                    if (!changeInstances.RedNodes.Contains(m.ParentAssociation.Parent) &&
                        !changeInstances.BlueNodes.Contains(m.ParentAssociation.Parent))
                    {
                        changeInstances.BlueNodes.Add(m.ParentAssociation.Parent);
                        if (!(m.ParentAssociation.Parent is PSMSchemaClass))
                        {
                            toDo.Enqueue(m.ParentAssociation.Parent);
                        }
                    }
                }
            }

            changeInstances.GreenNodes.AddRange(psmSchema.SchemaComponents.Where(c => !(c is PSMAssociation) && !(c is PSMSchemaClass) &&
                                                                                 !changeInstances.RedNodes.Contains(c) && !changeInstances.BlueNodes.Contains(c)).Cast <PSMComponent>());

            foreach (PSMComponent psmComponent in changeInstances.AllNodes)
            {
                if (!psmComponent.ExistsInVersion(changeInstances.OldVersion))
                {
                    changeInstances.AddedNodes.Add(psmComponent);
                }
            }

            #endregion
        }
コード例 #10
0
        public override void Execute(object parameter = null)
        {
            PSMClass psmClass = ((PSMClass)ScopeObject);

            if (psmClass.IsStructuralRepresentative)
            {
                Diagram diagram = ModelIterator.GetDiagramForComponent(psmClass.RepresentedClass);
                Current.MainWindow.FocusComponent(diagram, psmClass.RepresentedClass);
            }
        }
コード例 #11
0
        public XDocument GetSchematronSchema([NotNull] TranslationSettings translationSettings)
        {
            XDocument doc       = new XDocument(new XDeclaration("1.0", "utf-8", null));
            XElement  schSchema = doc.SchematronSchema();
            XComment  comment   = new XComment(string.Format(" Generated by eXolutio on {0} {1} from {2}/{3}. ", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), PSMSchema.Project.Name, PSMSchema.Caption));

            schSchema.Add(comment);

            Dictionary <PSMClass, List <PatternInfo> > patterns = new Dictionary <PSMClass, List <PatternInfo> >();

            foreach (OCLScript oclScript in PSMSchema.OCLScripts)
            {
                // creates patterns, some patterns will be declared abstract
                TranslateScript(schSchema, oclScript, translationSettings, ref patterns);
            }

            #region create instance patterns
            foreach (PSMClass contextClass in PSMSchema.PSMClasses)
            {
                foreach (PSMClass ancestorClass in ModelIterator.GetGeneralizationsWithSelf(contextClass))
                {
                    if (patterns.ContainsKey(ancestorClass) && (ancestorClass != contextClass ||
                                                                ancestorClass.GeneralizationsAsGeneral.Count > 0))
                    {
                        foreach (PatternInfo pattern in patterns[ancestorClass])
                        {
                            if (ancestorClass != contextClass)
                            {
                                schSchema.Add(new XComment(string.Format("instance pattern for {0}'s ancestor {1}", contextClass, ancestorClass.Name)));
                            }
                            else
                            {
                                schSchema.Add(new XComment(string.Format("instance pattern for {0}", contextClass)));
                            }
                            XElement instancePattern   = schSchema.SchematronPattern();
                            string   instancePatternId = string.Format("{0}-as-{1}", contextClass.Name, pattern.PatternName);
                            instancePattern.AddAttributeWithValue("id", instancePatternId);
                            instancePattern.AddAttributeWithValue("is-a", pattern.PatternName);
                            instancePattern.SchematronParam(pattern.ContextVariableName, contextClass.GetXPathFull(false).ToString());
                        }
                    }
                }
            }

            #endregion

            PostprocessLogMessages();

            return(doc);
        }
コード例 #12
0
        private static void CheckPSMSchema(PSMSchema psmSchema)
        {
            CheckSchema(psmSchema);

            CollectionAssert.AllItemsAreNotNull(psmSchema.Roots);
            foreach (PSMAssociationMember psmAssociationMember in psmSchema.Roots)
            {
                Assert.IsNull(psmAssociationMember.ParentAssociation);
            }

            foreach (PSMComponent psmComponent in ModelIterator.GetPSMComponents(psmSchema))
            {
                Assert.AreEqual(psmComponent.PSMSchema, psmSchema);
            }

            foreach (PSMSchemaReference psmSchemaReference in psmSchema.PSMSchemaReferences)
            {
                CheckPSMSchemaReference(psmSchemaReference);
            }

            foreach (PSMComponent psmComponent in ModelIterator.GetPSMComponents(psmSchema))
            {
                if (psmComponent is PSMAssociation)
                {
                    CheckPSMAssociation((PSMAssociation)psmComponent);
                }
                if (psmComponent is PSMClass)
                {
                    CheckPSMClass((PSMClass)psmComponent);
                }
                if (psmComponent is PSMAttribute)
                {
                    CheckPSMAttribute((PSMAttribute)psmComponent);
                }
                if (psmComponent is PSMContentModel)
                {
                    CheckPSMContentModel((PSMContentModel)psmComponent);
                }
                if (psmComponent is PSMSchemaClass)
                {
                    CheckPSMSchemaClass((PSMSchemaClass)psmComponent);
                }
            }
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        private static void CheckPIMSchema(PIMSchema pimSchema)
        {
            CheckSchema(pimSchema);

            foreach (PIMClass pimClass in pimSchema.PIMClasses)
            {
                CheckPIMClass(pimClass);
            }

            foreach (PIMAssociation pimAssociation in pimSchema.PIMAssociations)
            {
                CheckPIMAssociation(pimAssociation);
            }

            foreach (PIMComponent pimComponent in ModelIterator.GetPIMComponents(pimSchema))
            {
                Assert.AreEqual(pimComponent.PIMSchema, pimSchema);
            }
        }
コード例 #15
0
        public bool TestSchemaClassChildrenAreClasses(PSMSchema psmSchema)
        {
            bool result = true;

            foreach (PSMAssociationMember psmAssociationMember in ModelIterator.GetChildNodes(psmSchema.PSMSchemaClass))
            {
                if (!(psmAssociationMember is PSMClass))
                {
                    ILogMessage message = Log.AddWarningFormat("Child nodes of a schema class must be classes. Violated by {0}.", psmAssociationMember);
                    if (messageDict.ContainsKey(psmSchema))
                    {
                        message.RelatedMessage = messageDict[psmSchema];
                    }
                    LastViolatingComponent = psmAssociationMember;
                    result = false;
                }
            }

            return(result);
        }
コード例 #16
0
        public override void LoadSchemaToDiagram(Schema schema, bool bindingOnly = false)
        {
            base.LoadSchemaToDiagram(schema, bindingOnly);
            PIMSchema pimSchema = (PIMSchema)schema;

            if (!bindingOnly)
            {
                Caption = pimSchema.Caption;

                foreach (PIMComponent pimComponent in ModelIterator.GetPIMComponents(pimSchema))
                {
                    if (pimComponent.IsOfType(typeof(PIMClass), typeof(PIMAssociation)))
                    {
                        Components.Add(pimComponent);
                    }
                }
            }

            PIMSchema.ComponentRemoved += Components_ComponentRemoved;
        }
コード例 #17
0
        public static void FoldChildrenRecursive(PSMComponent parent, DiagramView activeDiagramView, EFoldingAction foldingAction)
        {
            IEnumerable <PSMComponent> childComponents = ModelIterator.GetPSMChildren(parent, false, true);

            foreach (PSMComponent childComponent in childComponents)
            {
                if (!activeDiagramView.RepresentantsCollection.IsElementPresent(childComponent))
                {
                    continue;
                }
                ComponentViewBase childView = activeDiagramView.RepresentantsCollection[childComponent];
                bool proceed = true;
                if (childView.DownCastSatisfies <IComponentViewBaseVH>(c => c.ViewHelper.DownCastSatisfies <IFoldableComponentViewHelper>(
                                                                           fvh => (fvh.IsFolded && foldingAction == EFoldingAction.Fold) || fvh.IsFolded && foldingAction == EFoldingAction.Unfold)))
                {
                    proceed = false;
                }
                FoldRecursive(childComponent, activeDiagramView, proceed, foldingAction);
            }
        }
コード例 #18
0
 private static void AddGroupMembersRecursive(PSMComponent referencedNode, ref List <PSMComponent> groupMembers)
 {
     foreach (PSMComponent component in ModelIterator.GetPSMChildren(referencedNode, true))
     {
         if (component is PSMAttribute)
         {
             groupMembers.Add(component);
         }
         if (component is PSMAssociationMember)
         {
             PSMAssociationMember associationMember = (PSMAssociationMember)component;
             if (associationMember.ParentAssociation.IsNamed)
             {
                 groupMembers.Add(associationMember);
             }
             else
             {
                 AddGroupMembersRecursive(associationMember, ref groupMembers);
             }
         }
     }
 }
コード例 #19
0
        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);
                        }
                    }
                }
            }
        }
コード例 #20
0
ファイル: XsdSchemaGenerator.cs プロジェクト: mff-uk/exolutio
        public XDocument GetXsd()
        {
            XDocument doc       = new XDocument(new XDeclaration("1.0", "utf-8", null));
            XElement  xsdSchema = doc.XsdSchema();
            XComment  comment   = new XComment(string.Format(" generated by eXolutio on {0} {1} from {2}/{3}. ", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), PSMSchema.Project.Name, PSMSchema.Caption));

            xsdSchema.Add(comment);
            var orderedNodes = ModelIterator.OrderBFS(PSMSchema.PSMNodes.Cast <PSMComponent>().ToList());

            AddGlobalElements(xsdSchema);

            foreach (PSMAssociationMember node in orderedNodes)
            {
                if (node is PSMClass)
                {
                    TranslateClass(xsdSchema, (PSMClass)node);
                }
            }

            AddSimpleTypes(xsdSchema);

            return(doc);
        }
コード例 #21
0
        public override XDocument Translate(PSMSchema schema, string schemaLocation = null)
        {
            Schema = schema;

            if (RootForGeneration == null)
            {
                IEnumerable <PSMAssociationMember> rootCandidates = null;

                if (Schema.PSMSchemaClass != null)
                {
                    rootCandidates = ModelIterator.GetLabeledChildNodes(Schema.PSMSchemaClass);
                }

                if (rootCandidates == null || rootCandidates.Count() == 0)
                {
                    Log.AddError("No possible root element. Schema class containing labeled association needed. ");
                    return(null);
                }

                RootForGeneration = rootCandidates.ChooseOneRandomly();
            }

            DataGeneratorContext context = new DataGeneratorContext();

            context.RootCreated = false;
            TranslateComments(null, context);
            TranslateAssociation(RootForGeneration.ParentAssociation, context);

            if (!String.IsNullOrEmpty(schemaLocation))
            {
                XNamespace schemaInstance = "http://www.w3.org/2001/XMLSchema-instance";
                context.Document.Root.Add(new XAttribute(XNamespace.Xmlns + "xsi", schemaInstance.NamespaceName));
                context.Document.Root.Add(new XAttribute(schemaInstance + "noNamespaceSchemaLocation", schemaLocation));
            }
            return(context.Document);
        }
コード例 #22
0
        public override Path GetXPathFull(bool followGeneralizations = true)
        {
            UnionPath unionPath = new UnionPath(PSMSchema);

            List <Path> nonRecursionPaths = new List <Path>();

            #region parent track
            if (ParentAssociation != null)
            {
                Path parentPath = ParentAssociation.GetXPathFull(followGeneralizations).DeepCopy();
                nonRecursionPaths.Add(parentPath);
                unionPath.ComponentPaths.Add(parentPath);
            }
            #endregion

            #region generalizations tracks
            if (followGeneralizations)
            {
                foreach (PSMGeneralization generalization in this.GeneralizationsAsGeneral)
                {
                    Path specificClassPath = generalization.Specific.GetXPathFull(followGeneralizations);
                    unionPath.ComponentPaths.Add(specificClassPath);
                    nonRecursionPaths.Add(specificClassPath);
                }
            }

            #endregion

            #region  first find cycles

            List <PSMComponent> componentsParticipatingInCycles = new List <PSMComponent>();
            Dictionary <PSMAssociation, List <ModelIterator.PSMCycle> > cyclesForAssociations
                = new Dictionary <PSMAssociation, List <ModelIterator.PSMCycle> >();
            foreach (PSMAssociation association in ChildPSMAssociations)
            {
                List <ModelIterator.PSMCycle> cycles = ModelIterator.GetPSMCyclesStartingInAssociation(association,
                                                                                                       followGeneralizationsWhereAsGeneral
                                                                                                       : false,
                                                                                                       followGeneralizationsWhereAsSpecific
                                                                                                       : true);
                cyclesForAssociations.Add(association, cycles);

                foreach (ModelIterator.PSMCycle cycle in cycles)
                {
                    componentsParticipatingInCycles.AddRange(cycle);
                }
            }

            #endregion

            #region process incoming NTAs, which then will be also used as prefixes for cycles

            foreach (PSMAssociation incomingNTA in GetIncomingNonTreeAssociations())
            {
                if (componentsParticipatingInCycles.Contains(incomingNTA))
                {
                    continue;
                }
                Path ntaPath = incomingNTA.GetXPathFull(followGeneralizations);
                unionPath.ComponentPaths.Add(ntaPath);
                nonRecursionPaths.Add(ntaPath);
            }

            #endregion

            #region process cycles

            List <string> usedDescendants = new List <string>();
            foreach (KeyValuePair <PSMAssociation, List <ModelIterator.PSMCycle> > kvp in cyclesForAssociations)
            {
                PSMAssociation association           = kvp.Key;
                List <ModelIterator.PSMCycle> cycles = kvp.Value;

                foreach (ModelIterator.PSMCycle cycle in cycles)
                {
                    PSMAssociation lastNamedAssociation = cycle.GetLastNamedAssociation();
                    string         descendant           = lastNamedAssociation != null ? lastNamedAssociation.Name : null;
                    if (descendant != null && !usedDescendants.Contains(descendant))
                    {
                        foreach (Path nonRecursionPath in nonRecursionPaths)
                        {
                            Path       path       = nonRecursionPath.DeepCopy();
                            SimplePath simplePath = path as SimplePath;
                            bool       optimized  = false;
                            if (simplePath != null && simplePath.Steps.Any())
                            {
                                Step laststep = simplePath.Steps.Last();
                                if (laststep.NodeTest == descendant && laststep.Axis == Axis.child)
                                {
                                    laststep.Axis = Axis.descendant;
                                    optimized     = true;
                                }
                            }
                            if (!optimized)
                            {
                                Step step = new Step {
                                    Axis = Axis.descendant, NodeTest = descendant
                                };
                                path.AddStep(step);
                            }
                            unionPath.ComponentPaths.Add(path);
                        }
                        usedDescendants.Add(descendant);
                    }
                }
            }

            #endregion

            if (unionPath.ComponentPaths.Count == 1)
            {
                return(unionPath.ComponentPaths[0]);
            }
            else
            {
                return(unionPath);
            }
        }
コード例 #23
0
        /// <summary>
        /// <para>
        /// Returns a name for a top level template for a given node in a PSM tree.
        /// The name follows the tree structure, dashes are used as tree separators,
        /// names of the nodes are used in each step (names of the associatiosn are ignored).
        /// </para>
        /// <para>
        /// Names for nodes in the schema class tree start with "ROOT", other names start with "TOP"
        /// </para>
        /// </summary>
        /// <returns></returns>
        public string SuggestName(PSMComponent node, bool elementsTemplate, bool attributesTemplate)
        {
            string result;

            if (PSMSchema.TopClasses.Contains(node))
            {
                result = "TOP-" + node.Name;
            }
            else if (PSMSchema.Roots.Contains(node))
            {
                result = "ROOT" + node.Name;
            }
            else
            {
                if (node is PSMContentModel)
                {
                    PSMContentModel cm            = (PSMContentModel)node;
                    string          distinguisher = String.Empty;
                    if (!cm.ParentAssociation.IsNamed)
                    {
                        List <PSMContentModel> withSiblings = ModelIterator.GetPSMChildren(cm.ParentAssociation.Parent).OfType <PSMContentModel>().ToList();
                        if (withSiblings.Count(s => s.Type == cm.Type) > 1)
                        {
                            distinguisher = (withSiblings.Where(c => c.Type == cm.Type).ToList().IndexOf(cm) + 1).ToString();
                        }
                    }
                    else
                    {
                        distinguisher = cm.ParentAssociation.Name;
                    }
                    switch (cm.Type)
                    {
                    case PSMContentModelType.Sequence:
                        result = SuggestName(cm.ParentAssociation.Parent, false, false) + "-" + "SEQ" + (!String.IsNullOrEmpty(distinguisher) ? distinguisher : String.Empty);
                        break;

                    case PSMContentModelType.Choice:
                        result = SuggestName(cm.ParentAssociation.Parent, false, false) + "-" + "CH" + (!String.IsNullOrEmpty(distinguisher) ? distinguisher : String.Empty);
                        break;

                    case PSMContentModelType.Set:
                        result = SuggestName(cm.ParentAssociation.Parent, false, false) + "-" + "SET" + (!String.IsNullOrEmpty(distinguisher) ? distinguisher : String.Empty);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else if (node is PSMClass)
                {
                    PSMClass psmClass = (PSMClass)node;
                    result = SuggestName(psmClass.ParentAssociation.Parent, false, false) + "-" + node.Name;
                }
                else if (node is PSMAttribute)
                {
                    PSMAttribute psmAttribute = (PSMAttribute)node;
                    result = SuggestName(psmAttribute.PSMClass, false, false) + "-" + psmAttribute.Name;
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (elementsTemplate)
            {
                return(result + "-ELM");
            }
            if (attributesTemplate)
            {
                return(result + "-ATT");
            }
            return(result);
        }
コード例 #24
0
ファイル: MainPage.xaml.cs プロジェクト: mff-uk/exolutio
        public void FocusComponent(Component component, bool activateDiagramTab = true)
        {
            Diagram diagram = ModelIterator.GetDiagramForComponent(component);

            Current.MainWindow.FocusComponent(diagram, component, activateDiagramTab);
        }
コード例 #25
0
        private void CurrentParentAsRedNode(List <PSMComponent> redNodes, PSMComponent componentNewVersion)
        {
            PSMComponent currentParent =
                componentNewVersion is PSMAssociation ? ((PSMAssociation)componentNewVersion).Parent : ModelIterator.GetPSMParent(componentNewVersion, true);

            if (currentParent != null)
            {
                redNodes.AddIfNotContained(currentParent);
            }
        }
コード例 #26
0
ファイル: PSMBridge.cs プロジェクト: mff-uk/exolutio
        public void TranslateSchema(Schema schema, bool translateAsOldVersion = false)
        {
            PSMSchema psmSchema = (PSMSchema)schema;
            IEnumerable <AttributeType> attTypes = psmSchema.GetAvailablePSMTypes();

            foreach (AttributeType type in attTypes)
            {
                if (translateAsOldVersion && schema.Project.PSMBuiltInTypes.Contains(type))
                {
                    continue;
                }
                Classifier existsCl;
                if (Library.RootNamespace.NestedClassifier.TryGetValue(type.Name, out existsCl))
                {
                    PSMAttributeType.Add(type, existsCl);
                    continue;
                }
                Classifier parent;
                if (type.BaseType == null)
                {
                    parent = Library.Any;
                }
                else
                {
                    if (Library.RootNamespace.NestedClassifier.TryGetValue(type.BaseType.Name, out parent) == false)
                    {
                        parent = Library.Any;
                    }
                }
                Classifier newClassifier = new Classifier(Library.TypeTable, Library.TypeTable.Library.RootNamespace, type.Name, parent);
                Library.TypeTable.RegisterType(newClassifier);
                //    Library.RootNamespace.NestedClassifier.Add(newClassifier);
                PSMAttributeType.Add(type, newClassifier);
            }

            List <PSMBridgeClass> classToProcess = new List <PSMBridgeClass>();
            // JM: usporadani trid tak, aby predkove byli zalozeni pred potomky
            List <PSMClass> psmClassesHierarchy = ModelIterator.GetPSMClassesInheritanceBFS(psmSchema).ToList();

            foreach (PSM.PSMClass psmClass in psmClassesHierarchy)
            {
                // JM: parent - predek v PSM modelu
                PSMBridgeClass parent       = psmClass.GeneralizationAsSpecific != null ? PSMAssociationMembers[psmClass.GeneralizationAsSpecific.General] : null;
                string         nameOverride = translateAsOldVersion ? psmClass.Name + @"_old" : null;
                PSMBridgeClass newClass     = new PSMBridgeClass(Library.TypeTable, Library.TypeTable.Library.RootNamespace, psmClass, parent, nameOverride);
                //  tt.Library.RootNamespace.NestedClassifier.Add(newClass);
                Library.TypeTable.RegisterType(newClass);
                classToProcess.Add(newClass);
                //Hack
                newClass.Tag = psmClass;
                //Registred to find
                PSMAssociationMembers.Add(psmClass, newClass);
            }

            foreach (var cM in psmSchema.PSMContentModels)
            {
                string cMName = PSMBridgeClass.GetContentModelOCLName(cM);
                if (translateAsOldVersion)
                {
                    cMName += @"_old";
                }
                PSMBridgeClass newClass = new PSMBridgeClass(Library.TypeTable, Library.TypeTable.Library.RootNamespace, cM, cMName);
                // tt.Library.RootNamespace.NestedClassifier.Add(newClass);
                Library.TypeTable.RegisterType(newClass);
                classToProcess.Add(newClass);
                newClass.Tag = cM;
                //Registred to find
                PSMAssociationMembers.Add(cM, newClass);
            }

            classToProcess.ForEach(cl => cl.TranslateMembers(this, translateAsOldVersion));
            List <PSMBridgeClass> orderedSRs = ModelIterator.GetPSMClassesStructuralRepresentativeRelationBFS(psmSchema).Where(c => c.IsStructuralRepresentative).Select(psmc => PSMAssociationMembers[psmc]).ToList();

            orderedSRs.ForEach(cl => cl.IncludeSRMembers(PSMAssociationMembers[((PSMClass)cl.PSMSource).RepresentedClass]));
        }
コード例 #27
0
        private void FormerParentAsRedNode(List <PSMComponent> redNodes, ChangeInstance changeInstance)
        {
            PSMComponent componentOldVersion = changeInstance is IExistingComponentChange ?
                                               (PSMComponent)((IExistingComponentChange)changeInstance).ComponentOldVersion :
                                               (PSMComponent)((IRemovalChange)changeInstance).ComponentOldVersion;

            PSMComponent formerParent =
                componentOldVersion is PSMAssociation ? ((PSMAssociation)componentOldVersion).Parent : ModelIterator.GetPSMParent(componentOldVersion, true);

            PSMComponent formerParentNewVersion = formerParent.GetInVersion(changeInstance.NewVersion);

            if (formerParentNewVersion != null)
            {
                redNodes.AddIfNotContained(formerParentNewVersion);
            }
        }