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 exportPackage(EA.Repository Repository, EA.Package pkg, DiagramCache diagramCache)
 {
     exportRoundTripPackage(Repository, pkg, diagramCache);
     foreach (EA.Package p in pkg.Packages)
     {
         exportPackage(Repository, p, diagramCache);//recurse
     }
 }
        private void exportAll(EA.Repository Repository, DiagramCache diagramCache)
        {
            EA.Diagram diagram = null;
            if (Repository.GetContextItemType() == ObjectType.otDiagram)
            {
                diagram = Repository.GetContextObject();
            }

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

            exportRoundTripPackage(Repository, apiPackage, diagramCache);
        }
Exemplo n.º 4
0
        static public EA.Element extractSelection(DiagramCache diagramCache, EA.Element root)
        {
            //String[] result = new String[0];

            //EA.TaggedValue tv = root.TaggedValues.GetByName(RoundTripAddInClass.PROPERTY_SELECTOR);

            //if (tv != null)
            //{
            //    logger.log("Selector:" + tv.Value);
            //    result = tv.Value.Split(',');
            //}
            //return result;

            EA.Element result = diagramCache.elementIDHash[root.ClassifierID];
            logger.log("Selector:" + result.Name);
            return(result);
        }
Exemplo n.º 5
0
        ///
        /// Validate all object run state keys correspond to classifier attributes
        ///
        //static public void validateDiagram(EA.Repository Repository, EA.Diagram diagram)
        //{
        //    IList<string> messages = diagramValidation(Repository, diagram);

        //    logger.log("**ValidationResults**");
        //    if (messages != null)
        //    {
        //        foreach (string m in messages)
        //        {
        //            logger.log(m);
        //        }
        //    }
        //}

        //static public IList<string> diagramValidation(EA.Repository Repository, EA.Diagram diagram)
        //{
        //    JSchema jschema = null;
        //    JObject json = null;
        //    try
        //    {
        //        //logger.log("Validate Sample");
        //        json = (JObject)sampleToJObject(Repository, diagram)["json"];

        //        //logger.log("JObject formed");

        //        EA.Package samplePkg = Repository.GetPackageByID(diagram.PackageID);
        //        EA.Package samplesPackage = Repository.GetPackageByID(samplePkg.ParentID);
        //        EA.Package apiPackage = Repository.GetPackageByID(samplesPackage.ParentID);

        //        EA.Package schemaPackage = null;

        //        foreach (EA.Package p in apiPackage.Packages)
        //        {
        //            if (p != null && p.Name.Equals(RoundTripAddInClass.API_PACKAGE_SCHEMAS))
        //            {
        //                schemaPackage = p;
        //            }
        //        }
        //        if (schemaPackage == null)
        //        {
        //            throw new Exception("No Schema package found");
        //        }

        //        EA.Diagram schemaDiagram = null;
        //        foreach (EA.Diagram d in schemaPackage.Diagrams)
        //        {
        //            if (d.Stereotype != null && d.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_SCHEMADIAGRAM))
        //            {
        //                schemaDiagram = d;
        //            }
        //        }



        //        jschema = SchemaManager.schemaToJsonSchema(Repository, schemaDiagram).Value;
        //    }
        //    catch (ModelValidationException ex)
        //    {
        //        return ex.errors.messages;
        //    }

        //    IList<string> messages;

        //    if (!json.IsValid(jschema, out messages))
        //    {
        //        logger.log("Sample is not valid:");
        //        return messages;
        //    }
        //    else
        //    {
        //        logger.log("Sample is Valid!");
        //        return null;
        //    }

        //}


        public static void syncMapping(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            logger.log("Sync Mapping");
            RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);
            IList <EA.Element> diagramElements = diagramCache.elementsList;
            IList <EA.Element> samples         = MetaDataManager.diagramSamples(Repository, diagramElements);

            EA.Element container             = container = MetaDataManager.findContainer(Repository, diagram, diagramCache, RoundTripAddInClass.EA_STEREOTYPE_MAPPING);
            EA.Element containerClassifierEl = diagramCache.elementIDHash[container.ClassfierID];
            string     containerName         = container.Name;
            string     containerClassifier   = containerClassifierEl.Name;

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


            Hashtable ht = new Hashtable();

            MetaDataManager.extractDiagramMetaData(ht, container);

            string project = (String)ht[RoundTripAddInClass.PROJECT];


            if (fileManager != null)
            {
                fileManager.initializeAPI(project);
                fileManager.setDataName(RoundTripAddInClass.MAPPING_PATH);
                fileManager.setup(RoundTripAddInClass.RAML_0_8);
                if (!fileManager.populationExists(container.Name, containerClassifier, RoundTripAddInClass.MAPPING_PATH, container.Name))
                {
                    MessageBox.Show("No file exists at:" + fileManager.exportPath(container.Name, containerClassifier, RoundTripAddInClass.MAPPING_PATH, container.Name));
                    return;
                }
                else
                {
                    string fullpath = fileManager.exportPath(containerName, containerClassifier, RoundTripAddInClass.MAPPING_PATH, container.Name);
                    JArray jo       = JArray.Parse(File.ReadAllText(fullpath));
                    sync_mapping(Repository, diagram, container, containerClassifierEl, jo, samplePkg, diagramCache);
                    samplePkg.Update();
                }
            }
        }
        static void cacheDiagramPackages(EA.Repository repository, DiagramCache diagramCache)
        {
            Object o;

            if (diagramCache.elementsList.Count == 0)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            for (short i = 0; i < diagramCache.elementsList.Count; i++)
            {
                o = diagramCache.elementsList[i];
                EA.Element el = (EA.Element)o;
                if (!diagramCache.packageIDHash.ContainsKey(el.PackageID))
                {
                    //logger.log("Get PKG" + el.PackageID);
                    EA.Package pkg = repository.GetPackageByID(el.PackageID);
                    diagramCache.packageIDHash.Add(el.PackageID, pkg);
                }
            }
        }
