Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic (De)SerializeTag (Read 2145 times)
ooswald
YaBB Newbies
*
Offline



Posts: 16
Joined: Jun 15th, 2006
(De)SerializeTag
Jun 19th, 2006 at 10:43am
Print Post  
[b]could you please provide a complete example for SerializeTag and DeserializeTag?[/b]

I have objects attached to the Tag property of Boxes and AnchorPoints and am able to serialize them into an XML file:

[code]
<Box ...>
  ...
  <Tag>
    <Filter Type="-some-string-here-" />
  </Tag>
  ...
</Box>
[/code]

using the following event handler:

[code]
void Writer_SerializeTag(object sender, SerializeTagArgs e) {
    if (e.Object is ChartObject) {
       ChartObject Node = (ChartObject)e.Object;
       if (Node.Tag is IFilter) {
           // Filter element
           e.XmlWriter.WriteStartElement("Filter");

           // Type attribute
           e.XmlWriter.WriteStartAttribute("Type");
           e.XmlWriter.WriteValue(Node.Tag.GetType().FullName);
           e.XmlWriter.WriteEndAttribute();

           e.XmlWriter.WriteEndElement();
       }

}
}
[/code]

when calling the Read() method of the XML reader, DeserializeTag gets called as expected:

[code]
void Reader_DeserializeTag(object sender, SerializeTagArgs e) {
    if (e.Object is ChartObject) {
       if (e.XmlReader.IsStartElement("Filter")) {
           Box Node = (Box)e.Object;
           string strTypeName = e.XmlReader.GetAttribute("Type");
           Node.Tag = (Activator.CreateInstance( Type.GetType(strTypeName) ) as IFilter);
       }   

}
}
[/code]

the object gets instanciated properly, however, a moment later Read() throws the following exception:

[code]
MindFusion.FlowChartX.Xml.InvalidFormatException: ControlHosts element missing or invalid
   at MindFusion.FlowChartX.Xml.XmlReader.x4cee5b00d96d6dfb(...)
   ...
[/code]

am i doing something wrong or is there a bug in FlowCharter.FX (latest build from website)?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: (De)SerializeTag
Reply #1 - Jun 19th, 2006 at 12:35pm
Print Post  
Set the Options.CustomTagSerialization property of the XmlWriter and the XmlReader to true when you use the XML reader and writer objects provided by the tag serialization events. Otherwise the control expects that you will use only the Representation property of the event arguments to save or load the tag as a simple string.

Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: (De)SerializeTag
Reply #2 - Jun 19th, 2006 at 12:59pm
Print Post  
If you have already set these properties, make sure the reader reads as many XML elements as the writer writes, or else the control would continue reading from a wrong position in the XmlReader stream.

Stoyan
  
Back to top
 
IP Logged
 
ooswald
YaBB Newbies
*
Offline



Posts: 16
Joined: Jun 15th, 2006
Re: (De)SerializeTag
Reply #3 - Jun 20th, 2006 at 5:57am
Print Post  
Thanks for the hint, I managed to fix the problem.

Instead of [b]IsStartElement()[/b] I'm now checking the [b]Name[/b] property (when calling DeserializeTag, the FlowChart reader has already advanced to my element).

Additionally, I added a [b]Skip()[/b] statement in order to advance to a position in the stream which is suitable for FlowChart's Read() method.

[code]void Reader_DeserializeTag(object sender, SerializeTagArgs e) {
    if (e.Object is ChartObject) {
       if ( e.XmlReader.Name == "Filter" ) {
           string strTypeName = e.XmlReader.GetAttribute("Type");
           // ...
           e.XmlReader.Skip();
       }   
    }
}[/code]
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint