public static bool filterDataItem(EA.Repository Repository, EA.Connector con, EA.Element e, EA.Element classifier)
 {
     if (e != null)
     {
         if (DiagramManager.isVisible(con))
         {
             if (e.Stereotype.Contains(RoundTripAddIn.RoundTripAddInClass.METAMODEL_DATAITEM))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        static public void parentToJObject(EA.Repository Repository, EA.Diagram diagram, JArray container, IList <int> sampleIds, EA.Element ancestor, EA.Element parent, IList <int> visited, IList <int> relationsVisited, DiagramCache diagramCache, string intertype)
        {
            IList <EA.Element> children = new List <EA.Element>();

            visited.Add(parent.ElementID);
            foreach (EA.Connector con in parent.Connectors)
            {
                if (relationsVisited.Contains(con.ConnectorID))
                {
                    continue;
                }

                if (!DiagramManager.isVisible(con))
                {
                    continue;
                }

                relationsVisited.Add(con.ConnectorID);

                EA.Element source = diagramCache.elementIDHash[con.ClientID];
                EA.Element target = diagramCache.elementIDHash[con.SupplierID];

                logger.log("Source " + source.Name + " Target " + target.Name + ":" + con.Direction);


                if (source.ClassifierID != target.ClassifierID)
                {
                    if (!sampleIds.Contains(target.ElementID))
                    {
                        continue;
                    }
                }

                if (!intertype.Equals("Y") && target.ElementID == parent.ElementID)
                {
                    target = diagramCache.elementIDHash[con.ClientID];
                }


                if (!intertype.Equals("Y") && source.ClassifierID == target.ClassifierID)
                {
                    //If they are of the same type we maintain link direction
                    if (source.ElementID != con.ClientID)
                    {
                        EA.Element h = source;
                        source = target;
                        target = h;
                    }
                }

                String     sourceGuid  = source.ElementGUID;
                String     sourceName  = source.Name;
                String     sourceClass = "";
                EA.Element sourceClazz = null;
                if (source.ClassifierID != 0)
                {
                    sourceClass = source.ClassifierName;
                    sourceClazz = diagramCache.elementIDHash[source.ClassifierID];
                    sourceClass = sourceClazz.Name;
                }

                String     targetGuid  = target.ElementGUID;
                String     targetName  = target.Name;
                String     targetClass = "";
                EA.Element targetClazz = null;
                if (target.ClassifierID != 0)
                {
                    targetClazz = diagramCache.elementIDHash[target.ClassifierID];
                    targetClass = targetClazz.Name;
                }


                if ((!intertype.Equals("Y")) && targetClass.Equals(sourceClass))
                {
                    continue;//skip inter type links
                }


                //if (visited.Contains(related.ElementID))
                //   continue;

                JObject jsonClass = new JObject();
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_ID, con.ConnectorGUID));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_NAME, con.Name));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_NOTES, con.Notes));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_SOURCE, sourceGuid));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_SOURCE_NAME, sourceName));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_SOURCE_CLASS, sourceClass));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_TARGET, targetGuid));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_TARGET_NAME, targetName));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_TARGET_CLASS, targetClass));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_TARGET_VALUE, "1"));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_TYPE, con.Type));
                jsonClass.Add(new JProperty(RoundTripAddInClass.MAPPING_PROPERTY_STEREOTYPE, con.Stereotype));

                logger.log("Source " + source.Name + "-" + sourceClass + " Target " + target.Name + "-" + targetClass);
                container.Add(jsonClass);


                children.Add(target);
            }
            //parentsToJObject(Repository, diagram, container, sampleIds, parent, children,visited);
        }