Exemplo n.º 7
0
        public static void syncSample(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            logger.log("Sync Sample");

            RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);
            IList <EA.Element> diagramElements = diagramCache.elementsList;

            IList <EA.Element> samples = MetaDataManager.diagramSamples(Repository, diagramElements);

            EA.Element container             = container = findContainer(Repository, diagram, diagramElements);
            EA.Element containerClassifierEl = Repository.GetElementByID(container.ClassfierID);
            string     containerName         = container.Name;
            string     containerClassifier   = containerClassifierEl.Name;


            //logger.log("Sample Root:" + container.Name);

            EA.Package samplePkg      = Repository.GetPackageByID(diagram.PackageID);
            EA.Package samplesPackage = Repository.GetPackageByID(samplePkg.ParentID);
            EA.Package apiPackage     = Repository.GetPackageByID(samplesPackage.ParentID);
            if (fileManager != null)
            {
                fileManager.initializeAPI(apiPackage.Name);
                fileManager.setup(RoundTripAddInClass.RAML_0_8);
                if (!fileManager.sampleExists(container.Name, containerClassifier))
                {
                    MessageBox.Show("No file exists at:" + fileManager.samplePath(container.Name, containerClassifier));
                    return;
                }
                else
                {
                    string  fullpath = fileManager.samplePath(containerName, containerClassifier);
                    JObject jo       = JObject.Parse(File.ReadAllText(fullpath));
                    sync_sample(Repository, container, jo);
                }
            }
        }
Exemplo n.º 8
0
        private static EA.Element reifyElement(EA.Repository Repository, DiagramCache diagramCache, JObject jo, EA.Package pkg)
        {
            EA.Element element   = null;
            JToken     guidToken = null;

            String name      = "";
            JToken nameToken = null;

            if (jo.TryGetValue(RoundTripAddInClass.CONSTRAINT_PROPERTY_NAME, out nameToken))
            {
                name = nameToken.ToString();
            }

            if (jo.TryGetValue(RoundTripAddInClass.CONSTRAINT_PROPERTY_GUID, out guidToken))
            {
                String     guid = guidToken.ToString();
                EA.Element el   = null;
                if (diagramCache.elementGuidHash.ContainsKey(guid))
                {
                    element = diagramCache.elementGuidHash[guid];
                }
                else
                {
                    element = Repository.GetElementByGuid(guid);
                }
            }

            if (element == null)
            {
                logger.log("Create Element");
                //Need to create constraint
                element = pkg.Elements.AddNew(name, "Object");
                element.Update();
                diagramCache.addElement(element);
            }
            return(element);
        }
        public static void syncPopulation(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            logger.log("Sync Population");
            RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);
            IList <EA.Element> diagramElements = diagramCache.elementsList;

            //IList<EA.Element> samples = MetaDataManager.diagramSamples(Repository, diagramElements);
            IList <EA.Element> samples = diagramElements;

            EA.Element container = container = MetaDataManager.findContainer(Repository, diagram, diagramCache, RoundTripAddInClass.EA_STEREOTYPE_POPULATION);

            logger.log("Classifier ID:" + container.ClassifierID);


            string containerName       = container.Name;
            string containerClassifier = "Classes";

            EA.Element containerClassifierEl = null;
            if (container.ClassifierID != 0)
            {
                containerClassifierEl = Repository.GetElementByID(container.ClassfierID);
                containerName         = container.Name;
                containerClassifier   = containerClassifierEl.Name;
            }

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

            Hashtable ht = new Hashtable();

            MetaDataManager.extractDiagramMetaData(ht, container);

            string project = (String)ht[RoundTripAddInClass.PROJECT];

            if (project == null)
            {
                MessageBox.Show("No project defined in the Population stereotyped element. Please enter project name where population should be exported.");
                return;
            }

            if (fileManager != null)
            {
                fileManager.initializeAPI(project);
                fileManager.setDataName(RoundTripAddInClass.POPULATION_PATH);
                fileManager.setup(RoundTripAddInClass.RAML_0_8);
                if (!fileManager.populationExists(container.Name, containerClassifier, RoundTripAddInClass.POPULATION_PATH, container.Name))
                {
                    MessageBox.Show("No file exists at:" + fileManager.exportPath(container.Name, containerClassifier, RoundTripAddInClass.POPULATION_PATH, container.Name));
                    return;
                }
                else
                {
                    string fullpath = fileManager.exportPath(containerName, containerClassifier, RoundTripAddInClass.POPULATION_PATH, container.Name);
                    JArray jo       = JArray.Parse(File.ReadAllText(fullpath));
                    sync_population(Repository, container, containerClassifierEl, jo, samplePkg, diagramCache);
                    samplePkg.Update();
                }
            }
        }
