Пример #1
0
 public WriterWorker(
     GraphMLSerializer <TVertex, TEdge> serializer,
     XmlWriter writer,
     IVertexAndEdgeSet <TVertex, TEdge> visitedGraph)
 {
     this.serializer   = serializer;
     this.writer       = writer;
     this.visitedGraph = visitedGraph;
 }
Пример #2
0
        private void VerifySerialization(TestAdjacencyGraph g)
        {
            GraphMLSerializer <TestVertex, TestEdge> serializer = new GraphMLSerializer <TestVertex, TestEdge>();

            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, g);
                String xml = writer.ToString();
                Console.WriteLine(xml);
                XmlAssert.IsWellFormedXml(xml);
            }
        }
        public static void SerializeToGraphML <TVertex, TEdge, TGraph>(
            this TGraph graph, XmlWriter writer, VertexIdentity <TVertex> vertexIdentities,
            EdgeIdentity <TVertex, TEdge> edgeIdentities)
            where TEdge : IEdge <TVertex>
            where TGraph : IEdgeListGraph <TVertex, TEdge>
        {
            Contract.Requires(graph != null);
            Contract.Requires(writer != null);

            var serializer = new GraphMLSerializer <TVertex, TEdge, TGraph>();

            serializer.Serialize(writer, graph, vertexIdentities, edgeIdentities);
        }
Пример #4
0
 public ReaderWorker(
     GraphMLSerializer <TVertex, TEdge> serializer,
     XmlReader reader,
     IMutableVertexAndEdgeListGraph <TVertex, TEdge> visitedGraph,
     IIdentifiableVertexFactory <TVertex> vertexFactory,
     IIdentifiableEdgeFactory <TVertex, TEdge> edgeFactory
     )
 {
     this.serializer    = serializer;
     this.reader        = reader;
     this.visitedGraph  = visitedGraph;
     this.vertexFactory = vertexFactory;
     this.edgeFactory   = edgeFactory;
 }
Пример #5
0
            public WriterWorker(
                GraphMLSerializer <TVertex, TEdge, TGraph> serializer,
                XmlWriter writer,
                TGraph visitedGraph,
                VertexIdentity <TVertex> vertexIdentities,
                EdgeIdentity <TVertex, TEdge> edgeIdentities)
            {
                Contract.Requires(serializer != null);
                Contract.Requires(writer != null);
                Contract.Requires(visitedGraph != null);
                Contract.Requires(vertexIdentities != null);
                Contract.Requires(edgeIdentities != null);

                this.serializer       = serializer;
                this.writer           = writer;
                this.visitedGraph     = visitedGraph;
                this.vertexIdentities = vertexIdentities;
                this.edgeIdentities   = edgeIdentities;
            }
        public void RoundTripGraph([PexAssumeNotNull] IMutableVertexAndEdgeListGraph <NamedVertex, NamedEdge> g)
        {
            GraphMLSerializer <NamedVertex, NamedEdge> serializer = new GraphMLSerializer <NamedVertex, NamedEdge>();
            AdjacencyGraph <NamedVertex, NamedEdge>    gd         = new AdjacencyGraph <NamedVertex, NamedEdge>();
            string baseLine;
            string output;

            using (StringWriter writer = new StringWriter())
            {
                serializer.Serialize(writer, g);
                baseLine = writer.ToString();
                TestConsole.WriteLineBold("Original graph:");
                Console.WriteLine(writer.ToString());
                TestConsole.WriteLineBold("---");

                using (XmlTextReader reader = new XmlTextReader(new StringReader(writer.ToString())))
                {
                    serializer.Deserialize(
                        reader,
                        gd,
                        new NamedVertex.Factory(),
                        new NamedEdge.Factory()
                        );
                }
            }

            TestConsole.WriteLineBold("Roundtripped graph:");
            using (StringWriter sw = new StringWriter())
            {
                serializer.Serialize(sw, gd);
                output = sw.ToString();
                Console.WriteLine(sw.ToString());
            }

            Assert.AreEqual(g.VertexCount, gd.VertexCount);
            Assert.AreEqual(g.EdgeCount, gd.EdgeCount);
            StringAssert.AreEqual(
                baseLine,
                output,
                StringComparison.InvariantCulture
                );
        }