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"); } } } } } } }
private static void sync_sample(EA.Repository Repository, EA.Element sample, JObject jo) { logger.log("Syncing:" + sample.Name); Dictionary <string, RunState> rs = ObjectManager.parseRunState(sample.RunState); Dictionary <string, RunState> nrs = new Dictionary <string, RunState>(); foreach (JProperty p in jo.Properties()) { //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) { logger.log("Connector:" + con.SupplierEnd.Role); EA.Element related = null; if (sample.ElementID == con.ClientID) { 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_sample(Repository, related, pjo); } 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_sample(Repository, related, (JObject)t); } else { MessageBox.Show("Arrays of types other than object not supported"); } } } } } } }