Exemplo n.º 10
0
        static public Hashtable sampleToJObject(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramElements)
        {
            Hashtable result = new Hashtable();

            //logger.log("sampleToObject");

            //IList<EA.Element> clazzes = MetaDataManager.diagramClasses(Repository, diagramElements.elementsList);
            //logger.log("GetClazzes" + clazzes.Count);

            //IList<EA.Element> components = MetaDataManager.diagramComponents(Repository, diagramElements.elementsList);
            //logger.log("GetComponents" + components.Count);


            //IList<EA.Element> samples = MetaDataManager.diagramSamples(Repository, diagramElements.elementsList);
            //logger.log("GetSamples" + samples.Count);

            //samples = samples.Concat(clazzes).ToList();
            //samples = samples.Concat(components).ToList();
            IList <EA.Element> samples = diagramElements.elementsList;

            logger.log("All" + samples.Count);

            EA.Element root = MetaDataManager.findContainer(Repository, diagram, diagramElements, RoundTripAddInClass.EA_STEREOTYPE_POPULATION);

            MetaDataManager.extractDiagramMetaData(result, root);

            logger.log("Classifier ID:" + root.ClassifierID);

            Dictionary <int, JObject> instances = new Dictionary <int, JObject>();
            JArray container           = new JArray();
            string containerName       = root.Name;
            string containerClassifier = "Classes";

            if (root.ClassifierID != 0)
            {
                EA.Element rootClassifier = Repository.GetElementByID(root.ClassifierID);
                containerName       = root.Name;
                containerClassifier = rootClassifier.Name;
            }

            foreach (EA.Element sample in samples)
            {
                //logger.log("Sample Name:" + sample.Name);

                if (sample.Stereotype == RoundTripAddInClass.EA_STEREOTYPE_POPULATION)
                {
                    continue;
                }

                if (root.ClassifierID != 0 && sample.ClassfierID != root.ClassfierID)
                {
                    //skip root elements that are the population elements.
                    continue;
                }

                //logger.log("Sample Name2:" + sample.Name);

                String     type  = "";
                EA.Element clazz = null;
                if (sample.ClassifierID != 0)
                {
                    clazz = diagramElements.elementIDHash[sample.ClassifierID];
                    type  = clazz.Name;
                }
                else
                {
                    logger.log("Classifier is null");
                }

                EA.Package package = diagramElements.packageIDHash[sample.PackageID];

                JObject jsonClass = null;

                {
                    jsonClass = new JObject();
                    jsonClass.Add(new JProperty(RoundTripAddInClass.POPULATION_PROPERTY_GUID, sample.ElementGUID));
                    jsonClass.Add(new JProperty(RoundTripAddInClass.POPULATION_PROPERTY_NAME, sample.Name));
                    jsonClass.Add(new JProperty(RoundTripAddInClass.POPULATION_PROPERTY_NOTES, sample.Notes));
                    jsonClass.Add(new JProperty(RoundTripAddInClass.POPULATION_PROPERTY_PACKAGE, package.Name));
                    if (clazz != null)
                    {
                        jsonClass.Add(new JProperty(RoundTripAddInClass.POPULATION_PROPERTY_TYPE, clazz.Name));
                    }

                    container.Add(jsonClass);
                }

                string rs = sample.RunState;

                ObjectManager.addRunStateToJson(rs, jsonClass);
                ObjectManager.addTagsToJson(sample, jsonClass);
            }

            logger.log("Export container:" + containerName);

            foreach (EA.Element clazz in samples)
            {
                JObject jsonClass = null;
                if (!instances.TryGetValue(clazz.ElementID, out jsonClass))
                {
                    continue;
                }
                if (jsonClass != null)
                {
                    logger.log("Found jsonClass:" + clazz.Name);
                    foreach (EA.Connector con in clazz.Connectors)
                    {
                        //logger.log("Found connector:");
                        EA.Element related = null;
                        if (clazz.ElementID == con.ClientID)
                        {
                            related = Repository.GetElementByID(con.SupplierID);

                            try
                            {
                                object o = instances[related.ElementID];
                            }
                            catch (KeyNotFoundException)
                            {
                                //Object is in package but not on the diagram
                                continue;
                            }

                            if (related != null && instances[related.ElementID] != null)
                            {
                                if (con.SupplierEnd.Cardinality.Equals(RoundTripAddInClass.CARDINALITY_0_TO_MANY) ||
                                    con.SupplierEnd.Cardinality.Equals(RoundTripAddInClass.CARDINALITY_1_TO_MANY)
                                    )
                                {
                                    //logger.log("Found array");

                                    string propertyName = related.Name;
                                    //Override with the connection supplier end
                                    try {
                                        if (con.SupplierEnd.Role.Length > 0)
                                        {
                                            propertyName = con.SupplierEnd.Role;
                                        }
                                    } catch (Exception) { }

                                    JProperty p = jsonClass.Property(propertyName);
                                    if (p == null)
                                    {
                                        JArray ja = new JArray();
                                        ja.Add(instances[related.ElementID]);
                                        //logger.log("Adding array property:"+ related.Name);
                                        jsonClass.Add(new JProperty(propertyName, ja));
                                    }
                                    else
                                    {
                                        JArray ja = (JArray)p.Value;
                                        //logger.log("Adding to array property");
                                        ja.Add(instances[related.ElementID]);
                                    }
                                }
                                else
                                {
                                    string propertyName = related.Name;
                                    //Override with the connection supplier end
                                    try {
                                        if (con.SupplierEnd.Role.Length > 0)
                                        {
                                            propertyName = con.SupplierEnd.Role;
                                        }
                                    } catch (Exception) { }
                                    //logger.log("Adding property:" + related.Name);
                                    jsonClass.Add(new JProperty(propertyName, instances[related.ElementID]));
                                }
                            }
                        }
                    }
                }
            }

            //KeyValuePair<string,JObject> kv = new KeyValuePair<string,JObject>(containerName,container);
            //return kv;

            //logger.log("REturning result");
            result.Add("sample", containerName);
            result.Add("class", containerClassifier);
            result.Add("json", container);
            return(result);
        }