Beispiel #3
0
        static public void parentToJObject(EA.Repository Repository, EA.Diagram diagram, JArray container, IList <int> sampleIds, EA.Element ancestor, EA.Element parent, IList <int> visited, int depth, DiagramCache diagramCache)
        {
            String type = "";

            if (parent.ClassifierID != 0)
            {
                //logger.log("Get Parent Classifier");
                EA.Element classifier = diagramCache.elementIDHash[parent.ClassifierID];
                type = classifier.Name;
            }

            JObject jsonClass = new JObject();

            jsonClass.Add(new JProperty(RoundTripAddInClass.HIERARCHY_PROPERTY_TYPE, type));
            jsonClass.Add(new JProperty(RoundTripAddInClass.HIERARCHY_PROPERTY_ID, parent.ElementGUID));
            jsonClass.Add(new JProperty(RoundTripAddInClass.HIERARCHY_PROPERTY_NAME, parent.Name));
            jsonClass.Add(new JProperty(RoundTripAddInClass.HIERARCHY_PROPERTY_DESCRIPTION, parent.Notes));
            jsonClass.Add(new JProperty(RoundTripAddInClass.HIERARCHY_PROPERTY_LEVEL, depth));
            if (ancestor != null)
            {
                jsonClass.Add(new JProperty(RoundTripAddInClass.HIERARCHY_PROPERTY_PARENT, ancestor.ElementGUID));
            }
            else
            {
                jsonClass.Add(new JProperty(RoundTripAddInClass.HIERARCHY_PROPERTY_PARENT, "null"));
            }
            container.Add(jsonClass);

            //ObjectManager.addTagsToJson(parent, jsonClass);
            //ObjectManager.addRunStateToJson(parent.RunState, jsonClass);

            IList <EA.Element> children = new List <EA.Element>();

            visited.Add(parent.ElementID);
            foreach (EA.Connector con in parent.Connectors)
            {
                if (!DiagramManager.isVisible(con)) //skip not visiable
                {
                    continue;
                }

                EA.Element related = DiagramManager.getVisibleRelatedElement(Repository, parent, con, diagramCache);
                if (related == null)
                {
                    continue;
                }

                //logger.log("Parent" + parent.Name);
                //logger.log("Related"+ related.Name);
                if (!sampleIds.Contains(related.ElementID))
                {
                    continue;
                }

                if (visited.Contains(related.ElementID))
                {
                    continue;
                }

                children.Add(related);

                logger.log("Parent:" + parent.Name + " Child:" + related.Name);
            }

            parentsToJObject(Repository, diagram, container, sampleIds, parent, children, visited, ++depth, diagramCache);
        }
