예제 #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);
        }
예제 #2
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);
		}
예제 #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);
            }
        }
예제 #4
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);
        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
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;
		}
예제 #8
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;
		}
예제 #9
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;
		}
예제 #10
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;
		}