Exemplo n.º 11
0
        private static void sync_population_runstate(EA.Repository Repository, EA.Element sample, EA.Element classifier, 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>();

            sample.ClassifierID = classifier.ElementID;

            foreach (JProperty p in jo.Properties())
            {
                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_GUID)
                {
                    continue;
                }
                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_NAME)
                {
                    sample.Name = p.Value.ToString();
                    continue;
                }
                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_NOTES)
                {
                    sample.Notes = p.Value.ToString();
                    continue;
                }

                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_TYPE)
                {
                    string     classifierName = p.Value.ToString();
                    EA.Element clazz          = RepositoryHelper.queryClassifier(Repository, classifierName);
                    if (clazz != null)
                    {
                        sample.ClassifierID = clazz.ElementID;
                        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();
        }
Exemplo n.º 12
0
        public static void sync_element_taggedvalue(EA.Repository Repository, EA.Element sample, EA.Element classifier, JObject jo, EA.Package pkg, DiagramCache diagramCache)
        {
            logger.log("Syncing JObject:" + sample.Name);
            EA.Collection taggedValues = sample.TaggedValues;

            if (classifier != null)
            {
                sample.ClassifierID = classifier.ElementID;
            }

            foreach (JProperty p in jo.Properties())
            {
                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_GUID)
                {
                    continue;
                }
                if (p.Name == RoundTripAddInClass.CONSTRAINT_PROPERTY_SOURCE || p.Name == RoundTripAddInClass.CONSTRAINT_PROPERTY_TARGET)
                {
                    continue;
                }
                if (p.Name == RoundTripAddInClass.CONSTRAINT_PROPERTY_CLASS || p.Name == RoundTripAddInClass.CONSTRAINT_PROPERTY_STEREOTYPE)
                {
                    continue;
                }
                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_PACKAGE)
                {
                    continue;
                }
                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_NAME)
                {
                    sample.Name = p.Value.ToString();
                    continue;
                }
                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_NOTES)
                {
                    sample.Notes = p.Value.ToString();
                    continue;
                }

                if (p.Name == RoundTripAddInClass.POPULATION_PROPERTY_TYPE)
                {
                    string     classifierName = p.Value.ToString();
                    EA.Element clazz          = RepositoryHelper.queryClassifier(Repository, classifierName);
                    if (clazz != null)
                    {
                        sample.ClassifierID = clazz.ElementID;
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (p.Value.Type != JTokenType.Object && p.Value.Type != JTokenType.Array)
                {
                    //logger.log("Handling Property:" + p.Name);

                    EA.TaggedValue r = taggedValues.GetByName(p.Name);

                    if (r != null)
                    {
                        //logger.log("Existing Tag");
                        r.Value = p.Value.ToString();
                        r.Update();
                    }
                    else
                    {
                        //logger.log("New Tag");
                        EA.TaggedValue tv = sample.TaggedValues.AddNew(p.Name, RoundTripAddInClass.EA_TYPE_STRING);
                        tv.Value = p.Value.ToString();
                        tv.Update();
                    }
                }
            }
            sample.Update();
        }
        ///
        /// Called when user makes a selection in the menu.
        /// This is your main exit point to the rest of your Add-in
        ///
        /// <param name="Repository" />the repository
        /// <param name="Location" />the location of the menu
        /// <param name="MenuName" />the name of the menu
        /// <param name="ItemName" />the name of the selected menu item
        public void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName)
        {
            logger.enable(Repository);

            DiagramCache diagramCache = new DiagramCache();

            EA.Diagram diagram = null;
            if (Repository.GetContextItemType() == ObjectType.otDiagram)
            {
                diagram = Repository.GetContextObject();
            }

            switch (ItemName)
            {
            case menuExportMapping:
                MappingManager.exportMapping(Repository, diagram, diagramCache);
                break;

            case menuSyncMapping:
                MappingManager.syncMapping(Repository, diagram, diagramCache);
                break;

            case menuExportHierarchy:
                logger.log("Menu Export Hierarchy");
                HierarchyManager.exportHierarchy(Repository, diagram, diagramCache);

                break;

            case menuExportPopulation:
                PopulationManager.exportPopulation(Repository, diagram, diagramCache);

                break;

            case menuSyncPopulation:
                PopulationManager.syncPopulation(Repository, diagram, diagramCache);
                break;

            case menuSyncHierarchy:
                HierarchyManager.syncHierarchy(Repository, diagram, diagramCache);
                break;


            case menuExportConstraint:
                ConstraintManager.exportConstraint(Repository, diagram, diagramCache);
                break;

            case menuSyncConstraint:
                ConstraintManager.syncConstraint(Repository, diagram, diagramCache);
                break;

            case menuExportAll:
                exportAll(Repository, diagramCache);
                break;

            case menuExportPackage:
                exportPackage(Repository, diagramCache);
                break;

            case menuExportDiagram:
                exportDiagram(Repository);
                break;

            case menuExportSchema:
                try
                {
                    SchemaManager.exportSchema(Repository, diagram, diagramCache);
                    MetaDataManager.setAsSchemaDiagram(Repository, diagram);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                break;

            //case menuExportCanonical:
            //    try
            //    {
            //        SchemaManager.exportCanonical(Repository, diagram);
            //        //MetaDataManager.setAsCanonicalDiagram(Repository, diagram);
            //    }
            //    catch (Exception ex)
            //    {
            //        MessageBox.Show(ex.Message);
            //    }
            //    break;

            case menuExportSample:
                SampleManager.exportSample(Repository, diagram, diagramCache);
                MetaDataManager.setAsSampleDiagram(Repository, diagram);
                break;

            case menuSyncSample:
                SampleManager.syncSample(Repository, diagram, diagramCache);
                break;

            case menuCreateSample:
                SchemaManager.generateSample(Repository, diagramCache);
                break;

            case menuUpdateClassFromInstance:
                SchemaManager.updateClassFromInstance(Repository);
                break;

            case menuUpdateInstanceFromClass:
                SchemaManager.operateOnSample(Repository, SchemaManager.updateSampleFromClass);
                break;

            case menuValidateDiagram:
                if (diagram != null)
                {
                    if (diagram.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_SAMPLEDIAGRAM))
                    {
                        SampleManager.validateDiagram(Repository, diagram, diagramCache);
                    }
                    else if (diagram.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_SCHEMADIAGRAM))
                    {
                        SchemaManager.validateDiagram(Repository, diagram, diagramCache);
                    }
                }

                break;



            case menuToggleLogging:
                logger.toggleLogging(Repository);
                break;

            case menuWeb:
                this.callWeb(Repository);
                break;
            }
        }
Exemplo n.º 14
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");
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 15
0
        static public EA.Element getVisibleRelatedElement(EA.Repository repository, EA.Element source, EA.Connector con, DiagramCache diagramCache)
        {
            //logger.log("Visible Connection:" + con.Name);

            //logger.log("Check Supplier" + con.SupplierID);

            //EA.Element sup = repository.GetElementByID(con.SupplierID);
            //logger.log(sup.Name);
            EA.Element related = null;
            if (diagramCache.elementIDHash.ContainsKey(con.SupplierID))
            {
                related = diagramCache.elementIDHash[con.SupplierID];
            }
            if (related == null)//Found issue that links may be visible while
            {
                return(null);
            }
            if (related != null && related.ElementID == source.ElementID && diagramCache.elementIDHash.ContainsKey(con.ClientID))
            {
                //logger.log("Check Client");
                related = diagramCache.elementIDHash[con.ClientID];
            }
            return(related);
        }
Exemplo n.º 16
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());
            }
        }
Exemplo n.º 17
0
        static public Hashtable sampleToJObject(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            logger.log("SampeToJObject");
            Hashtable result = new Hashtable();

            //IList<EA.Element> clazzes = MetaDataManager.diagramClasses(Repository, diagramCache.elementsList);

            //IList<EA.Element> components = MetaDataManager.diagramComponents(Repository, diagramCache.elementsList);

            //IList<EA.Element> samples = MetaDataManager.diagramSamples(Repository, diagramCache.elementsList);

            //samples = samples.Concat(clazzes).ToList();
            //samples = samples.Concat(components).ToList();

            IList <EA.Element> samples = diagramCache.elementsList;

            logger.log("Samples:" + samples.Count);

            EA.Element root = MetaDataManager.findContainer(Repository, diagram, diagramCache, RoundTripAddInClass.EA_STEREOTYPE_MAPPING);

            logger.log("MetaData container:" + root.Name);

            EA.Element rootClassifier           = null;
            Dictionary <int, JObject> instances = new Dictionary <int, JObject>();
            JArray container           = new JArray();
            string containerName       = "ALL";
            string containerClassifier = "Class";

            if (root.ClassifierID != 0)
            {
                rootClassifier      = diagramCache.elementIDHash[root.ClassifierID];
                containerName       = root.Name;
                containerClassifier = rootClassifier.Name;
                logger.log("Export container:" + rootClassifier.Name);
            }

            MetaDataManager.extractDiagramMetaData(result, root);


            String prefix    = (string)result[RoundTripAddInClass.PREFIX];
            String intertype = (string)result[RoundTripAddInClass.INCLUDE_INTERTYPE];


            IList <int>        visited          = new List <int>();
            IList <EA.Element> parents          = new List <EA.Element>();
            IList <int>        sampleIds        = new List <int>();
            IList <int>        relationsVisited = new List <int>();

            foreach (EA.Element sample in samples)
            {
                sampleIds.Add(sample.ElementID);

                if (sample.Stereotype == RoundTripAddInClass.EA_STEREOTYPE_HIERARCHY)
                {
                    continue;
                }

                if (root.ClassifierID != 0 && sample.ClassfierID != root.ClassfierID)
                {
                    continue;
                }


                visited.Add(sample.ElementID);
                parents.Add(sample);
            }

            parentsToJObject(Repository, diagram, container, sampleIds, null, parents, visited, relationsVisited, diagramCache, intertype);

            string msg = prefix + JsonConvert.SerializeObject(container, Newtonsoft.Json.Formatting.Indented) + "\n";

            result.Add("sample", containerName);
            result.Add("class", containerClassifier);
            result.Add("json", msg);
            //result.Add("export", root.Name);
            return(result);
        }
