コード例 #1
0
 public EquatableAdditionalDataTestEdge(
     [NotNull] EquatableTestVertex source,
     [NotNull] EquatableTestVertex target,
     [NotNull] string id,
     double data)
     : base(source, target, id)
 {
     Data = data;
 }
コード例 #2
0
        public void GraphMLSerialization_HeaderCheck(bool emitDeclarationOnSerialize, bool emitDeclarationOnDeserialize)
        {
            var graph = new EquatableTestGraph
            {
                String = "graph",
                Int    = 42
            };

            var vertex1 = new EquatableTestVertex("v1")
            {
                StringDefault = "foo",
                String        = "string",
                Int           = 10,
                Long          = 20,
                Float         = 25.0F,
                Double        = 30.0,
                Bool          = true
            };

            var vertex2 = new EquatableTestVertex("v2")
            {
                StringDefault = "bar",
                String        = "string2",
                Int           = 110,
                Long          = 120,
                Float         = 125.0F,
                Double        = 130.0,
                Bool          = true
            };

            graph.AddVertex(vertex1);
            graph.AddVertex(vertex2);

            var edge1 = new EquatableTestEdge(vertex1, vertex2, "e_1")
            {
                String = "edge",
                Int    = 90,
                Long   = 100,
                Float  = 25.0F,
                Double = 110.0,
                Bool   = true
            };

            graph.AddEdge(edge1);

            EquatableTestGraph serializedGraph = VerifySerialization(
                graph,
                g =>
            {
                using (var writer = new StringWriter())
                {
                    var settings = new XmlWriterSettings {
                        Indent = true
                    };
                    using (XmlWriter xmlWriter = XmlWriter.Create(writer, settings))
                    {
                        var serializer = new GraphMLSerializer <EquatableTestVertex, EquatableTestEdge, EquatableTestGraph>
                        {
                            EmitDocumentDeclaration = emitDeclarationOnDeserialize
                        };

                        serializer.Serialize(
                            xmlWriter,
                            g,
                            vertex => vertex.ID,
                            edge => edge.ID);
                    }

                    return(writer.ToString());
                }
            },
                xml =>
            {
                using (var reader = new StringReader(xml))
                {
                    var serializer = new GraphMLDeserializer <EquatableTestVertex, EquatableTestEdge, EquatableTestGraph>
                    {
                        EmitDocumentDeclaration = emitDeclarationOnDeserialize
                    };

#if SUPPORTS_XML_DTD_PROCESSING
                    var settings = new XmlReaderSettings
                    {
                        ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings,
                        XmlResolver     = new GraphMLXmlResolver(),
                        DtdProcessing   = DtdProcessing.Ignore
                    };

                    using (XmlReader xmlReader = XmlReader.Create(reader, settings))
                    {
#else
                    var xmlReader = new XmlTextReader(reader);
                    {
                        xmlReader.ProhibitDtd = false;
                        xmlReader.XmlResolver = null;
#endif
                        var g = new EquatableTestGraph();
                        serializer.Deserialize(
                            xmlReader,
                            g,
                            id => new EquatableTestVertex(id),
                            (source, target, id) => new EquatableTestEdge(source, target, id));
                        return(g);
                    }
                }
            });

            Assert.IsTrue(
                EquateGraphs.Equate(
                    graph,
                    serializedGraph));
        }
コード例 #3
0
 public static string VertexIdentity_Complex([NotNull] EquatableTestVertex vertex)
 {
     return(vertex.ID);
 }