public void ReadWriteGraphMlAdjacencyGraph()
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(sw);
            writer.Formatting = Formatting.Indented;

            GraphMLGraphSerializer ser = new GraphMLGraphSerializer(@"../../graphml.dtd");
            ser.Serialize(writer,Graph);

            Console.WriteLine(sw.ToString());
            Validate(sw.ToString());
            Console.WriteLine("Validated");

            StringReader sr = new StringReader(sw.ToString());
            XmlTextReader reader = new XmlTextReader(sr);
            ISerializableVertexAndEdgeListGraph g = ser.Deserialize(reader);

            writer = new XmlTextWriter(Console.Out);
            writer.Formatting = Formatting.Indented;
            Console.WriteLine("Outputting reloaded");
            ser.Serialize(writer,g);
        }
Exemplo n.º 2
0
        private void menuItem4_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = false;
            dlg.DefaultExt = ".xml";
            dlg.Title="Load GraphML file";
            if(dlg.ShowDialog() != DialogResult.OK)
                return;

            this.netronPanel.Clear();

            // create serialize
            GraphMLGraphSerializer ser = new GraphMLGraphSerializer(".");
            ser.GraphType = typeof(BidirectionalGraph);
            ser.VertexProviderType = typeof(SerializableVertexProvider);
            ser.EdgeProviderType = typeof(SerializableEdgeProvider);

            try
            {
                XmlReader reader = new XmlTextReader(dlg.FileName);
                // validate
                GraphMLGraphSerializer.Validate(reader);
                reader = new XmlTextReader(dlg.FileName);
                this.netronPanel.Graph = (BidirectionalGraph)ser.Deserialize(reader);
            }
            catch(Exception ex)
            {
                Debug.Write(ex.ToString());
                Debug.Flush();
                throw;
            }
            this.netronPanel.Populator.PopulatePanel(this.netronPanel.Graphics);

            foreach(SerializableVertex v in this.netronPanel.Graph.Vertices)
            {
                PropertyGridShape shape = (PropertyGridShape)this.netronPanel.Populator.VertexShapes[v];
                if (v.Entries.ContainsKey("name"))
                    shape.Title = v.Entries["name"];
                else
                    shape.Title = v.ID.ToString();
                if (v.Entries.ContainsKey("icon"))
                {
                    try
                    {
                        shape.Icon = new Icon(v.Entries["icon"]);
                    }
                    catch(Exception)
                    {}
                }

                // add some properties
                foreach(DictionaryEntry de in v.Entries)
                {
                    if (de.Key.ToString()=="name" || de.Key.ToString()=="icon")
                        continue;
                    shape.Rows.Add(new PropertyEntry(de.Key.ToString(),de.Value.ToString()));
                }
            }

            foreach(SerializableEdge edge in this.netronPanel.Graph.Edges)
            {
                if (edge.Entries.ContainsKey("name"))
                {
                    SplineConnection conn = (SplineConnection)this.netronPanel.Populator.EdgeConnections[edge];
                    conn.Label = edge.Entries["name"];
                }
            }

            this.netronPanel.Populator.PopulatePanel(this.netronPanel.Graphics);
        }
Exemplo n.º 3
0
		public void ToXml(TextWriter writer)
		{
			if (writer==null)
				throw new ArgumentNullException("writer");
			
			GraphMLGraphSerializer ser = new GraphMLGraphSerializer("");			
			XmlTextWriter xmlWriter = new XmlTextWriter(writer);			
			xmlWriter.Formatting = Formatting.Indented;
			ser.Serialize(xmlWriter,this.graph);			
		}
        public void WriteGraphMlAdjacencyGraph()
        {
            XmlTextWriter writer = new XmlTextWriter(Console.Out);
            writer.Formatting = Formatting.Indented;

            GraphMLGraphSerializer ser = new GraphMLGraphSerializer();
            ser.Serialize(writer,Graph);
        }
        public void WriteReadGraphMlAdjacencyGraph()
        {
            StringWriter sw = new StringWriter();
            XmlTextWriter writer = new XmlTextWriter(sw);
            writer.Formatting = Formatting.Indented;

            GraphMLGraphSerializer ser = new GraphMLGraphSerializer();
            ser.Serialize(writer,Graph);
            Console.WriteLine("------------- serialized graph -----------------");
            Console.WriteLine(sw.ToString());

            XmlAssert.XmlValid(sw.ToString());

            StringReader sr = new StringReader(sw.ToString());
            XmlTextReader reader = new XmlTextReader(sr);
            ser.TypeFromXml = true;
            ISerializableVertexAndEdgeListGraph g = ser.Deserialize(reader);

            ser = new GraphMLGraphSerializer();
            StringWriter swResult = new StringWriter();
            writer = new XmlTextWriter(swResult);
            writer.Formatting = Formatting.Indented;
            ser.Serialize(writer,g);
            Console.WriteLine("------------- deserialized graph -----------------");
            Console.WriteLine(swResult.ToString());

            XmlAssert.XmlEquals(sw.ToString(), swResult.ToString());
            CheckGraphEqual(Graph,g);
        }