Exemplo n.º 18
0
        static public void parentsToJObject(EA.Repository Repository, EA.Diagram diagram, JArray container, IList <int> sampleIds, EA.Element ancestor, IList <EA.Element> parents, IList <int> visited, IList <int> relationsVisited, DiagramCache diagramCache, string intertype)
        {
            logger.log("Parents :" + parents.Count);

            foreach (EA.Element parent in parents)
            {
                logger.log("Handling:" + parent.Name);
                parentToJObject(Repository, diagram, container, sampleIds, ancestor, parent, visited, relationsVisited, diagramCache, intertype);
            }
        }
        private void exportRoundTripPackage(EA.Repository Repository, EA.Package package, DiagramCache diagramCache)
        {
            foreach (object obj in package.Diagrams)
            {
                EA.Diagram samplediagram = (EA.Diagram)obj;


                //DiagramManager.exportDiagram(Repository, samplediagram, diagramCache);
                if (samplediagram.Stereotype == RoundTripAddInClass.EA_STEREOTYPE_POPULATIONDIAGRAM)
                {
                    PopulationManager.exportPopulation(Repository, samplediagram, diagramCache);
                }
                else if (samplediagram.Stereotype == RoundTripAddInClass.EA_STEREOTYPE_MAPPINGDIAGRAM)
                {
                    MappingManager.exportMapping(Repository, samplediagram, diagramCache);
                }
                else if (samplediagram.Stereotype == RoundTripAddInClass.EA_STEREOTYPE_HIERARCHYDIAGRAM)
                {
                    HierarchyManager.exportHierarchy(Repository, samplediagram, diagramCache);
                }
            }
        }
Exemplo n.º 20
0
        ///
        /// Validate all object run state keys correspond to classifier attributes
        ///
        //static public void validateDiagram(EA.Repository Repository,EA.Diagram diagram)
        //{
        //    IList<string> messages = diagramValidation(Repository,diagram);

        //    logger.log("**ValidationResults**");
        //    if(messages!=null)
        //    {
        //        foreach (string m in messages)
        //        {
        //            logger.log(m);
        //        }
        //    }
        //}

        //static public IList<string> diagramValidation(EA.Repository Repository, EA.Diagram diagram,IList<EA.Element> diagramElements)
        //{
        //    JSchema jschema = null;
        //    JObject json = null;
        //    try
        //    {
        //        //logger.log("Validate Sample");
        //        json = (JObject)sampleToJObject(Repository, diagram, diagramElements)["json"];

        //        //logger.log("JObject formed");

        //        EA.Package samplePkg = Repository.GetPackageByID(diagram.PackageID);
        //        EA.Package samplesPackage = Repository.GetPackageByID(samplePkg.ParentID);
        //        EA.Package apiPackage = Repository.GetPackageByID(samplesPackage.ParentID);

        //        EA.Package schemaPackage = null;

        //        foreach (EA.Package p in apiPackage.Packages)
        //        {
        //            if (p!=null && p.Name.Equals(RoundTripAddInClass.API_PACKAGE_SCHEMAS))
        //            {
        //                schemaPackage = p;
        //            }
        //        }
        //        if (schemaPackage == null)
        //        {
        //            throw new Exception("No Schema package found");
        //        }

        //        EA.Diagram schemaDiagram = null;
        //        foreach (EA.Diagram d in schemaPackage.Diagrams)
        //        {
        //            if (d.Stereotype != null && d.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_SCHEMADIAGRAM))
        //            {
        //                schemaDiagram = d;
        //            }
        //        }



        //        jschema = SchemaManager.schemaToJsonSchema(Repository, schemaDiagram,diagramElements).Value;
        //    }
        //    catch (ModelValidationException ex)
        //    {
        //        return ex.errors.messages;
        //    }

        //    IList<string> messages;

        //    if (!json.IsValid(jschema, out messages))
        //    {
        //        logger.log("Sample is not valid:");
        //        return messages;
        //    }
        //    else{
        //        logger.log("Sample is Valid!");
        //        return null;
        //    }

        //}


        public static void syncHierarchy(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            logger.log("Sync Hierarchy");

            RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);
            //IList<EA.Element> diagramElements = diagramCache.elementsList;

            IList <EA.Element> samples = MetaDataManager.diagramSamples(Repository, diagramCache.elementsList);

            EA.Element container             = container = MetaDataManager.findContainer(Repository, diagram, diagramCache, RoundTripAddInClass.EA_STEREOTYPE_HIERARCHY);
            EA.Element containerClassifierEl = diagramCache.elementIDHash[container.ClassfierID];
            string     containerName         = container.Name;
            string     containerClassifier   = containerClassifierEl.Name;

            Hashtable ht = new Hashtable();

            MetaDataManager.extractDiagramMetaData(ht, container);

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

            string sourcecontrolPackage = (string)ht[RoundTripAddInClass.PROJECT];


            if (fileManager != null)
            {
                fileManager.initializeAPI(sourcecontrolPackage);
                fileManager.setDataName(RoundTripAddInClass.HIERARCHY_PATH);
                fileManager.setup(RoundTripAddInClass.RAML_0_8);
                if (!fileManager.populationExists(container.Name, containerClassifier, RoundTripAddInClass.HIERARCHY_PATH, container.Name))
                {
                    MessageBox.Show("No file exists at:" + fileManager.exportPath(container.Name, containerClassifier, RoundTripAddInClass.HIERARCHY_PATH, container.Name));
                    return;
                }
                else
                {
                    string fullpath = fileManager.exportPath(containerName, containerClassifier, RoundTripAddInClass.HIERARCHY_PATH, container.Name);
                    JArray jo       = JArray.Parse(File.ReadAllText(fullpath));
                    sync_hierarchy(Repository, diagram, container, jo, samplePkg, diagramCache);
                    samplePkg.Update();
                    diagram.DiagramLinks.Refresh();
                    if (!diagram.Update())
                    {
                        logger.log(diagram.GetLastError());
                    }
                }
            }
        }
