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:
_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:
_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:
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