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