Exemplo n.º 21
0
        static public void exportPopulation(EA.Repository Repository, EA.Diagram diagram, DiagramCache diagramCache)
        {
            try
            {
                if (!diagram.Stereotype.Equals(RoundTripAddInClass.EA_STEREOTYPE_POPULATIONDIAGRAM))
                {
                    logger.log("exportSample: Ignore diagam that isnt a population diagram");
                    return;
                }

                RepositoryHelper.createDiagramCache(Repository, diagram, diagramCache);
                IList <EA.Element> diagramElements = diagramCache.elementsList;

                Hashtable ht        = sampleToJObject(Repository, diagram, diagramCache);
                string    sample    = (string)ht["sample"];
                string    clazz     = (string)ht["class"];
                JArray    container = (JArray)ht["json"];


                logger.log("Population Size:" + container.Count);
                //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);
                //EA.Package samplesPackage = Repository.GetPackageByID(samplePkg.ParentID);
                //EA.Package apiPackage = Repository.GetPackageByID(samplesPackage.ParentID);


                String project = (String)ht[RoundTripAddInClass.PROJECT];
                if (project == null)
                {
                    project = RoundTripAddInClass.EXPORT_PACKAGE;
                }


                if (fileManager != null)
                {
                    fileManager.initializeAPI(project);
                    fileManager.setDataName(RoundTripAddInClass.POPULATION_PATH);
                    fileManager.setup(RoundTripAddInClass.RAML_0_8);
                    fileManager.exportData(sample, clazz, msg, RoundTripAddInClass.POPULATION_PATH, sample);
                }
            }catch (ModelValidationException ex) {
                MessageBox.Show(ex.errors.messages.ElementAt(0).ToString());
            }
        }
Exemplo n.º 22
0
        static void cacheDiagramClassifiers(EA.Repository repository, DiagramCache diagramCache)
        {
            Object o;

            if (diagramCache.elementsList.Count == 0)
            {
                return;
            }

            int           classifierId;
            StringBuilder sb = new StringBuilder();

            for (short i = 0; i < diagramCache.elementsList.Count; i++)
            {
                o = diagramCache.elementsList[i];
                EA.Element el = (EA.Element)o;
                if (!diagramCache.elementIDHash.ContainsKey(el.ElementID))
                {
                    diagramCache.elementIDHash.Add(el.ElementID, el);
                }
                classifierId = el.ClassifierID;
                if (classifierId != 0)
                {
                    sb.Append(classifierId);
                    sb.Append(",");
                }
            }
            logger.log("Getting classifiers" + sb.ToString());

            String classifiersString = sb.ToString();

            if (classifiersString.Length == 0)
            {
                return;
            }
            classifiersString = classifiersString.Substring(0, classifiersString.Length - 1);
            EA.Collection classifierCollection = repository.GetElementSet(classifiersString, 0);

            logger.log("Classifiers Length" + classifierCollection.Count);

            int elementId;

            for (short i = 0; i < classifierCollection.Count; i++)
            {
                logger.log("Get classifier" + i);
                logger.log(classifierCollection.GetType().Name);

                o = classifierCollection.GetAt(i);

                EA.Element element = (EA.Element)o;
                elementId = element.ElementID;
                logger.log("A");
                if (!diagramCache.elementIDHash.ContainsKey(elementId))
                {
                    diagramCache.elementIDHash.Add(elementId, element);
                }
                logger.log("B");
                if (!diagramCache.elementGuidHash.ContainsKey(element.ElementGUID))
                {
                    diagramCache.elementGuidHash.Add(element.ElementGUID, element);
                }
            }
        }
