/// <summary> /// Serializes a node /// </summary> /// <param name="s"></param> /// <returns></returns> private ShapeType SerializeNode(Shape s) { PropertiesHashtable properties = GraphMLDataAttribute.GetValuesOfTaggedFields(s); ShapeType node = new ShapeType(); node.UID = FormatID(s); node.InstanceKey = s.Summary.Key; foreach (Connector c in s.Connectors) { ConnectorType ct = new ConnectorType(); ct.Name = c.Name; ct.UID = c.UID.ToString(); node.Data.Add(ct); } //-------------------------------------- foreach (DataType data in DataTypesFromAttributes(properties)) { node.Data.Add(data); } return(node); }
/// <summary> /// Converts the hashtable of GraphML-marked properties to types /// </summary> /// <param name="properties"></param> /// <returns></returns> private DataType[] DataTypesFromAttributes(PropertiesHashtable properties) { DataType[] dts = new DataType[properties.Count]; for (int k = 0; k < properties.Count; k++) { dts[k] = new DataType(); dts[k].Name = properties.Keys[k]; object val = null; if ((val = properties[k]) != null) { //the color is a bit different if (typeof(Color).IsInstanceOfType(val)) { int num = ((Color)val).ToArgb(); dts[k].Value.Add(num.ToString()); } else if (typeof(Shape).IsInstanceOfType(val)) { dts[k].Value.Add((val as Shape).UID.ToString()); } else if (typeof(Guid).IsInstanceOfType(val)) { dts[k].Value.Add(((Guid)val).ToString()); } else if (typeof(CollectionBase).IsInstanceOfType(val)) { CollectionBase col = val as CollectionBase; IEnumerator enumer = col.GetEnumerator(); while (enumer.MoveNext()) { object obj = enumer.Current; PropertiesHashtable props = GraphMLDataAttribute.GetValuesOfTaggedFields(obj); DataType[] tps = DataTypesFromAttributes(props); DataType dt = new DataType(); dt.Name = obj.GetType().Name; //the name of the collection element dt.IsCollection = true; for (int m = 0; m < tps.Length; m++) { dt.Value.Add(tps[m]); } dts[k].Value.Add(dt); dts[k].IsCollection = true; } } else { dts[k].Value.Add(val.ToString()); } } /* * makes the union of all properties in the different shapes * if ( !keyList.Contains(properties.Keys[k])) * keyList.Add(properties.Keys[k],val); */ } return(dts); }
/// <summary> /// Serializes an edge /// </summary> /// <param name="c"></param> /// <returns></returns> private ConnectionType SerializeEdge(Connection c) { PropertiesHashtable properties = GraphMLDataAttribute.GetValuesOfTaggedFields(c); ConnectionType edge = new ConnectionType(); edge.ID = FormatID(c); /* Save the connectors the Connection is connected to */ edge.Source = FormatID(c.From.BelongsTo); edge.Target = FormatID(c.To.BelongsTo); /* Save the connectors the Connection is connected to */ edge.Sourceport = FormatID(c.From); edge.Targetport = FormatID(c.To); edge.InstanceKey = c.Summary.Key; foreach (DataType dt in DataTypesFromAttributes(properties)) { edge.Data.Add(dt); } return(edge); }
/// <summary> /// Converts the hashtable of GraphML-marked properties to types /// </summary> /// <param name="properties"></param> /// <returns></returns> private DataType[] DataTypesFromAttributes(PropertiesHashtable properties) { DataType[] dts = new DataType[properties.Count]; for(int k=0; k<properties.Count;k++) { dts[k] = new DataType(); dts[k].Name = properties.Keys[k]; object val = null; if ((val=properties[k]) != null) { //the color is a bit different if(typeof(Color).IsInstanceOfType(val)) { int num = ((Color) val).ToArgb(); dts[k].Value.Add(num.ToString()); } else if(typeof(Shape).IsInstanceOfType(val)) { dts[k].Value.Add((val as Shape).UID.ToString()); } else if(typeof(Guid).IsInstanceOfType(val)) { dts[k].Value.Add(((Guid) val ).ToString()); } else if(typeof(CollectionBase).IsInstanceOfType(val)) { CollectionBase col = val as CollectionBase; IEnumerator enumer = col.GetEnumerator(); while(enumer.MoveNext()) { object obj = enumer.Current; PropertiesHashtable props= GraphMLDataAttribute.GetValuesOfTaggedFields(obj); DataType[] tps = DataTypesFromAttributes(props); DataType dt = new DataType(); dt.Name=obj.GetType().Name;//the name of the collection element dt.IsCollection = true; for(int m =0; m<tps.Length; m++) dt.Value.Add (tps[m]); dts[k].Value.Add(dt); dts[k].IsCollection = true; } } else dts[k].Value.Add(val.ToString()); } /* * makes the union of all properties in the different shapes if ( !keyList.Contains(properties.Keys[k])) keyList.Add(properties.Keys[k],val); */ } return dts; }