private void exportAllGlobal(EA.Repository Repository)
        {
            DiagramCache diagramCache = new DiagramCache();
            {
                List <string> diagrams = DiagramManager.querySchemaDiagrams(Repository);
                foreach (string diagramId in diagrams)
                {
                    EA.Diagram diagram = Repository.GetDiagramByGuid(diagramId);
                    logger.log("Exporting Schema Diagram:" + diagram.Name);
                    SchemaManager.exportSchema(Repository, diagram, diagramCache);
                }
            }
            {
                List <string> diagrams = DiagramManager.querySampleDiagrams(Repository);
                foreach (string diagramId in diagrams)
                {
                    EA.Diagram diagram = Repository.GetDiagramByGuid(diagramId);

                    EA.Package samplePackage = Repository.GetPackageByID(diagram.PackageID);
                    EA.Package apiPackage    = Repository.GetPackageByID(samplePackage.ParentID);

                    logger.log("Exporting Sample Diagram:" + diagram.Name + " from api package:" + apiPackage.Name);
                    SampleManager.exportSample(Repository, diagram, diagramCache);
                }
            }
        }
        private void exportDiagram(EA.Repository Repository)
        {
            EA.Diagram diagram = null;
            if (Repository.GetContextItemType() == ObjectType.otDiagram)
            {
                diagram = Repository.GetContextObject();
            }

            DiagramManager.exportDiagram(Repository, diagram);
        }
예제 #3
0
        static public void exportMapping(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            try
            {
                DiagramManager.captureDiagramLinks(diagram);

                //logger.log("links captured");
                RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);
                //logger.log("cache created");
                if (!diagram.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_MAPPINGDIAGRAM))
                {
                    logger.log("exportSample: Ignore diagram that isnt a mapping diagram");
                    return;
                }

                Hashtable ht                   = sampleToJObject(Repository, diagram, diagramCache);
                string    sample               = (string)ht["sample"];
                string    clazz                = (string)ht["class"];
                string    container            = (string)ht["json"];
                string    export               = (string)ht[RoundTripAddInClass.FILENAME];
                string    sourcecontrolPackage = (string)ht[RoundTripAddInClass.PROJECT];

                logger.log("Project:" + sourcecontrolPackage);
                //KeyValuePair<string,JObject> kv = sampleToJObject(Repository, diagram);
                //JObject container = kv.Value;

                if (container == null)
                {
                    MessageBox.Show("No object linked to root with classification sample declared nor  (older style) object of classification Request declared");
                    return;
                }

                //string msg = JsonConvert.SerializeObject(container, Newtonsoft.Json.Formatting.Indented) + "\n";
                EA.Package samplePkg = Repository.GetPackageByID(diagram.PackageID);



                if (fileManager != null)
                {
                    fileManager.initializeAPI(sourcecontrolPackage);
                    fileManager.setDataName(RoundTripAddInClass.MAPPING_PATH);
                    fileManager.setup(RoundTripAddInClass.RAML_0_8);
                    fileManager.exportData(sample, clazz, container, RoundTripAddInClass.MAPPING_PATH, export);
                }
            }
            catch (ModelValidationException ex)
            {
                MessageBox.Show(ex.errors.messages.ElementAt(0).ToString());
            }
        }
예제 #4
0
 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);
 }
