Esempio n. 1
0
        /// <summary>
        /// Create the graph element and stores graph level data.
        /// </summary>
        /// <param name="writer">xml writer</param>
        /// <param name="baseGraph">"base" graph of g</param>
        /// <param name="g">graph to serialize</param>
        protected override void WriteGraphElem(
            XmlWriter writer,
            ISerializableVertexAndEdgeListGraph baseGraph,
            IVertexAndEdgeListGraph g
            )
        {
            writer.WriteStartElement("gxl");

            // adding xsd ref
            writer.WriteAttributeString("xmlns", "http://www.gupro.de/GXL/xmlschema/gxl-1.0.xsd");

            // adding graph node
            writer.WriteStartElement("graph");
            writer.WriteAttributeString("edgeids", "true");
            if (g.IsDirected)
            {
                writer.WriteAttributeString("edgemode", "directed");
            }
            else
            {
                writer.WriteAttributeString("edgemode", "undirected");
            }

            // adding type information
            IGraphSerializationInfo info = new GraphSerializationInfo(true);

            info.Add("graph-type", GetTypeQualifiedName(baseGraph));
            info.Add("vertex-provider-type", GetTypeQualifiedName(baseGraph.VertexProvider));
            info.Add("edge-provider-type", GetTypeQualifiedName(baseGraph.EdgeProvider));
            info.Add("allow-parallel-edges", g.AllowParallelEdges);
            WriteInfo(writer, info);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="g"></param>
        protected void ReadEdge(
            XmlReader reader,
            ISerializableVertexAndEdgeListGraph g
            )
        {
            MoveToAttribute(reader, "id", true);
            string id = this.ParseEdgeID(reader.Value);

            MoveToAttribute(reader, "from", true);
            string sourceid = ParseVertexID(reader.Value);

            MoveToAttribute(reader, "to", true);
            string targetid = ParseVertexID(reader.Value);

            // add edge.
            IEdge e = g.AddEdge(
                (IVertex)CreatedVertices[sourceid],
                (IVertex)CreatedVertices[targetid]
                );

            // add to table
            CreatedEdges[id] = e;

            GraphSerializationInfo info = ReadInfo(reader);

            if (info != null)
            {
                ((IGraphDeSerializable)e).ReadGraphData(info);
            }

            this.MovePastEndElement(reader, "edge");
        }
Esempio n. 3
0
        /// <summary>
        /// Reads custom info from GraphMl
        /// </summary>
        /// <param name="reader">xml reader</param>
        /// <returns>custom data</returns>
        protected GraphSerializationInfo ReadInfo(
            XmlReader reader)
        {
            GraphSerializationInfo info = new GraphSerializationInfo(false);

            while (MoveToElement(reader, "attr"))
            {
                MoveToAttribute(reader, "name", true);
                string key = reader.Value;
                if (!MoveNextElement(reader))
                {
                    throw new Exception("expected data, not found");
                }
                string t = reader.Name;
                if (!reader.Read())
                {
                    throw new Exception("expected data, not found");
                }
                string value = reader.Value;
                info.Add(key, value);
                MovePastEndElement(reader, t);
                MovePastEndElement(reader, "attr");
            }

            if (info.Count > 0)
            {
                return(info);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
		/// <summary>
		/// Create the graph element and stores graph level data.
		/// </summary>
		/// <param name="writer">xml writer</param>
		/// <param name="baseGraph">"base" graph of g</param>
		/// <param name="g">graph to serialize</param>		
		protected override void WriteGraphElem(
			XmlWriter writer,
			ISerializableVertexAndEdgeListGraph baseGraph,
			IVertexAndEdgeListGraph g
			)
		{
			writer.WriteStartElement("gxl");

			// adding xsd ref
			writer.WriteAttributeString("xmlns","http://www.gupro.de/GXL/xmlschema/gxl-1.0.xsd");

			// adding graph node
			writer.WriteStartElement("graph");
			writer.WriteAttributeString("edgeids","true");
			if (g.IsDirected)
				writer.WriteAttributeString("edgemode","directed");
			else
				writer.WriteAttributeString("edgemode","undirected");

			// adding type information
			IGraphSerializationInfo info = new GraphSerializationInfo(true);
			info.Add("graph-type",GetTypeQualifiedName(baseGraph));
			info.Add("vertex-provider-type",GetTypeQualifiedName(baseGraph.VertexProvider));
			info.Add("edge-provider-type",GetTypeQualifiedName(baseGraph.EdgeProvider));
			info.Add("allow-parallel-edges",g.AllowParallelEdges);
			WriteInfo(writer,info);
		}
Esempio n. 5
0
 /// <summary>
 /// Writes a vertex element and it's custom data stored in info.
 /// </summary>
 /// <param name="writer">xml writer</param>
 /// <param name="v">vertex to store</param>
 /// <param name="info">vertex custom data</param>
 protected override void WriteVertexElem(
     XmlWriter writer,
     IVertex v,
     GraphSerializationInfo info
     )
 {
     writer.WriteStartElement("node");
     writer.WriteAttributeString("id", FormatID(v));
     WriteInfo(writer, info);
     writer.WriteEndElement();             // node
 }
Esempio n. 6
0
        private IGraphSerializationInfo InfoFromEdge(EdgeType edge)
        {
            GraphSerializationInfo info = new GraphSerializationInfo(false);

            foreach (DataType dt in edge.Data)
            {
                info.Add(dt.Key, dt.Text);
            }

            return(info);
        }
Esempio n. 7
0
 /// <summary>
 /// Writes a vertex element and it's custom data stored in info.
 /// </summary>
 /// <param name="writer">xml writer</param>
 /// <param name="e">edge to store</param>
 /// <param name="info">edge custom data</param>
 protected override void WriteEdgeElem(
     XmlWriter writer,
     IEdge e,
     GraphSerializationInfo info
     )
 {
     writer.WriteStartElement("edge");
     writer.WriteAttributeString("id", FormatID(e));
     writer.WriteAttributeString("from", FormatID(e.Source));
     writer.WriteAttributeString("to", FormatID(e.Target));
     WriteInfo(writer, info);
     writer.WriteEndElement();             // node
 }
Esempio n. 8
0
        private NodeType SerializeVertex(IVertex v)
        {
            NodeType node = new NodeType();

            node.ID = FormatID(v);
            GraphSerializationInfo info = new GraphSerializationInfo(true);

            ((IGraphSerializable)v).WriteGraphData(info);

            foreach (DataType dt in ToDatas(info))
            {
                node.Items.AddData(dt);
            }

            return(node);
        }
Esempio n. 9
0
        private IGraphSerializationInfo InfoFromNode(NodeType node)
        {
            GraphSerializationInfo info = new GraphSerializationInfo(false);

            foreach (Object o in node.Items)
            {
                DataType dt = o as DataType;
                if (dt == null)
                {
                    continue;
                }
                info.Add(dt.Key, dt.Text.ToString());
            }

            return(info);
        }
Esempio n. 10
0
        private GraphType SerializeGraph(
            ISerializableVertexAndEdgeListGraph baseGraph,
            IVertexAndEdgeListGraph g)
        {
            // create graph node
            GraphType graph = new GraphType();

            // fill up graph
            if (g.IsDirected)
            {
                graph.EdgeDefault = GraphEdgeDefaultType.Directed;
            }
            else
            {
                graph.EdgeDefault = GraphEdgeDefaultType.Undirected;
            }

            // adding type information
            IGraphSerializationInfo info = new GraphSerializationInfo(true);

            info.Add(graphTypeKeyName, GetTypeQualifiedName(baseGraph));
            info.Add(vertexProviderTypeKeyName, GetTypeQualifiedName(baseGraph.VertexProvider));
            info.Add(edgeProviderTypeKeyName, GetTypeQualifiedName(baseGraph.EdgeProvider));
            info.Add(allowParallelEdgesKeyName, g.AllowParallelEdges);

            // add data...
            foreach (DataType dt in ToDatas(info))
            {
                graph.Items.AddData(dt);
            }

            // add vertices
            foreach (IVertex v in g.Vertices)
            {
                graph.Items.AddNode(SerializeVertex(v));
            }

            // add edges
            foreach (IEdge e in g.Edges)
            {
                graph.Items.AddEdge(SerializeEdge(e));
            }

            return(graph);
        }
Esempio n. 11
0
        /// <summary>
        /// Serializes the filtered graph g to xml
        /// </summary>
        /// <param name="writer">xml writer</param>
        /// <param name="baseGraph">"base" graph of g</param>
        /// <param name="g">graph to serialize</param>
        /// <exception cref="ArgumentNullException">writer or g are null</exception>
        /// <exception cref="ArgumentException">g vertex or edge does not
        /// implement <see cref="QuickGraph.Concepts.Serialization.IGraphSerializable"/>.
        /// </exception>
        public void Serialize(
            XmlWriter writer,
            ISerializableVertexAndEdgeListGraph baseGraph,
            IVertexAndEdgeListGraph g
            )
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (baseGraph == null)
            {
                throw new ArgumentNullException("baseGraph");
            }
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            // Add graph node
            WriteGraphElem(writer, baseGraph, g);

            // add vertices
            foreach (IVertex v in g.Vertices)
            {
                // get vertex data
                GraphSerializationInfo info = new GraphSerializationInfo(true);
                ((IGraphSerializable)v).WriteGraphData(info);
                // write it to xml
                WriteVertexElem(writer, v, info);
            }

            // add edges
            foreach (IEdge e in g.Edges)
            {
                // get edge data
                GraphSerializationInfo info = new GraphSerializationInfo(true);
                ((IGraphSerializable)e).WriteGraphData(info);
                // write to xml
                WriteEdgeElem(writer, e, info);
            }

            // finish graph node
            WriteEndGraphElem(writer);
        }
Esempio n. 12
0
        private EdgeType SerializeEdge(IEdge e)
        {
            EdgeType edge = new EdgeType();

            edge.ID       = FormatID(e);
            edge.Source   = FormatID(e.Source);
            edge.Target   = FormatID(e.Target);
            edge.Directed = true;

            GraphSerializationInfo info = new GraphSerializationInfo(true);

            ((IGraphSerializable)e).WriteGraphData(info);

            foreach (DataType dt in ToDatas(info))
            {
                edge.Data.AddDataType(dt);
            }

            return(edge);
        }
Esempio n. 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="g"></param>
        protected void ReadVertex(
            XmlReader reader,
            ISerializableVertexAndEdgeListGraph g
            )
        {
            MoveToAttribute(reader, "id", true);
            string id = this.ParseVertexID(reader.Value);

            // add vertex.
            IVertex v = g.AddVertex();

            // add to table
            CreatedVertices[id] = v;

            GraphSerializationInfo info = ReadInfo(reader);

            if (info != null)
            {
                ((IGraphDeSerializable)v).ReadGraphData(info);
            }

            this.MovePastEndElement(reader, "node");
        }
Esempio n. 14
0
		/// <summary>
		/// Writes a vertex element and it's custom data stored in info.
		/// </summary>
		/// <param name="writer">xml writer</param>
		/// <param name="e">edge to store</param>
		/// <param name="info">edge custom data</param>
		protected abstract void WriteEdgeElem(
			XmlWriter writer,
			IEdge e, 
			GraphSerializationInfo info
			);
Esempio n. 15
0
		/// <summary>
		/// Writes a vertex element and it's custom data stored in info.
		/// </summary>
		/// <param name="writer">xml writer</param>
		/// <param name="v">vertex to store</param>
		/// <param name="info">vertex custom data</param>
		protected abstract void WriteVertexElem(
			XmlWriter writer,
			IVertex v, 
			GraphSerializationInfo info
			);
Esempio n. 16
0
		/// <summary>
		/// Serializes the filtered graph g to xml
		/// </summary>
		/// <param name="writer">xml writer</param>
		/// <param name="baseGraph">"base" graph of g</param>
		/// <param name="g">graph to serialize</param>
		/// <exception cref="ArgumentNullException">writer or g are null</exception>
		/// <exception cref="ArgumentException">g vertex or edge does not
		/// implement <see cref="QuickGraph.Concepts.Serialization.IGraphSerializable"/>.
		/// </exception>
		public void Serialize(
			XmlWriter writer, 
			ISerializableVertexAndEdgeListGraph baseGraph,
			IVertexAndEdgeListGraph g
			)
		{
			if (writer==null)
				throw new ArgumentNullException("writer");
			if (baseGraph==null)
				throw new ArgumentNullException("baseGraph");
			if (g==null)
				throw new ArgumentNullException("g");

			// Add graph node
			WriteGraphElem(writer,baseGraph,g);

			// add vertices
			foreach(IVertex v in g.Vertices)
			{
				// get vertex data
				GraphSerializationInfo info = new GraphSerializationInfo(true);
				((IGraphSerializable)v).WriteGraphData(info);
				// write it to xml
				WriteVertexElem(writer,v,info);
			}

			// add edges
			foreach(IEdge e in g.Edges)
			{
				// get edge data
				GraphSerializationInfo info = new GraphSerializationInfo(true);
				((IGraphSerializable)e).WriteGraphData(info);
				// write to xml
				WriteEdgeElem(writer,e,info);
			}

			// finish graph node
			WriteEndGraphElem(writer);
		}
Esempio n. 17
0
		private IGraphSerializationInfo InfoFromEdge(EdgeType edge)
		{
			GraphSerializationInfo info = new GraphSerializationInfo(false);

			foreach(DataType dt in edge.Data)
			{
				info.Add(dt.Key, dt.Text);
			}

			return info;
		}
Esempio n. 18
0
		private IGraphSerializationInfo InfoFromNode(NodeType node)
		{
			GraphSerializationInfo info = new GraphSerializationInfo(false);

			foreach(Object o in node.Items)
			{
				DataType dt = o as DataType;
				if (dt==null)
					continue;
				info.Add(dt.Key, dt.Text.ToString());
			}

			return info;
		}
Esempio n. 19
0
		private EdgeType SerializeEdge(IEdge e)
		{
			EdgeType edge = new EdgeType();
			edge.ID = FormatID(e);
			edge.Source = FormatID(e.Source);
			edge.Target = FormatID(e.Target);
			edge.Directed = true;

			GraphSerializationInfo info = new GraphSerializationInfo(true);
			((IGraphSerializable)e).WriteGraphData(info);

			foreach(DataType dt in ToDatas(info))
			{
				edge.Data.AddDataType(dt);
			}

			return edge;
		}
Esempio n. 20
0
		private NodeType SerializeVertex(IVertex v)
		{
			NodeType node = new NodeType();
			node.ID = FormatID(v);
			GraphSerializationInfo info = new GraphSerializationInfo(true);
			((IGraphSerializable)v).WriteGraphData(info);

			foreach(DataType dt in ToDatas(info))
			{
				node.Items.AddData(dt);
			}

			return node;
		}
Esempio n. 21
0
		private GraphType SerializeGraph(
			ISerializableVertexAndEdgeListGraph baseGraph,
			IVertexAndEdgeListGraph g)
		{
			// create graph node
			GraphType graph = new GraphType();			

			// fill up graph
			if (g.IsDirected)
				graph.EdgeDefault = GraphEdgeDefaultType.Directed;
			else
				graph.EdgeDefault= GraphEdgeDefaultType.Undirected;

			// adding type information
			IGraphSerializationInfo info = new GraphSerializationInfo(true);
			info.Add(graphTypeKeyName,GetTypeQualifiedName(baseGraph));
			info.Add(vertexProviderTypeKeyName,GetTypeQualifiedName(baseGraph.VertexProvider));
			info.Add(edgeProviderTypeKeyName,GetTypeQualifiedName(baseGraph.EdgeProvider));
			info.Add(allowParallelEdgesKeyName,g.AllowParallelEdges);
			
			// add data...
			foreach(DataType dt in ToDatas(info))
			{
				graph.Items.AddData(dt);
			}

			// add vertices
			foreach(IVertex v in g.Vertices)
				graph.Items.AddNode( SerializeVertex(v) );

			// add edges
			foreach(IEdge e in g.Edges)
				graph.Items.AddEdge( SerializeEdge(e) );

			return graph;
		}
Esempio n. 22
0
		/// <summary>
		/// Reads custom info from GraphMl
		/// </summary>
		/// <param name="reader">xml reader</param>
		/// <returns>custom data</returns>
		protected GraphSerializationInfo ReadInfo(
			XmlReader reader)
		{
			GraphSerializationInfo info = new GraphSerializationInfo(false);

			while (MoveToElement(reader,"attr"))
			{
				MoveToAttribute(reader,"name",true);
				string key = reader.Value;
				if (!MoveNextElement(reader))
					throw new Exception("expected data, not found");
				string t = reader.Name;
				if (!reader.Read())
					throw new Exception("expected data, not found");
				string value = reader.Value;
				info.Add(key,value);
				MovePastEndElement(reader,t);
				MovePastEndElement(reader,"attr");
			}

			if (info.Count>0)
				return info;
			else
				return null;
		}
Esempio n. 23
0
		/// <summary>
		/// Writes a vertex element and it's custom data stored in info.
		/// </summary>
		/// <param name="writer">xml writer</param>
		/// <param name="e">edge to store</param>
		/// <param name="info">edge custom data</param>
		protected override void WriteEdgeElem(
			XmlWriter writer,
			IEdge e, 
			GraphSerializationInfo info
			)
		{
			writer.WriteStartElement("edge");
			writer.WriteAttributeString("id",FormatID(e));
			writer.WriteAttributeString("from",FormatID(e.Source));
			writer.WriteAttributeString("to",FormatID(e.Target));
			WriteInfo(writer,info);
			writer.WriteEndElement(); // node
		}
Esempio n. 24
0
 /// <summary>
 /// Writes a vertex element and it's custom data stored in info.
 /// </summary>
 /// <param name="writer">xml writer</param>
 /// <param name="v">vertex to store</param>
 /// <param name="info">vertex custom data</param>
 protected abstract void WriteVertexElem(
     XmlWriter writer,
     IVertex v,
     GraphSerializationInfo info
     );
Esempio n. 25
0
 /// <summary>
 /// Writes a vertex element and it's custom data stored in info.
 /// </summary>
 /// <param name="writer">xml writer</param>
 /// <param name="e">edge to store</param>
 /// <param name="info">edge custom data</param>
 protected abstract void WriteEdgeElem(
     XmlWriter writer,
     IEdge e,
     GraphSerializationInfo info
     );
Esempio n. 26
0
		/// <summary>
		/// Writes a vertex element and it's custom data stored in info.
		/// </summary>
		/// <param name="writer">xml writer</param>
		/// <param name="v">vertex to store</param>
		/// <param name="info">vertex custom data</param>
		protected override void WriteVertexElem(
			XmlWriter writer,
			IVertex v, 
			GraphSerializationInfo info
			)
		{
			writer.WriteStartElement("node");
			writer.WriteAttributeString("id",FormatID(v));
			WriteInfo(writer,info);
			writer.WriteEndElement(); // node
		}