Exemplo n.º 23
0
        private static void sync_population(EA.Repository Repository, EA.Element sample, EA.Element classifier, JArray ja, EA.Package pkg, DiagramCache diagramCache)
        {
            logger.log("Syncing JArray:" + sample.Name);
            Dictionary <string, RunState> rs  = ObjectManager.parseRunState(sample.RunState);
            Dictionary <string, RunState> nrs = new Dictionary <string, RunState>();

            foreach (JObject jo in ja.Children <JObject>())
            {
                logger.log("Syncing Child:");
                JToken guidToken = null;
                if (jo.TryGetValue(RoundTripAddInClass.POPULATION_PROPERTY_GUID, out guidToken))
                {
                    String     guid = guidToken.ToString();
                    EA.Element el   = diagramCache.elementGuidHash[guid];
                    if (el == null)
                    {
                        el = Repository.GetElementByGuid(guid);
                    }
                    if (el != null)
                    {
                        //logger.log("Found element for guid" + guid);
                        ObjectManager.sync_element_taggedvalue(Repository, el, classifier, jo, pkg, diagramCache);
                    }
                    else
                    {
                        logger.log("No element for guid" + guid);
                    }
                }
                else
                {
                    logger.log("No guid, adding element" + jo.ToString());
                    EA.Element el = pkg.Elements.AddNew("", "Object");
                    logger.log("No guid, adding element" + jo.ToString());
                    ObjectManager.sync_element_taggedvalue(Repository, el, classifier, jo, pkg, diagramCache);
                }
            }
        }
Exemplo n.º 24
0
 public static DiagramCache createDiagramCache(EA.Repository repository, EA.Diagram diagram, DiagramCache result)
 {
     cacheDiagramElements(repository, diagram.DiagramObjects, result);
     logger.log("cache elements");
     cacheDiagramClassifiers(repository, result);
     logger.log("cache classifier");
     cacheDiagramPackages(repository, result);
     logger.log(result.elementsList.Count + ":" + result.elementIDHash.Count);
     return(result);
 }
Exemplo n.º 25
0
 static void populateCache(EA.Collection elements, DiagramCache diagramCache)
 {
 }
 private void exportPackage(EA.Repository Repository, DiagramCache diagramCache)
 {
     EA.Package pkg = Repository.GetTreeSelectedPackage();
     exportPackage(Repository, pkg, diagramCache);
 }
Exemplo n.º 27
0
        private static void sync_mapping(EA.Repository Repository, EA.Diagram diagram, EA.Element sample, EA.Element classifier, JArray ja, EA.Package pkg, DiagramCache diagramCache)
        {
            logger.log("Syncing JArray:" + sample.Name);
            Dictionary <string, RunState> rs  = ObjectManager.parseRunState(sample.RunState);
            Dictionary <string, RunState> nrs = new Dictionary <string, RunState>();

            foreach (JObject jo in ja.Children <JObject>())
            {
                logger.log("Syncing Relationship:");

                EA.Element source = null;
                EA.Element target = null;

                JToken guidToken = null;
                if (jo.TryGetValue(RoundTripAddInClass.MAPPING_PROPERTY_SOURCE, out guidToken))
                {
                    String     guid = guidToken.ToString();
                    EA.Element el   = Repository.GetElementByGuid(guid);
                    if (el != null)
                    {
                        //logger.log("Found element for guid" + guid);
                        source = el;
                    }
                    else
                    {
                        logger.log("No element for guid" + guid);
                    }
                }
                if (jo.TryGetValue(RoundTripAddInClass.MAPPING_PROPERTY_TARGET, out guidToken))
                {
                    String     guid = guidToken.ToString();
                    EA.Element el   = Repository.GetElementByGuid(guid);
                    if (el != null)
                    {
                        //logger.log("Found element for guid" + guid);
                        target = el;
                    }
                    else
                    {
                        logger.log("No element for guid" + guid);
                    }
                }
                if (source != null && target != null)
                {
                    if (!checkRelationship(source, target))
                    {
                        sync_relationship(Repository, diagram, source, target, jo, pkg);
                    }
                }
            }
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
0
        static void cacheDiagramElements(EA.Repository repository, EA.Collection collection, DiagramCache diagramCache)
        {
            //diagramCache.elementsList = new List<EA.Element>();
            Object o;

            EA.Element e;
            if (collection.Count == 0)
            {
                return;
            }

            int eId, pkgId;

            EA.Collection elements = null;

            List <int> els = new List <int>();

            for (short i = 0; i < collection.Count; i++)
            {
                o   = collection.GetAt(i);
                eId = ((EA.DiagramObject)o).ElementID;
                if (diagramCache.elementIDHash.ContainsKey(eId))//Skip elements already cached
                {
                    continue;
                }
                els.Add(eId);
            }


            StringBuilder sb;

            {
                sb = new StringBuilder();
                for (short i = 0; i < els.Count - 1; i++)
                {
                    eId = els[i];
                    sb.Append(eId);
                    sb.Append(",");
                }
                eId = els[(short)(els.Count - 1)];
                sb.Append(eId);
                String elementsString = sb.ToString();
                //logger.log("DiagramObjectIds"+sb.ToString());
                //logger.log("Getting elements:"+elementsString);

                elements = repository.GetElementSet(elementsString, 0);
            }
            sb = new StringBuilder();

            if (elements != null)
            {
                foreach (EA.Element el in elements)
                {
                    diagramCache.elementsList.Add(el);
                    if (!diagramCache.elementIDHash.ContainsKey(el.ElementID))
                    {
                        diagramCache.elementIDHash.Add(el.ElementID, el);
                    }
                    if (!diagramCache.elementGuidHash.ContainsKey(el.ElementGUID))
                    {
                        diagramCache.elementGuidHash.Add(el.ElementGUID, el);
                    }
                }
            }
        }
Exemplo n.º 30
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);
        }