예제 #5
0
        static public void exportHierarchy(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            try
            {
                if (!diagram.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_HIERARCHYDIAGRAM))
                {
                    logger.log("exportSample: Ignore diagram that isnt a hierarchy diagram");
                    return;
                }

                DiagramManager.captureDiagramLinks(diagram);

                RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);
                Hashtable ht = sampleToJObject(Repository, diagram, diagramCache);

                string sample      = (string)ht["sample"];
                string clazz       = (string)ht["class"];
                string container   = (string)ht["json"];
                string exportName  = (string)ht[RoundTripAddInClass.FILENAME];
                string projectName = (string)ht[RoundTripAddInClass.PROJECT];


                if (container == null)
                {
                    MessageBox.Show("No object linked to root with classification sample declared nor  (older style) object of classification Request declared");
                    return;
                }

                if (projectName == null)
                {
                    projectName = RoundTripAddInClass.EXPORT_PACKAGE;
                }

                logger.log("saving");
                if (fileManager != null)
                {
                    fileManager.initializeAPI(projectName);
                    fileManager.setDataName(RoundTripAddInClass.HIERARCHY_PATH);
                    fileManager.setup(RoundTripAddInClass.RAML_0_8);
                    fileManager.exportData(sample, clazz, container, RoundTripAddInClass.HIERARCHY_PATH, exportName);
                }
            }catch (ModelValidationException ex) {
                MessageBox.Show(ex.errors.messages.ElementAt(0).ToString());
            }
        }
예제 #6
0
        static public void exportConstraint(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            try
            {
                DiagramManager.captureDiagramLinks(diagram);

                RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);

                if (!diagram.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_CONSTRAINTDIAGRAM))
                {
                    logger.log("Ignore diagram that isnt a constraint diagram");
                    return;
                }

                Hashtable ht                   = sampleToJObject(Repository, diagram, diagramCache);
                string    sample               = (string)ht["sample"];
                string    clazz                = (string)ht["class"];
                string    container            = (string)ht["json"];
                string    export               = (string)ht[RoundTripAddInClass.FILENAME];
                string    sourcecontrolPackage = (string)ht[RoundTripAddInClass.PROJECT];

                logger.log("Project:" + sourcecontrolPackage);

                if (container == null)
                {
                    MessageBox.Show("No object linked to root with classification sample declared nor  (older style) object of classification Request declared");
                    return;
                }

                EA.Package samplePkg = Repository.GetPackageByID(diagram.PackageID);


                if (fileManager != null)
                {
                    fileManager.initializeAPI(sourcecontrolPackage);
                    fileManager.setDataName(RoundTripAddInClass.CONSTRAINT_PATH);
                    fileManager.setup(RoundTripAddInClass.RAML_0_8);
                    fileManager.exportData(sample, clazz, container, RoundTripAddInClass.CONSTRAINT_PATH, export);
                }
            }
            catch (ModelValidationException ex)
            {
                MessageBox.Show(ex.errors.messages.ElementAt(0).ToString());
            }
        }
        ///
        /// Called Before EA starts to check Add-In Exists
        /// Nothing is done here.
        /// This operation needs to exists for the addin to work
        ///
        /// <param name="Repository" />the EA repository
        /// a string
        public String EA_Connect(EA.Repository Repository)
        {
            logger.setRepository(Repository);

            try
            {
                fileManager.setBasePath(Properties.Settings.Default.BasePath);
                fileManager.setDiagramPath(Properties.Settings.Default.DiagramPath);
            }
            catch (Exception)
            {
                logger.log("Did not find BasePath or DiagramPath in user settings");
            }

            MappingManager.setLogger(logger);
            MappingManager.setFileManager(fileManager);

            HierarchyManager.setLogger(logger);
            HierarchyManager.setFileManager(fileManager);

            PopulationManager.setLogger(logger);
            PopulationManager.setFileManager(fileManager);

            ConstraintManager.setLogger(logger);
            ConstraintManager.setFileManager(fileManager);

            DiagramManager.setLogger(logger);
            DiagramManager.setFileManager(fileManager);

            SchemaManager.setLogger(logger);
            SchemaManager.setFileManager(fileManager);
            SampleManager.setLogger(logger);
            SampleManager.setFileManager(fileManager);

            MetaDataManager.setLogger(logger);
            RepositoryHelper.setLogger(logger);
            ObjectManager.setLogger(logger);

            return("a string");
        }
예제 #8
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, 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);
        }
예제 #9
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);
        }
예제 #10
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");
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #11
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);
                }
            }
        }