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); }
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); } } }