Beispiel #4
0
        private static void sync_hierarchy(EA.Repository Repository, EA.Diagram diagram, EA.Element sample, JObject jo, EA.Package pkg, DiagramCache diagramCache)
        {
            logger.log("Syncing JObject:" + sample.Name);
            Dictionary <string, RunState> rs  = ObjectManager.parseRunState(sample.RunState);
            Dictionary <string, RunState> nrs = new Dictionary <string, RunState>();

            foreach (JProperty p in jo.Properties())
            {
                logger.log("Property:" + p.Name + ":" + p.Value.ToString());
                if (p.Name == RoundTripAddInClass.HIERARCHY_PROPERTY_LEVEL)
                {
                    continue;
                }
                if (p.Name == RoundTripAddInClass.HIERARCHY_PROPERTY_ID)
                {
                    continue;
                }
                if (p.Name == RoundTripAddInClass.HIERARCHY_PROPERTY_NAME)
                {
                    sample.Name = p.Value.ToString();
                    continue;
                }
                if (p.Name == RoundTripAddInClass.HIERARCHY_PROPERTY_DESCRIPTION)
                {
                    sample.Notes = p.Value.ToString();
                    continue;
                }

                if (p.Name == RoundTripAddInClass.HIERARCHY_PROPERTY_TYPE)
                {
                    string     classifierName    = p.Value.ToString();
                    EA.Element elementClassifier = diagramCache.elementIDHash[sample.ClassifierID];
                    if (elementClassifier == null || elementClassifier.Name != classifierName)
                    {
                        EA.Element clazz = RepositoryHelper.queryClassifier(Repository, classifierName);
                        if (clazz != null)
                        {
                            sample.ClassifierID = clazz.ElementID;
                            continue;
                        }
                    }
                    else
                    {
                    }
                    continue;
                }
                if (p.Name == RoundTripAddInClass.HIERARCHY_PROPERTY_PARENT)
                {
                    string guid = p.Value.ToString();
                    if (guid == null || guid.Length == 0 || guid == "null")
                    {
                        continue;
                    }

                    EA.Element parent = null;
                    if (diagramCache.elementGuidHash.ContainsKey(guid))
                    {
                        parent = diagramCache.elementGuidHash[guid];
                    }
                    if (parent == null)
                    {
                        parent = Repository.GetElementByGuid(guid);
                    }
                    if (parent == null)
                    {
                        logger.log("missing parent");
                        continue;
                    }
                    else
                    {
                        linkToParent(Repository, diagram, sample, parent);
                    }
                    continue;
                }

                //string rsv=null;
                if (p.Value.Type != JTokenType.Object && p.Value.Type != JTokenType.Array)
                {
                    //logger.log("Adding Property:" + sample.Name);
                    RunState r;
                    if (rs.ContainsKey(p.Name))
                    {
                        r = rs[p.Name];
                    }
                    else
                    {
                        r     = new RunState();
                        r.key = p.Name;
                    }
                    r.value = p.Value.ToString();

                    nrs.Add(r.key, r);
                }
            }

            sample.RunState = ObjectManager.renderRunState(nrs);
            logger.log(sample.RunState);
            sample.Update();

            foreach (EA.Connector con in sample.Connectors)
            {
                EA.Element related = null;

                if (!DiagramManager.isVisible(con)) //skip not visiable
                {
                    continue;
                }

                //logger.log("Connector:" + con.SupplierEnd.Role);

                if (sample.ElementID == con.ClientID)
                {
                    if (diagramCache.elementIDHash.ContainsKey(con.SupplierID))
                    {
                        related = diagramCache.elementIDHash[con.SupplierID];
                    }

                    if (related == null)
                    {
                        related = Repository.GetElementByID(con.SupplierID);
                    }

                    JProperty p = jo.Property(con.SupplierEnd.Role);

                    if (p != null)
                    {
                        //logger.log("Found Json Property:" + con.SupplierEnd.Role);
                        if (p.Value.Type == JTokenType.Object)
                        {
                            JObject pjo = (JObject)p.Value;
                            sync_hierarchy(Repository, diagram, related, pjo, pkg, diagramCache);
                        }
                        else if (p.Value.Type == JTokenType.Array)
                        {
                            JArray ja = (JArray)p.Value;
                            if (ja.Count > 0)
                            {
                                JToken t = ja.ElementAt(0);
                                ja.RemoveAt(0);
                                if (t.Type == JTokenType.Object)
                                {
                                    sync_hierarchy(Repository, diagram, related, (JObject)t, pkg, diagramCache);
                                }
                                else
                                {
                                    MessageBox.Show("Arrays of types other than object not supported");
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        static public void parentToJObject(EA.Repository Repository, EA.Diagram diagram, JArray container, IList <int> sampleIds, EA.Element ancestor, EA.Element constraint, IList <int> visited, IList <int> relationsVisited, DiagramCache diagramCache)
        {
            IList <EA.Element> children = new List <EA.Element>();

            visited.Add(constraint.ElementID);

            EA.Element constraintClazz = diagramCache.elementIDHash[constraint.ClassifierID];


            JObject jsonClass = new JObject();

            jsonClass.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_GUID, constraint.ElementGUID));
            jsonClass.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_NAME, constraint.Name));
            jsonClass.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_CLASS, constraintClazz.Name));
            jsonClass.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_STEREOTYPE, constraint.Stereotype));

            ObjectManager.addTagsToJson(constraint, jsonClass);

            container.Add(jsonClass);

            JArray sources = new JArray();
            JArray targets = new JArray();

            jsonClass.Add(RoundTripAddInClass.CONSTRAINT_PROPERTY_SOURCE, sources);
            jsonClass.Add(RoundTripAddInClass.CONSTRAINT_PROPERTY_TARGET, targets);

            foreach (EA.Connector con in constraint.Connectors)
            {
                if (relationsVisited.Contains(con.ConnectorID))
                {
                    continue;
                }

                if (!DiagramManager.isVisible(con))
                {
                    continue;
                }

                relationsVisited.Add(con.ConnectorID);

                Boolean    isSource = true;
                EA.Element related  = null;
                if (constraint.ElementID == con.ClientID)
                {
                    isSource = false;
                    related  = diagramCache.elementIDHash[con.SupplierID];
                }
                else
                {
                    isSource = true;
                    related  = diagramCache.elementIDHash[con.ClientID];
                }


                String relGuid  = related.ElementGUID;
                String relName  = related.Name;
                String relClass = "";

                if (related.ClassifierID != 0)
                {
                    EA.Element relatedClazz = diagramCache.elementIDHash[related.ClassifierID];
                    relClass = relatedClazz.Name;
                }

                JObject jsonCon = new JObject();
                jsonCon.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_GUID, relGuid));
                jsonCon.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_NAME, relName));
                jsonCon.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_CLASS, relClass));
                jsonCon.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_CONNECTOR_TYPE, con.Type));
                jsonCon.Add(new JProperty(RoundTripAddInClass.CONSTRAINT_PROPERTY_CONNECTOR_GUID, con.ConnectorGUID));

                logger.log("Related " + related.Name + "-" + relClass);
                if (isSource)
                {
                    sources.Add(jsonCon);
                }
                else
                {
                    targets.Add(jsonCon);
                }
            }
        }