Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic FlowChart Version 5 Serialization-Deserialization (Read 4219 times)
slorenzo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 27th, 2007
FlowChart Version 5 Serialization-Deserialization
Nov 27th, 2007 at 8:41am
Print Post  
Hi, I have a problems with version 5 when I serialize and deserialize FlowChart.

I use a custom class in a object tag and I use this code to Serialize FlowChart:

Code
Select All
  _diagram.SerializeTag += new SerializeTagEventHandler(this.SerializeTag);
  _diagram.SaveToXml(fileName);

  private void SerializeTag(object sender, MindFusion.Diagramming.SerializeTagEventArgs e)
	  {
		object tag = null;
		string xmlTag = "";
		string stringRepresentation = "";

		e.Handled = true;

		if (e.Object is DiagramItem)
		{
		    tag = (e.Object as DiagramItem).Tag;
		    if (tag is VectorNodeProps)
			  xmlTag =Util.ObjectXMLSerializer(.....

		    if (tag is string)
		    {
			  xmlTag = (string)tag;
		    }

		}
		if (e.Object is Diagram)
		{
		    tag = (e.Object as Diagram).Tag;
		    xmlTag = Util.ObjectXMLSerializer(....
		}

		if (tag != null)
		{
		    stringRepresentation = tag.GetType().ToString();
		    stringRepresentation += ";";
		    stringRepresentation += xmlTag;
		}

		XmlNode repNode = e.Context.XmlDocument.CreateTextNode(stringRepresentation);
		e.Representation.AppendChild(repNode);
	  }
 




And then I use this code to Deserialize:

Code
Select All
 _diagram.DeserializeTag += new SerializeTagEventHandler(this.DeserializeTag);
 _diagram.LoadFromXml(fileName);


 private void DeserializeTag(object sender, MindFusion.Diagramming.SerializeTagEventArgs e)
	  {
 XmlText textNode = e.Representation.LastChild as XmlText;
		string stringRep = textNode.Value;
		int pos = stringRep.IndexOf(";");

		if (pos == -1)
		    return;

		string type = stringRep.Substring(0, pos);
		string xml = stringRep.Substring(pos + 1);
		object tag = null;
		Type t = Type.GetType(type);

 if (t == typeof(MyClass))
		{
		  tag = Util.ObjectXMLSerializer(......)
		   .....
		   .....
		}
   if (t == typeof(string))
		{
		    tag = xml;
		}

		if (e.Object is Group)
		    ((Group)e.Object).Tag = tag;
		else if (e.Object is DiagramItem)
		    ((DiagramItem)e.Object).Tag = tag;
		else if (e.Object is Diagram)
		    ((Diagram)e.Object).Tag = tag;
	  }
 



The tags are correctly serializated, but wen I try to deserialize I get this exception:

Code
Select All
System.FormatException was caught
  Message="Input string was not in a correct format."
  Source="MindFusion.Diagramming"
  StackTrace:
	 at MindFusion.Diagramming.Diagram.LoadFromXml(XmlDocument document)
	 at MindFusion.Diagramming.Diagram.LoadFromXml(String fileName)
	 at Gui.ViewFormControls.DataFlowControl.LoadDataFlow(String fileName, Diagram _flowChart) in ....
 



Can anyone help me!!!
Thanks Lorenzo
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: FlowChart Version 5 Serialization-Deserializat
Reply #1 - Nov 27th, 2007 at 10:19am
Print Post  
Hi,

You must set e.Handled = true. Otherwise the diagram will try to deserialize the tag on its own and will probably not recognize your tag format.

Stoyan
  
Back to top
 
IP Logged
 
slorenzo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 27th, 2007
Re: FlowChart Version 5 Serialization-Deserializat
Reply #2 - Nov 27th, 2007 at 10:44am
Print Post  
I have already try to set e.Handled = true in the Deserialize code, but after the deserealization the tags are null, even if they are correctly assigned to the objects.

Thanks, lorenzo
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: FlowChart Version 5 Serialization-Deserializat
Reply #3 - Nov 27th, 2007 at 10:50am
Print Post  
Hi,

Now you must assign the deserialized object to e.Tag, and not directly to the item's Tag. The value you set in e.Tag is later assigned to the item.

Stoyan
  
Back to top
 
IP Logged
 
slorenzo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 27th, 2007
Re: FlowChart Version 5 Serialization-Deserializat
Reply #4 - Nov 27th, 2007 at 10:59am
Print Post  
Thanks now work correctly  Smiley
  
Back to top
 
IP Logged
 
slorenzo
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 27th, 2007
Re: FlowChart Version 5 Serialization-Deserializat
Reply #5 - Nov 27th, 2007 at 11:49am
Print Post  
Sorry another question, it's possible to disable images serialization?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: FlowChart Version 5 Serialization-Deserializat
Reply #6 - Nov 27th, 2007 at 1:07pm
Print Post  
That's not possible. Instead, you could use the SaveToXml(XmlDocument) to save the diagram, remove all "/Image" XML elements, and them use XmlDocument.Save the save XML file.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint